From: Bruno Jesus <00cpxxx@gmail.com> Subject: gdi32: Support negative count values in GetBitmapBits Message-Id: Date: Tue, 7 Apr 2015 23:19:44 -0300 Fixes bug https://bugs.winehq.org/show_bug.cgi?id=32719 diff --git a/dlls/gdi32/bitmap.c b/dlls/gdi32/bitmap.c index 79374a0..6d1bed9 100644 --- a/dlls/gdi32/bitmap.c +++ b/dlls/gdi32/bitmap.c @@ -253,7 +253,7 @@ LONG WINAPI GetBitmapBits( dst_stride = get_bitmap_stride( bmp->dib.dsBm.bmWidth, bmp->dib.dsBm.bmBitsPixel ); ret = max = dst_stride * bmp->dib.dsBm.bmHeight; if (!bits) goto done; - if (count > max) count = max; + if (count < 0 || count > max) count = max; ret = count; src.visrect.left = 0; diff --git a/dlls/gdi32/tests/bitmap.c b/dlls/gdi32/tests/bitmap.c index 84f843f..e19c552 100644 --- a/dlls/gdi32/tests/bitmap.c +++ b/dlls/gdi32/tests/bitmap.c @@ -56,8 +56,9 @@ static void test_bitmap_info(HBITMAP hbm, INT expected_depth, const BITMAPINFOHE { BITMAP bm; BITMAP bma[2]; - INT ret, width_bytes; + INT ret, width_bytes, i; BYTE buf[512], buf_cmp[512]; + INT test_size[] = {0 /*first value will be changed */, 0, -1, -1000, ~0, sizeof(buf)}; ret = GetObjectW(hbm, sizeof(bm), &bm); ok(ret == sizeof(bm), "GetObject returned %d\n", ret); @@ -75,17 +76,28 @@ static void test_bitmap_info(HBITMAP hbm, INT expected_depth, const BITMAPINFOHE assert(sizeof(buf) == sizeof(buf_cmp)); SetLastError(0xdeadbeef); - ret = GetBitmapBits(hbm, 0, NULL); - ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight); + test_size[0] = bm.bmWidthBytes * bm.bmHeight; + /* NULL output buffer with different count values */ + for (i = 0; i < sizeof(test_size) / sizeof(test_size[0]); i++) + { + ret = GetBitmapBits(hbm, test_size[i], NULL); + ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight); + } memset(buf_cmp, 0xAA, sizeof(buf_cmp)); memset(buf_cmp, 0, bm.bmWidthBytes * bm.bmHeight); - memset(buf, 0xAA, sizeof(buf)); - ret = GetBitmapBits(hbm, sizeof(buf), buf); - ok(ret == bm.bmWidthBytes * bm.bmHeight, "%d != %d\n", ret, bm.bmWidthBytes * bm.bmHeight); - ok(!memcmp(buf, buf_cmp, sizeof(buf)), - "buffers do not match, depth %d\n", bmih->biBitCount); + /* Correct output buffer with different count values */ + for (i = 0; i < sizeof(test_size) / sizeof(test_size[0]); i++) + { + int expect = i == 1 ? 0 : bm.bmWidthBytes * bm.bmHeight; + memset(buf, 0xAA, sizeof(buf)); + ret = GetBitmapBits(hbm, test_size[i], buf); + ok(ret == expect, "Test[%d]: %d != %d\n", i, ret, expect); + if (expect) + ok(!memcmp(buf, buf_cmp, sizeof(buf)), + "Test[%d]: buffers do not match, depth %d\n", i, bmih->biBitCount); + } /* test various buffer sizes for GetObject */ ret = GetObjectW(hbm, sizeof(*bma) * 2, bma);