From 3d389ee2ac6478a470f19e73826a3889dd117337 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Mon, 17 Feb 2025 09:30:53 +0100 Subject: [PATCH] Windows: Fix rounding error in BitmapInfoHeader calculation A potential rounding error in calculating the padded scanline length could lead to the biSizeImage field being assigned a too small value. Fixes: QTBUG-133782 Pick-to: 6.9 6.8 6.5 Change-Id: I251212cf2859f7268fc8ad6ca1cbc57f2bb1f1c0 Reviewed-by: Friedemann Kleint Reviewed-by: Oliver Wolff --- src/gui/image/qpixmap_win.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/gui/image/qpixmap_win.cpp b/src/gui/image/qpixmap_win.cpp index fc601bccfc1..90ec0f03a74 100644 --- a/src/gui/image/qpixmap_win.cpp +++ b/src/gui/image/qpixmap_win.cpp @@ -48,7 +48,8 @@ static inline void initBitMapInfoHeader(int width, int height, bool topToBottom, bih->biBitCount = WORD(bitCount); bih->biCompression = compression; // scan lines are word-aligned (unless RLE) - const DWORD bytesPerLine = pad4(DWORD(width) * bitCount / 8); + const DWORD bytesPerLine = bitCount == 1 ? pad4(DWORD(qCeil(width / 8.0))) + : pad4(DWORD(width) * bitCount / 8); bih->biSizeImage = bytesPerLine * DWORD(height); }