+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);
+ 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_without_trailer_1, sizeof(gif_without_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_without_trailer_2, sizeof(gif_without_trailer_2));
+ 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);
+}
+