[3/3] windowscodecs: Fixed loading png from streams

Viktor Semykin thesame.ml at gmail.com
Mon Mar 27 15:09:15 CDT 2017


Png decoder was making one extra seek after it met IEND chunk. This led to
crashes of some software.

Signed-off-by: Viktor Semykin <thesame.ml at gmail.com>
---
 dlls/windowscodecs/pngformat.c       | 7 +++----
 dlls/windowscodecs/tests/pngformat.c | 2 +-
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/dlls/windowscodecs/pngformat.c b/dlls/windowscodecs/pngformat.c
index 990dcf6..c98a6a7 100644
--- a/dlls/windowscodecs/pngformat.c
+++ b/dlls/windowscodecs/pngformat.c
@@ -774,11 +774,12 @@ static HRESULT WINAPI PngDecoder_Initialize(IWICBitmapDecoder *iface, IStream *p
 
     /* Find the metadata chunks in the file. */
     seek.QuadPart = 8;
-    hr = IStream_Seek(pIStream, seek, STREAM_SEEK_SET, &chunk_start);
-    if (FAILED(hr)) goto end;
 
     do
     {
+        hr = IStream_Seek(pIStream, seek, STREAM_SEEK_SET, &chunk_start);
+        if (FAILED(hr)) goto end;
+
         hr = read_png_chunk(pIStream, chunk_type, NULL, &chunk_size);
         if (FAILED(hr)) goto end;
 
@@ -816,8 +817,6 @@ static HRESULT WINAPI PngDecoder_Initialize(IWICBitmapDecoder *iface, IStream *p
         }
 
         seek.QuadPart = chunk_start.QuadPart + chunk_size + 12; /* skip data and CRC */
-        hr = IStream_Seek(pIStream, seek, STREAM_SEEK_SET, &chunk_start);
-        if (FAILED(hr)) goto end;
     } while (memcmp(chunk_type, "IEND", 4));
 
     This->stream = pIStream;
diff --git a/dlls/windowscodecs/tests/pngformat.c b/dlls/windowscodecs/tests/pngformat.c
index 20b6e93..18304a5 100644
--- a/dlls/windowscodecs/tests/pngformat.c
+++ b/dlls/windowscodecs/tests/pngformat.c
@@ -300,7 +300,7 @@ static IWICBitmapDecoder *create_decoder(const void *image_data, UINT image_size
 
     zero.QuadPart = 0;
     IStream_Seek (stream, zero, STREAM_SEEK_CUR, &pos);
-    todo_wine ok(pos.QuadPart < image_size, "seek beyond the end of stream: %lu >= %u\n",
+    ok(pos.QuadPart < image_size, "seek beyond the end of stream: %lu >= %u\n",
         pos.QuadPart, image_size);
 
     refcount = IStream_Release(stream);
-- 
2.12.1




More information about the wine-patches mailing list