Closed smcv closed 4 months ago
That sounds like the right solution.
I'll provide a PR when I've figured out what is even going on in my scout build...
It looks as though d2c7e0905 might have accidentally fixed this as well (it was intentionally fixing a missing close/free, but seems to have unintentionally fixed this double-free at the same time).
I think #430 resolves this, but I want to get to the bottom of what is happening in my scout build to have better confidence about that solution before undrafting it.
To reproduce:
IMG_SaveJPG_RW_jpeglib()
fails. I'm currently trying to backport SDL_image 2.8.2 to Steam Runtime version 1 'scout', an Ubuntu-12.04-based environment, and for whatever reason it's failing; I'll address that eventually when I've figured out what is happening, but for now, it provides a convenient way to exercise failure code-paths that are not normally reached.IMG_SaveJPG_RW_jpeglib()
fail cleanly (at the moment there is another bug in its use ofsetjmp
/longjmp
: #429)IMG_SaveJPG_RW(surface, dst, 1, quality)
, for example viaIMG_SaveJPG
which is called by SDL_image's own test suiteExpected result: Saving with libjpeg fails. SDL_image tries to fall back to tinyjpeg. No crash.
Actual result: First SDL_image calls
IMG_SaveJPG_RW_jpeglib(., ., freedst=1, .)
, and then it callsIMG_SaveJPG_RW_tinyjpeg(., ., freedst=1, .)
. The first call closes (frees) the destination RWops object (file). The second call is a use-after-free and then a double-free, which in my case is detected by glibc, causing anabort()
.Suggested solution: Probably the entire implementation of
freedst
should be inIMG_SaveJPG_RW()
, and the two backend-specific implementationsIMG_SaveJPG_RW_jpeglib()
andIMG_SaveJPG_RW_tinyjpeg()
should never free the RWops object.