Fix GH-22121: double-free in gdImageSetStyle() after overflow early return#71
Fix GH-22121: double-free in gdImageSetStyle() after overflow early return#71iliaal wants to merge 1 commit into
Conversation
|
Thanks @iliaal do not forget to upstream this fix, there is a sliver of hope seemingly someone is taking charge over there ;) |
You are too quick, I am still testing :) Yeah, I'll do PR to GD upstream too once CI/CD confirms this works |
…y return gdImageSetStyle freed im->style before checking overflow2(). When the overflow check tripped and the function early-returned, im->style was left dangling. The next gdImageSetStyle, gdImageDestroy, or gdImageSetPixel gdStyled/gdStyledBrushed dispatch then freed or dereferenced it. Move the overflow check above the free to match upstream libgd (libgd/libgd src/gd.c::gdImageSetStyle), which has always had the check first. The original divergence was an oversight in 77ba248 when the overflow check was ported from libgd 2.0.29. Fixes phpGH-22121
4606a48 to
e45f5f6
Compare
Actually this is a result of a bad port from 2016, upstream actually does things correctly, so doing a correct sync. |
|
Submitted upstream as php#22125. Closing this staging PR. |
|
nice but by upstream, I meant this repository (and need to come up with a C reproducer). |
|
Upstream (GD) doesn't have the problem, because it does overflow check before the free, the issue was only in PHP |
|
ah I missed your previous comment, sorry. Yes indeed upstream gd is correct. |
gdImageSetStyle(ext/gd/libgd/gd.c:2880) freesim->stylebefore callingoverflow2(). When the overflow check trips and the function returns,im->styleis left dangling and the nextgdImageSetStyle,gdImageDestroy, orgdImageSetPixelgdStyled/gdStyledBrusheddispatch frees or dereferences it.Move the overflow check above the free to match upstream libgd (
libgd/libgdsrc/gd.c::gdImageSetStyle), which has always had the check first. The divergence was an oversight in 77ba248 when the overflow check was ported from libgd 2.0.29.Fixes php#22121