Vincent Povirk : windowscodecs: Check for empty rect in WriteSource_Proxy.

Alexandre Julliard julliard at winehq.org
Mon Jun 16 12:37:48 CDT 2014


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

Author: Vincent Povirk <vincent at codeweavers.com>
Date:   Fri Jun 13 14:39:26 2014 -0500

windowscodecs: Check for empty rect in WriteSource_Proxy.

---

 dlls/windowscodecs/main.c            |    2 +-
 dlls/windowscodecs/proxy.c           |    3 ++
 dlls/windowscodecs/tests/converter.c |   50 ++++++++++++++++++++++++++++++----
 3 files changed, 49 insertions(+), 6 deletions(-)

diff --git a/dlls/windowscodecs/main.c b/dlls/windowscodecs/main.c
index a4cb93f..d346711 100644
--- a/dlls/windowscodecs/main.c
+++ b/dlls/windowscodecs/main.c
@@ -182,7 +182,7 @@ HRESULT write_source(IWICBitmapFrameEncode *iface,
         prc = &rc;
     }
 
-    if (prc->Width != width)
+    if (prc->Width != width || prc->Height <= 0)
         return E_INVALIDARG;
 
     stride = (bpp * width + 7)/8;
diff --git a/dlls/windowscodecs/proxy.c b/dlls/windowscodecs/proxy.c
index 53c7d17..38f076f 100644
--- a/dlls/windowscodecs/proxy.c
+++ b/dlls/windowscodecs/proxy.c
@@ -225,6 +225,9 @@ HRESULT WINAPI IWICBitmapFrameEncode_SetThumbnail_Proxy_W(IWICBitmapFrameEncode
 HRESULT WINAPI IWICBitmapFrameEncode_WriteSource_Proxy_W(IWICBitmapFrameEncode *iface,
     IWICBitmapSource *pIBitmapSource, WICRect *prc)
 {
+    if (prc && (prc->Width <= 0 || prc->Height <= 0))
+        prc = NULL;
+
     return IWICBitmapFrameEncode_WriteSource(iface, pIBitmapSource, prc);
 }
 
diff --git a/dlls/windowscodecs/tests/converter.c b/dlls/windowscodecs/tests/converter.c
index 6c3d232..095298f 100644
--- a/dlls/windowscodecs/tests/converter.c
+++ b/dlls/windowscodecs/tests/converter.c
@@ -509,7 +509,7 @@ static void test_encoder_properties(const CLSID* clsid_encoder, IPropertyBag2 *o
 }
 
 static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* clsid_encoder,
-    const struct bitmap_data **dsts, const CLSID *clsid_decoder, const char *name)
+    const struct bitmap_data **dsts, const CLSID *clsid_decoder, WICRect *rc, const char *name)
 {
     HRESULT hr;
     IWICBitmapEncoder *encoder;
@@ -565,8 +565,14 @@ static void test_multi_encoder(const struct bitmap_data **srcs, const CLSID* cls
                     hr = IWICBitmapFrameEncode_SetSize(frameencode, srcs[i]->width, srcs[i]->height);
                     ok(SUCCEEDED(hr), "SetSize failed, hr=%x\n", hr);
 
-                    hr = IWICBitmapFrameEncode_WriteSource(frameencode, &src_obj->IWICBitmapSource_iface, NULL);
-                    ok(SUCCEEDED(hr), "WriteSource failed, hr=%x\n", hr);
+                    hr = IWICBitmapFrameEncode_WriteSource(frameencode, &src_obj->IWICBitmapSource_iface, rc);
+                    if (rc && (rc->Width <= 0 || rc->Height <= 0))
+                    {
+                        /* WriteSource fails but WriteSource_Proxy succeeds. */
+                        ok(hr == E_INVALIDARG, "WriteSource failed, hr=%x (%s)\n", hr, name);
+                        hr = IWICBitmapFrameEncode_WriteSource_Proxy(frameencode, &src_obj->IWICBitmapSource_iface, rc);
+                    }
+                    ok(SUCCEEDED(hr), "WriteSource failed, hr=%x (%s)\n", hr, name);
 
                     hr = IWICBitmapFrameEncode_Commit(frameencode);
                     ok(SUCCEEDED(hr), "Commit failed, hr=%x\n", hr);
@@ -635,7 +641,39 @@ static void test_encoder(const struct bitmap_data *src, const CLSID* clsid_encod
     dsts[0] = dst;
     dsts[1] = NULL;
 
-    test_multi_encoder(srcs, clsid_encoder, dsts, clsid_decoder, name);
+    test_multi_encoder(srcs, clsid_encoder, dsts, clsid_decoder, NULL, name);
+}
+
+static void test_encoder_rects(void)
+{
+    const struct bitmap_data *srcs[2];
+    const struct bitmap_data *dsts[2];
+    WICRect rc;
+
+    srcs[0] = &testdata_24bppBGR;
+    srcs[1] = NULL;
+    dsts[0] = &testdata_24bppBGR;
+    dsts[1] = NULL;
+
+    rc.X = 0;
+    rc.Y = 0;
+    rc.Width = 4;
+    rc.Height = 2;
+
+    test_multi_encoder(srcs, &CLSID_WICTiffEncoder, dsts, &CLSID_WICTiffDecoder, &rc, "test_encoder_rects full");
+
+    rc.Width = 0;
+    test_multi_encoder(srcs, &CLSID_WICTiffEncoder, dsts, &CLSID_WICTiffDecoder, &rc, "test_encoder_rects width=0");
+
+    rc.Width = -1;
+    test_multi_encoder(srcs, &CLSID_WICTiffEncoder, dsts, &CLSID_WICTiffDecoder, &rc, "test_encoder_rects width=-1");
+
+    rc.Width = 4;
+    rc.Height = 0;
+    test_multi_encoder(srcs, &CLSID_WICTiffEncoder, dsts, &CLSID_WICTiffDecoder, &rc, "test_encoder_rects height=0");
+
+    rc.Height = -1;
+    test_multi_encoder(srcs, &CLSID_WICTiffEncoder, dsts, &CLSID_WICTiffDecoder, &rc, "test_encoder_rects height=-1");
 }
 
 static const struct bitmap_data *multiple_frames[3] = {
@@ -673,7 +711,9 @@ START_TEST(converter)
                  &testdata_24bppBGR, &CLSID_WICTiffDecoder, "TIFF encoder 24bppBGR");
 
     test_multi_encoder(multiple_frames, &CLSID_WICTiffEncoder,
-                       multiple_frames, &CLSID_WICTiffDecoder, "TIFF encoder multi-frame");
+                       multiple_frames, &CLSID_WICTiffDecoder, NULL, "TIFF encoder multi-frame");
+
+    test_encoder_rects();
 
     CoUninitialize();
 }




More information about the wine-cvs mailing list