Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stb_image] image too large check is wrong #1659

Open
MWP opened this issue Jul 2, 2024 · 1 comment
Open

[stb_image] image too large check is wrong #1659

MWP opened this issue Jul 2, 2024 · 1 comment

Comments

@MWP
Copy link

MWP commented Jul 2, 2024

stb_image being used on a STM32 ARM Cortex-M7 micro controller.
Firmware built using gcc.

stb/stb_image.h

Line 5121 in 013ac3b

if ((1 << 30) / s->img_x / s->img_n < s->img_y) return stbi__err("too large", "Image too large to decode");

stb_image.h line 5121 checking size of a PNG image returns with the error "Image too large to decode", when it should not.
In my test case, the PNG is 8bpp, RGBA, 300 x 100 pixels.
I have step-debugged the code, img_x, img_y, img_n are correct (300, 100, 4 respectively).

@NBickford-NV
Copy link
Contributor

Hi! I'm trying to think about how this can happen -- are ints 16 bits on this platform, maybe? (1 << 30) / s->img_x / s->img_n here should evaluate to (1 << 30) / 300 / 4 == 894784, but if (1 << 30)'s truncated to 16 bits, then it would evaluate to 0. (The idea behind this check is that it tests whether x * y * n > 2^30 without risking integer overflow.)

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants