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

packer: Fix possible array indexing error when pixels is null #54

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hexaredecimal
Copy link

Saw this bug while watching the stream on YT. The bug is that pixels is indexed before the null check and that could result in a fatal error in case of a null value. The null check is done a little bit late.

koil/packer.c3

Lines 24 to 32 in 48d0f0d

char *pixels = stbi_load((ZString)filename, &x, &y, null, comp);
int size = x*y*comp;
usz offset = pack.len();
assets.push({filename, offset, x, y});
pack.append_chars((String)pixels[0..size-1]);
if (pixels == null) {
io::printf("ERROR: could not load file %s\n", filename);
return 1;
}

What I did

Moved the lines for getting the offset, size, appending to assets and appending pixels to the pack to run after the null check.

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.

1 participant