-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Fixes null pointer dereference in https://github.com/nothings/stb/issues/1452 #1454
base: master
Are you sure you want to change the base?
Conversation
… return 0, and the requested number of components to stbi_load_from_memory is not 0 or 4
Thank you! I have just applied this as a downstream patch in Fedora Linux. |
That's amazingly fast, thank you Ben! (I figured I'd send you an email later this morning since I remember you saw and applied the earlier stb_image patches, but you beat me to it!) |
Mainstream pull requests: nothings/stb#1454 Related mainstream issue tickets: nothings/stb#1452
Mainstream pull requests: nothings/stb#1454 Related mainstream issue tickets: nothings/stb#1452
Tracking CVE numbers: this is a patch for https://nvd.nist.gov/vuln/detail/CVE-2023-43898 ((#1521). |
Looks like this is also a patch for https://nvd.nist.gov/vuln/detail/CVE-2021-45340, which is how this bug appeared in libsixel (see libsixel/libsixel#73 and #1736). |
@NBickford-NV You’ve studied this code more deeply than I am likely to have time to. Do you think #1736 is a wise change in addition to this PR? Is it easy enough to prove that there is nowhere else that |
@musicinmybrain Turns out, that's a really good question! I tried proving this and failed at My attempted proof that this is the only place where
|
Okay, after deeper analysis, I think case 6 might be OK after all, but it's complex.
That is: if I had a go at reproducing this, and if you run the following code you'll notice that execution enters So, because that proof's nontrivial, it's probably a good idea to have #1736 as well! #include "stb_image.h"
#include <stdlib.h>
int test_1454_gif()
{
const stbi_uc data[] = { 'G', 'I', 'F', '8', '9', 'a', // Magic number
1, 0, 1, 0, // Width and height
0, 0, 0}; // flags, bgindex, ratio
int size = (int)sizeof(data);
int *delays = NULL;
int x, y, z, comp;
stbi_uc* image = stbi_load_gif_from_memory(
(const stbi_uc*)data, size,
&delays,
&x, &y, &z,
&comp, 3);
if (image)
{
stbi_image_free(image);
}
if (delays)
{
stbi_image_free(delays);
}
return EXIT_SUCCESS;
} |
Thank you for that very detailed analysis! I’m shipping #1736 as an additional downstream patch in Fedora’s |
I read every email I get, and I get an email for every comment in the repo. It's just a matter of me committing the time to a release cycle. |
Hi stb maintainers!
I just saw issue #1452, and put together this pull request to fix it. When stbi__pic_load_core returns
NULL
, this code now frees the allocated image and returns 0 immediately, instead of passing a null pointer tostbi__convert_format()
.Thanks!