WineHQ
Bug Tracking Database – Bug 42727

 Bugzilla

 

Last modified: 2017-07-11 12:38:41 CDT  

obsolete 128MB bitmap size limit

Bug 42727 - obsolete 128MB bitmap size limit
obsolete 128MB bitmap size limit
Status: UNCONFIRMED
AppDB: Show Apps affected by this bug
Product: Wine
Classification: Unclassified
Component: gdi32
unspecified
x86-64 Linux
: P2 normal
: ---
Assigned To: Mr. Bugs
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2017-03-28 10:42 CDT by Claude Heiland-Allen
Modified: 2017-07-11 12:38 CDT (History)
0 users

See Also:
Regression SHA1:
Fixed by SHA1:
Distribution: ---
Staged patchset:


Attachments
source code to probe supported bitmap size (904 bytes, text/x-c)
2017-03-28 10:42 CDT, Claude Heiland-Allen
Details
test results for wine 1.8.6-5 on Debian Stretch amd64 (1.41 KB, text/plain)
2017-03-28 10:43 CDT, Claude Heiland-Allen
Details
test results for wine-development 2.0-3 on Debian Stretch amd64 (1.41 KB, text/plain)
2017-03-28 10:44 CDT, Claude Heiland-Allen
Details
test results for Windows 10 Pro 64bit (1.67 KB, text/plain)
2017-03-28 10:45 CDT, Claude Heiland-Allen
Details
test results for Windows 10 Pro 64bit running 32bit test (2.11 KB, text/plain)
2017-03-28 10:45 CDT, Claude Heiland-Allen
Details
test results for Windows 7 Ultimate (1.67 KB, text/plain)
2017-03-28 10:45 CDT, Claude Heiland-Allen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Claude Heiland-Allen 2017-03-28 10:42:51 CDT
Created attachment 57708 [details]
source code to probe supported bitmap size

The current WINE bitmap implementation has a size limit of 128MiB dating back to 2008 with a comment about Windows XP:
https://source.winehq.org/git/wine.git/blob/39935fe5ad889d537d828cc82771bdb969cdb2d4:/dlls/gdi32/bitmap.c#l197

    197     /* XP doesn't allow creating bitmaps larger than 128 MB */
    198     if (bm.bmHeight > 128 * 1024 * 1024 / bm.bmWidthBytes)
    199     {
    200         SetLastError( ERROR_NOT_ENOUGH_MEMORY );
    201         return 0;
    202     }

However, recent versions of Windows seem to have a higher limit, of 2GiB.  Attached source code tries to create bitmaps with increasing sizes (each just under 2^N bytes) and prints successes and eventual failure.

The bitmap test code seems to have a test for individual maximum dimension (width), but not for maximum total bitmap size:
https://source.winehq.org/git/wine.git/blob/39935fe5ad889d537d828cc82771bdb969cdb2d4:/dlls/gdi32/tests/bitmap.c#l1487

Thanks for testing to users at http://www.fractalforums.com/windows-fractal-software/windows-bitmap-size-test/ - I'll attach their results after submitting.
Comment 1 Claude Heiland-Allen 2017-03-28 10:43:43 CDT
Created attachment 57709 [details]
test results for wine 1.8.6-5 on Debian Stretch amd64
Comment 2 Claude Heiland-Allen 2017-03-28 10:44:28 CDT
Created attachment 57710 [details]
test results for wine-development 2.0-3 on Debian Stretch amd64
Comment 3 Claude Heiland-Allen 2017-03-28 10:45:00 CDT
Created attachment 57711 [details]
test results for Windows 10 Pro 64bit
Comment 4 Claude Heiland-Allen 2017-03-28 10:45:28 CDT
Created attachment 57712 [details]
test results for Windows 10 Pro 64bit running 32bit test
Comment 5 Claude Heiland-Allen 2017-03-28 10:45:58 CDT
Created attachment 57713 [details]
test results for Windows 7 Ultimate
Comment 6 Claude Heiland-Allen 2017-07-10 14:33:44 CDT
Possible fix?

        /* Windows doesn't allow creating bitmaps larger than 2GiB */
        if (bm.bmHeight >= 2LL * 1024 * 1024 * 1024 / bm.bmWidthBytes)
        {
            SetLastError( ERROR_NOT_ENOUGH_MEMORY );
            return 0;
        }
Comment 7 Claude Heiland-Allen 2017-07-11 12:38:41 CDT
here's a workaround, avoiding the code path with the bogus 128MB limit:


#include <windows.h>

// based on: https://source.winehq.org/git/wine.git/blob/39935fe5ad889d537d828cc82771bdb969cdb2d4:/dlls/gdi32/gdi_private.h#l561
static inline long long get_bitmap_stride_ll(long long width, long long bpp)
{
  return ((width * bpp + 15LL) >> 3LL) & ~1LL;
}

// workaround https://bugs.winehq.org/show_bug.cgi?id=42727
// "obsolete 128MB bitmap size limit"
// see also: http://www.fractalforums.com/windows-fractal-software/windows-bitmap-size-test/
HBITMAP create_bitmap(HDC hdc, int width, int height)
{
  long long stride = get_bitmap_stride_ll(width, 24LL);
  long long bytes = stride * height;
  if (bytes >= 2LL * 1024LL * 1024LL * 1024LL || bytes <= 0LL)
  {
    return 0;
  }
  BITMAPINFO bmi;
  bmi.bmiHeader.biSize = sizeof(bmi);
  bmi.bmiHeader.biWidth = width;
  bmi.bmiHeader.biHeight = height;
  bmi.bmiHeader.biPlanes = 1;
  bmi.bmiHeader.biBitCount = 24;
  bmi.bmiHeader.biCompression = BI_RGB;
  bmi.bmiHeader.biSizeImage = bytes;
  bmi.bmiHeader.biXPelsPerMeter = 2835; // 72 dpi
  bmi.bmiHeader.biYPelsPerMeter = 2835; // 72 dpi
  bmi.bmiHeader.biClrUsed = 0;
  bmi.bmiHeader.biClrImportant = 0;
  return CreateDIBSection(hdc, &bmi, DIB_RGB_COLORS, 0, 0, 0);
}


Privacy Policy
If you have a privacy inquiry regarding this site, please write to privacy@winehq.org

Hosted By CodeWeavers