Skip to content

use size_t for pixel count in wuffs png loader#657

Merged
solidpixel merged 1 commit into
ARM-software:mainfrom
sahvx655-wq:png-pixel-count-size_t
Jul 8, 2026
Merged

use size_t for pixel count in wuffs png loader#657
solidpixel merged 1 commit into
ARM-software:mainfrom
sahvx655-wq:png-pixel-count-size_t

Conversation

@sahvx655-wq

Copy link
Copy Markdown
Contributor
  1. dim_x and dim_y come from the PNG image config as uint32_t, so num_pixels = dim_x * dim_y is evaluated in 32-bit and wraps once the pixel count reaches 2^32 (65536x65536 truncates to 0, 65536x65537 to 65536).
  2. the wrapped count then slips past the num_pixels > SIZE_MAX / 4 guard on the next line and sizes the pixbuf allocation, so the oversize rejection never fires and the buffer is under-sized for the real dimensions.

Widened the first multiply to size_t so the count and the guard are computed at full width, matching the sizing in alloc_image and the KTX/DDS/ASTC loaders. Wuffs' own slice-length check still rejects the mismatch today, so this keeps the guard correct rather than fixing a live overflow.

@solidpixel solidpixel merged commit 3d22be8 into ARM-software:main Jul 8, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants