Fixes the first stbi_load_gif issue in #1838 by clearing delays on all outofmem paths#1839
Fixes the first stbi_load_gif issue in #1838 by clearing delays on all outofmem paths#1839NBickford-NV wants to merge 2 commits into
delays on all outofmem paths#1839Conversation
…destroy its input pointer according to C specification 7.22.3.5 item 3.
|
My colleague Pyarelal Knowles noticed that I made a mistake in simplifying the calls to
I've reverted my changes to |
Updated SDL repos, thanks. |
After calling
stbi_load_gif, apps should free thedelayspointer it passed in ifdelaysis non-null. This means that after freeingdelaysin thestbi__load_gif_main_outofmemerror path, stb_image_load should also setdelaystoNULL. Otherwise if we allocatedelaysonce but we get tostbi__load_gif_main_outofmemon a later frame, then the app sees a non-nulldelayspointer and tries to free it again.With this change, running
clang++ poc.c -fsanitize=address && ./a.out 490442704-000e388f-3edd-409b-9253-83046ac80317.giffrom #1838 now correctly reports "Failed to load GIF" instead of segfaulting.Forks with JarLob's double-free fix in #1549 were also affected; it implemented this logic on some paths, but not all, and #1838 happens to reach one of the other paths. Moving the
delays = NULLlogic tostbi__load_gif_main_outofmemon those forks allows us to save a few lines of code.In addition, since
reallocfirst frees the input pointer (C specification 7.22.3.5 item 1), we shouldn't pass the input tostbi__load_gif_main_outofmemafter a realloc -- then we'd get a different double-free. If we remove the temporary pointer and dop = realloc(p, ...)then I think we get the right behavior and save a few lines of code.Thanks!