From 09a07d4ae8ba47e989b5a5c4235da3c0eb6c95e1 Mon Sep 17 00:00:00 2001 From: jet <34238471+jet2jet@users.noreply.github.com> Date: Tue, 8 Oct 2024 21:07:56 +0900 Subject: [PATCH] Merge pull request #56 from jet2jet/feature/fix_icon_item_image_size Fix icon item image size to ignore biImageSize when biCompression is BI_RGB --- src/main/data/IconItem.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/data/IconItem.ts b/src/main/data/IconItem.ts index a72edeb..779c2f0 100644 --- a/src/main/data/IconItem.ts +++ b/src/main/data/IconItem.ts @@ -101,7 +101,17 @@ export default class IconItem { // round up to 4 bytes (32 bit) const widthBytes = roundUp(bi.bitCount * Math.abs(bi.width), 32) / 8; const absActualHeight = Math.abs(bi.height) / 2; - const size = sizeImage || widthBytes * absActualHeight; + // sizeImage may be weird if compression is 0 (BI_RGB), so + // we calculate actual bitmap size from width and height + const size = + bi.compression !== 0 && sizeImage !== 0 + ? sizeImage + : widthBytes * absActualHeight; + if (size + offset > totalSize) { + throw new Error( + `Unexpected bitmap data in icon: bitmap size ${size} is larger than ${totalSize} - ${offset}` + ); + } this._pixels = allocatePartialBinary(view, offset, size); offset += size; const maskSize = calcMaskSize(bi.width, absActualHeight);