Dmitry Timoshkov : windowscodecs: Add NULL pointer checks to some color context methods.
Alexandre Julliard
julliard at winehq.org
Mon Nov 19 13:38:38 CST 2012
Module: wine
Branch: master
Commit: bfed6e5f3003a3a9b33b71290e35d0b983a9e7f4
URL: http://source.winehq.org/git/wine.git/?a=commit;h=bfed6e5f3003a3a9b33b71290e35d0b983a9e7f4
Author: Dmitry Timoshkov <dmitry at baikal.ru>
Date: Mon Nov 19 13:33:48 2012 +0800
windowscodecs: Add NULL pointer checks to some color context methods.
---
dlls/windowscodecs/colorcontext.c | 8 ++++++++
dlls/windowscodecs/pngformat.c | 2 ++
dlls/windowscodecs/tests/pngformat.c | 21 +++++++++++++++++++++
3 files changed, 31 insertions(+), 0 deletions(-)
diff --git a/dlls/windowscodecs/colorcontext.c b/dlls/windowscodecs/colorcontext.c
index 5434fc6..457b4db 100644
--- a/dlls/windowscodecs/colorcontext.c
+++ b/dlls/windowscodecs/colorcontext.c
@@ -144,6 +144,8 @@ static HRESULT WINAPI ColorContext_GetType(IWICColorContext *iface,
ColorContext *This = impl_from_IWICColorContext(iface);
TRACE("(%p,%p)\n", iface, pType);
+ if (!pType) return E_INVALIDARG;
+
*pType = This->type;
return S_OK;
}
@@ -157,6 +159,8 @@ static HRESULT WINAPI ColorContext_GetProfileBytes(IWICColorContext *iface,
if (This->type != WICColorContextProfile)
return WINCODEC_ERR_NOTINITIALIZED;
+ if (!pcbActual) return E_INVALIDARG;
+
if (cbBuffer >= This->profile_len && pbBuffer)
memcpy(pbBuffer, This->profile, This->profile_len);
@@ -171,6 +175,8 @@ static HRESULT WINAPI ColorContext_GetExifColorSpace(IWICColorContext *iface,
ColorContext *This = impl_from_IWICColorContext(iface);
TRACE("(%p,%p)\n", iface, pValue);
+ if (!pValue) return E_INVALIDARG;
+
*pValue = This->exif_color_space;
return S_OK;
}
@@ -191,6 +197,8 @@ HRESULT ColorContext_Create(IWICColorContext **colorcontext)
{
ColorContext *This;
+ if (!colorcontext) return E_INVALIDARG;
+
This = HeapAlloc(GetProcessHeap(), 0, sizeof(ColorContext));
if (!This) return E_OUTOFMEMORY;
diff --git a/dlls/windowscodecs/pngformat.c b/dlls/windowscodecs/pngformat.c
index 89f092e..6d6117e 100644
--- a/dlls/windowscodecs/pngformat.c
+++ b/dlls/windowscodecs/pngformat.c
@@ -854,6 +854,8 @@ static HRESULT WINAPI PngDecoder_Frame_GetColorContexts(IWICBitmapFrameDecode *i
TRACE("(%p,%u,%p,%p)\n", iface, cCount, ppIColorContexts, pcActualCount);
+ if (!pcActualCount) return E_INVALIDARG;
+
EnterCriticalSection(&This->lock);
if (ppng_get_iCCP(This->png_ptr, This->info_ptr, &name, &compression_type, &profile, &len))
diff --git a/dlls/windowscodecs/tests/pngformat.c b/dlls/windowscodecs/tests/pngformat.c
index b7dfbd0..3f4e855 100644
--- a/dlls/windowscodecs/tests/pngformat.c
+++ b/dlls/windowscodecs/tests/pngformat.c
@@ -331,6 +331,9 @@ static void test_color_contexts(void)
ok(decoder != 0, "Failed to load PNG image data\n");
/* global color context */
+ hr = IWICBitmapDecoder_GetColorContexts(decoder, 0, NULL, NULL);
+ ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "GetColorContexts error %#x\n", hr);
+
count = 0xdeadbeef;
hr = IWICBitmapDecoder_GetColorContexts(decoder, 0, NULL, &count);
ok(hr == WINCODEC_ERR_UNSUPPORTEDOPERATION, "GetColorContexts error %#x\n", hr);
@@ -340,6 +343,9 @@ static void test_color_contexts(void)
hr = IWICBitmapDecoder_GetFrame(decoder, 0, &frame);
ok(hr == S_OK, "GetFrame error %#x\n", hr);
+ hr = IWICBitmapFrameDecode_GetColorContexts(frame, 0, NULL, NULL);
+ ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
+
count = 0xdeadbeef;
hr = IWICBitmapFrameDecode_GetColorContexts(frame, 0, NULL, &count);
ok(hr == S_OK, "GetColorContexts error %#x\n", hr);
@@ -366,19 +372,31 @@ static void test_color_contexts(void)
ok(hr == S_OK, "GetColorContexts error %#x\n", hr);
ok(count == 1, "unexpected count %u\n", count);
+ hr = IWICImagingFactory_CreateColorContext(factory, NULL);
+ ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
+
hr = IWICImagingFactory_CreateColorContext(factory, &context);
ok(hr == S_OK, "CreateColorContext error %#x\n", hr);
+ hr = IWICColorContext_GetType(context, NULL);
+ ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
+
type = 0xdeadbeef;
hr = IWICColorContext_GetType(context, &type);
ok(hr == S_OK, "GetType error %#x\n", hr);
ok(type == WICColorContextUninitialized, "unexpected type %u\n", type);
+ hr = IWICColorContext_GetProfileBytes(context, 0, NULL, NULL);
+ ok(hr == WINCODEC_ERR_NOTINITIALIZED, "GetProfileBytes error %#x\n", hr);
+
size = 0;
hr = IWICColorContext_GetProfileBytes(context, 0, NULL, &size);
ok(hr == WINCODEC_ERR_NOTINITIALIZED, "GetProfileBytes error %#x\n", hr);
ok(!size, "unexpected size %u\n", size);
+ hr = IWICColorContext_GetExifColorSpace(context, NULL);
+ ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
+
colorspace = 0xdeadbeef;
hr = IWICColorContext_GetExifColorSpace(context, &colorspace);
ok(hr == S_OK, "GetExifColorSpace error %#x\n", hr);
@@ -424,6 +442,9 @@ static void test_color_contexts(void)
hr = IWICBitmapFrameDecode_GetColorContexts(frame, count, &context, &count);
ok(hr == S_OK, "GetColorContexts error %#x\n", hr);
+ hr = IWICColorContext_GetProfileBytes(context, 0, NULL, NULL);
+ ok(hr == E_INVALIDARG, "expected E_INVALIDARG, got %#x\n", hr);
+
size = 0;
hr = IWICColorContext_GetProfileBytes(context, 0, NULL, &size);
ok(hr == S_OK, "GetProfileBytes error %#x\n", hr);
More information about the wine-cvs
mailing list