Commit c701781
LibGfx: Fix PNG decoder leaks from libpng error longjmp
Problem: Runs of the Linux Sanitizers intermittently fail with
LeakSanitizer leaks of ~45 KB across 21 allocations from
PNGLoadingContext::read_frames() — triggered when the test suite
decodes malformed PNGs.
Cause: When libpng hits a corrupted IDAT chunk inside png_read_image(),
it longjmps back to the setjmp landing pad in
PNGLoadingContext::read_all_frames(). longjmp unwinds the stack without
running C++ destructors — so the stack-locals in read_frames
(Vector<u8*> row_pointers, the in-flight Bitmap inside decode_frame, and
the APNG branch’s output buffer and Painter) leak their heap storage.
Fix: Promote those stack-locals to members of PNGLoadingContext (which
is heap-allocated and outlives the setjmp scope) — so their storage is
reachable by RAII when the context is destroyed. Clear them in the
setjmp error handler too — so memory is released promptly on the error
path, rather than waiting until ~PNGLoadingContext().1 parent 1050981 commit c701781
3 files changed
Lines changed: 43 additions & 6 deletions
File tree
- Libraries/LibGfx/ImageFormats
- Tests/LibGfx
- test-inputs/png
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
37 | 53 | | |
38 | 54 | | |
39 | 55 | | |
40 | 56 | | |
41 | 57 | | |
42 | 58 | | |
43 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
44 | 63 | | |
45 | 64 | | |
46 | 65 | | |
| |||
255 | 274 | | |
256 | 275 | | |
257 | 276 | | |
258 | | - | |
259 | 277 | | |
260 | | - | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
261 | 281 | | |
262 | 282 | | |
263 | 283 | | |
264 | | - | |
| 284 | + | |
265 | 285 | | |
266 | 286 | | |
267 | | - | |
| 287 | + | |
| 288 | + | |
268 | 289 | | |
269 | 290 | | |
270 | 291 | | |
271 | 292 | | |
272 | 293 | | |
273 | 294 | | |
274 | 295 | | |
275 | | - | |
276 | | - | |
| 296 | + | |
| 297 | + | |
277 | 298 | | |
278 | 299 | | |
279 | 300 | | |
| |||
364 | 385 | | |
365 | 386 | | |
366 | 387 | | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
367 | 391 | | |
368 | 392 | | |
369 | 393 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
516 | 516 | | |
517 | 517 | | |
518 | 518 | | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
519 | 532 | | |
520 | 533 | | |
521 | 534 | | |
| |||
Loading
0 commit comments