Jinoh Kang : gdi32: Calculate effective number of scan lines and truncate bitmap bits for EMR_SETDIBITSTODEVICE.

Alexandre Julliard julliard at winehq.org
Mon Nov 8 15:45:05 CST 2021


Module: wine
Branch: master
Commit: 9301a9e1f89f7b049362b5143f52845bbf9cb341
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=9301a9e1f89f7b049362b5143f52845bbf9cb341

Author: Jinoh Kang <jinoh.kang.kr at gmail.com>
Date:   Sat Nov  6 01:37:35 2021 +0900

gdi32: Calculate effective number of scan lines and truncate bitmap bits for EMR_SETDIBITSTODEVICE.

Signed-off-by: Jinoh Kang <jinoh.kang.kr at gmail.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/gdi32/emfdc.c          | 20 ++++++++++++++++++++
 dlls/gdi32/tests/metafile.c |  7 -------
 2 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/dlls/gdi32/emfdc.c b/dlls/gdi32/emfdc.c
index 093f2d83737..d0b9033722c 100644
--- a/dlls/gdi32/emfdc.c
+++ b/dlls/gdi32/emfdc.c
@@ -1815,6 +1815,7 @@ BOOL EMFDC_SetDIBitsToDevice( DC_ATTR *dc_attr, INT x_dst, INT y_dst, DWORD widt
     EMRSETDIBITSTODEVICE *emr;
     BOOL ret;
     UINT bmi_size, img_size, payload_size, emr_size;
+    UINT src_height, stride;
     BITMAPINFOHEADER bih;
     BITMAPINFO *bi;
 
@@ -1822,6 +1823,25 @@ BOOL EMFDC_SetDIBitsToDevice( DC_ATTR *dc_attr, INT x_dst, INT y_dst, DWORD widt
     if (!emf_parse_user_bitmapinfo( &bih, &info->bmiHeader, usage, TRUE,
                                     &bmi_size, &img_size )) return 0;
 
+    if (bih.biHeight >= 0)
+    {
+        src_height = (UINT)bih.biHeight;
+        if (src_height > y_src + height) src_height = y_src + height;
+
+        if (src_height < startscan) lines = 0;
+        else if (lines > src_height - startscan) lines = src_height - startscan;
+
+        if (!lines) return 0;
+
+        if (bih.biCompression == BI_RGB || bih.biCompression == BI_BITFIELDS)
+        {
+            /* truncate image and check for overflows */
+            stride = get_dib_stride( bih.biWidth, bih.biBitCount );
+            img_size = lines * stride;
+            if (img_size / stride != lines) return 0;
+        }
+    }
+
     /* check for overflows */
     payload_size = bmi_size + img_size;
     if (payload_size < bmi_size) return 0;
diff --git a/dlls/gdi32/tests/metafile.c b/dlls/gdi32/tests/metafile.c
index 25c851e7384..2df38674c2f 100644
--- a/dlls/gdi32/tests/metafile.c
+++ b/dlls/gdi32/tests/metafile.c
@@ -7764,13 +7764,6 @@ static void test_emf_SetDIBitsToDevice(void)
     {
         winetest_push_context("Test %d", test_idx);
 
-        if (tests[test_idx].height != bitmap_height && !strcmp(winetest_platform, "wine"))
-        {
-            skip("Wine does not adjust cLines appropriately\n");
-            winetest_pop_context();
-            continue;
-        }
-
         memset(&bmi, 0, sizeof(bmi));
         if (tests[test_idx].infomode < 2)
         {




More information about the wine-cvs mailing list