Commit 6b68d94
committed
Fix GH-22121: double-free in gdImageSetStyle() after overflow early 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 GH-22121
Closes GH-221251 parent b0ef5fc commit 6b68d94
2 files changed
Lines changed: 7 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
5 | 9 | | |
6 | 10 | | |
7 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2854 | 2854 | | |
2855 | 2855 | | |
2856 | 2856 | | |
2857 | | - | |
2858 | | - | |
2859 | | - | |
2860 | 2857 | | |
2861 | 2858 | | |
2862 | 2859 | | |
| 2860 | + | |
| 2861 | + | |
| 2862 | + | |
2863 | 2863 | | |
2864 | 2864 | | |
2865 | 2865 | | |
| |||
0 commit comments