fix: Clear stale zstream pointers when releasing the inflate stream
The zstream buffer pointers and counters are all cleared on acquisition
in `png_inflate_claim`, but only `next_in` and `avail_in` were cleared
on release in `png_read_finish_IDAT`, and none were cleared on release
in the chunk decompression paths.
If `png_read_end` is called before row reading starts, the IDAT stream
is never claimed. Previously, a leftover non-zero `avail_in` caused the
refill in `png_read_IDAT_data` to be skipped, and inflation continued
through a stale `next_in` into an input buffer that may since have been
deallocated.
Introduce the function `png_inflate_detach_buffers` to clear the
pointers and the counters of zstream input and output buffers on both
acquisition and release. Although clearing `next_out` and `avail_out`
is not currently necessary at any call site, it makes release mirror
acquisition at a negligible cost paid once for each zlib stream.
This is a cherry-pick of commit 6c7783b151377f591c83955e23da50991ad1a600
from branch 'libpng18'.
Reported-by: Ze Sheng <OwenSanzas@users.noreply.github.com>
Reported-by: JasonHonKL <JasonHonKL@users.noreply.github.com>
1 file changed