Dmitry Timoshkov : windowscodecs/tests: Add some tests for loading truncated GIF images.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Jul 14 09:42:26 CDT 2015


Module: wine
Branch: master
Commit: 51a3bc2d9d42bcf0065e95a1795c69c427f02ce9
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=51a3bc2d9d42bcf0065e95a1795c69c427f02ce9

Author: Dmitry Timoshkov <dmitry at baikal.ru>
Date:   Mon Jul 13 17:09:30 2015 +0800

windowscodecs/tests: Add some tests for loading truncated GIF images.

---

 dlls/windowscodecs/gifformat.c       |   8 ++-
 dlls/windowscodecs/tests/gifformat.c | 106 +++++++++++++++++++++++++++++++++--
 2 files changed, 108 insertions(+), 6 deletions(-)

diff --git a/dlls/windowscodecs/gifformat.c b/dlls/windowscodecs/gifformat.c
index 3a82c09..d134515 100644
--- a/dlls/windowscodecs/gifformat.c
+++ b/dlls/windowscodecs/gifformat.c
@@ -1055,10 +1055,13 @@ static ULONG WINAPI GifDecoder_Release(IWICBitmapDecoder *iface)
 
     if (ref == 0)
     {
-        IStream_Release(This->stream);
+        if (This->stream)
+        {
+            IStream_Release(This->stream);
+            DGifCloseFile(This->gif);
+        }
         This->lock.DebugInfo->Spare[0] = 0;
         DeleteCriticalSection(&This->lock);
-        DGifCloseFile(This->gif);
         HeapFree(GetProcessHeap(), 0, This);
     }
 
@@ -1435,6 +1438,7 @@ HRESULT GifDecoder_CreateInstance(REFIID iid, void** ppv)
 
     This->IWICBitmapDecoder_iface.lpVtbl = &GifDecoder_Vtbl;
     This->IWICMetadataBlockReader_iface.lpVtbl = &GifDecoder_BlockVtbl;
+    This->stream = NULL;
     This->ref = 1;
     This->initialized = FALSE;
     This->gif = NULL;
diff --git a/dlls/windowscodecs/tests/gifformat.c b/dlls/windowscodecs/tests/gifformat.c
index 5b4cd8bc..85ffc8f 100644
--- a/dlls/windowscodecs/tests/gifformat.c
+++ b/dlls/windowscodecs/tests/gifformat.c
@@ -80,15 +80,12 @@ static const char gif_frame_sizes[] = {
 
 static IWICImagingFactory *factory;
 
-static IWICBitmapDecoder *create_decoder(const void *image_data, UINT image_size)
+static IStream *create_stream(const void *image_data, UINT image_size)
 {
     HGLOBAL hmem;
     BYTE *data;
     HRESULT hr;
-    IWICBitmapDecoder *decoder = NULL;
     IStream *stream;
-    GUID format;
-    LONG refcount;
 
     hmem = GlobalAlloc(0, image_size);
     data = GlobalLock(hmem);
@@ -98,6 +95,20 @@ static IWICBitmapDecoder *create_decoder(const void *image_data, UINT image_size
     hr = CreateStreamOnHGlobal(hmem, TRUE, &stream);
     ok(hr == S_OK, "CreateStreamOnHGlobal error %#x\n", hr);
 
+    return stream;
+}
+
+static IWICBitmapDecoder *create_decoder(const void *image_data, UINT image_size)
+{
+    HRESULT hr;
+    IWICBitmapDecoder *decoder;
+    IStream *stream;
+    GUID format;
+    LONG refcount;
+
+    stream = create_stream(image_data, image_size);
+    if (!stream) return NULL;
+
     hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
     ok(hr == S_OK, "CreateDecoderFromStream error %#x\n", hr);
 
@@ -402,6 +413,92 @@ static void test_gif_frame_sizes(void)
     IWICBitmapDecoder_Release(decoder);
 }
 
+static const char gif_with_trailer_1[] = {
+/* LSD */'G','I','F','8','7','a',0x01,0x00,0x01,0x00,0x80,0x00,0x00,
+/* palette */0xff,0xff,0xff,0xff,0xff,0xff,
+/* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
+/* image data */0x02,0x02,0x44,0x01,0x00,0x3b
+};
+static const char gif_with_trailer_2[] = {
+/* LSD */'G','I','F','8','7','a',0x01,0x00,0x01,0x00,0x00,0x00,0x00,
+/* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
+/* image data */0x02,0x02,0x44,0x3b
+};
+static const char gif_without_trailer_1[] = {
+/* LSD */'G','I','F','8','7','a',0x01,0x00,0x01,0x00,0x80,0x00,0x00,
+/* palette */0xff,0xff,0xff,0xff,0xff,0xff,
+/* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
+/* image data */0x02,0x02,0x44,0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef
+};
+
+static const char gif_without_trailer_2[] = {
+/* LSD */'G','I','F','8','7','a',0x01,0x00,0x01,0x00,0x00,0x00,0x00,
+/* IMD */0x2c,0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x00,0x00,
+/* image data */0x02,0x02,0x44,0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef
+};
+
+static void test_truncated_gif(void)
+{
+    HRESULT hr;
+    IStream *stream;
+    IWICBitmapDecoder *decoder;
+    GUID format;
+
+    stream = create_stream(gif_with_trailer_1, sizeof(gif_with_trailer_1));
+    if (!stream) return;
+
+    hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
+    ok(hr == S_OK, "CreateDecoderFromStream error %#x\n", hr);
+    hr = IWICBitmapDecoder_GetContainerFormat(decoder, &format);
+    ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
+    ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
+       "wrong container format %s\n", wine_dbgstr_guid(&format));
+    IWICBitmapDecoder_Release(decoder);
+    IStream_Release(stream);
+
+    stream = create_stream(gif_with_trailer_2, sizeof(gif_with_trailer_2));
+    if (!stream) return;
+    hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
+todo_wine
+    ok(hr == S_OK, "CreateDecoderFromStream error %#x\n", hr);
+if (hr != S_OK) goto skip_1;
+    hr = IWICBitmapDecoder_GetContainerFormat(decoder, &format);
+    ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
+    ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
+       "wrong container format %s\n", wine_dbgstr_guid(&format));
+    IWICBitmapDecoder_Release(decoder);
+skip_1:
+    IStream_Release(stream);
+
+    stream = create_stream(gif_without_trailer_1, sizeof(gif_without_trailer_1));
+    if (!stream) return;
+    hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
+todo_wine
+    ok(hr == S_OK, "CreateDecoderFromStream error %#x\n", hr);
+if (hr != S_OK) goto skip_2;
+    hr = IWICBitmapDecoder_GetContainerFormat(decoder, &format);
+    ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
+    ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
+       "wrong container format %s\n", wine_dbgstr_guid(&format));
+    IWICBitmapDecoder_Release(decoder);
+skip_2:
+    IStream_Release(stream);
+
+    stream = create_stream(gif_without_trailer_2, sizeof(gif_without_trailer_2));
+    if (!stream) return;
+    hr = IWICImagingFactory_CreateDecoderFromStream(factory, stream, NULL, 0, &decoder);
+todo_wine
+    ok(hr == S_OK, "CreateDecoderFromStream error %#x\n", hr);
+if (hr != S_OK) goto skip_3;
+    hr = IWICBitmapDecoder_GetContainerFormat(decoder, &format);
+    ok(hr == S_OK, "GetContainerFormat error %#x\n", hr);
+    ok(IsEqualGUID(&format, &GUID_ContainerFormatGif),
+       "wrong container format %s\n", wine_dbgstr_guid(&format));
+    IWICBitmapDecoder_Release(decoder);
+skip_3:
+    IStream_Release(stream);
+}
+
 START_TEST(gifformat)
 {
     HRESULT hr;
@@ -428,6 +525,7 @@ START_TEST(gifformat)
     test_global_gif_palette_2frames();
     test_local_gif_palette();
     test_gif_frame_sizes();
+    test_truncated_gif();
 
     IWICImagingFactory_Release(factory);
 }




More information about the wine-cvs mailing list