[php-src] PR #23824: Fix bzopen() ownership of the stream it wraps
| From: | bukka | Date: | Mon, 21 Sep 2026 14:27:41 +0000 |
| Subject: | [php-src] PR #23824: Fix bzopen() ownership of the stream it wraps | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-38677@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/23824
Author: bukka
bzopen() with a stream argument, and the wrapper fallback in _php_stream_bz2open(), pass the
stream's own descriptor to BZ2_bzdopen(). bzlib takes ownership of it and closes it in
BZ2_bzclose(), after which the inner stream close closes the same descriptor number again. The bz2
stream also keeps a raw pointer to the inner stream while holding a reference on its resource only,
so closing the inner stream with fclose() left a dangling pointer that the bz2 close dereferenced,
while bzlib kept using a descriptor number that could already belong to another file.
Hand bzlib a duplicate of the descriptor and resolve the inner stream from its resource on close, so
a closed inner stream is skipped.