Fix GH-17787: ZipArchive stream truncates when the archive is freed#22555
Open
eyupcanakman wants to merge 1 commit into
Open
Fix GH-17787: ZipArchive stream truncates when the archive is freed#22555eyupcanakman wants to merge 1 commit into
eyupcanakman wants to merge 1 commit into
Conversation
…e is freed getStream(), getStreamIndex() and getStreamName() return a stream that reads from the ZipArchive's underlying zip_t but keeps no reference to it. When the object is freed while the stream is still open, the destructor closes the zip_t and reads stop partway through. Keep the archive object alive for the stream's lifetime so the borrowed handle stays valid until the stream is closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ZipArchive::getStreamIndex()(andgetStream/getStreamName) hands back a stream that reads from the archive's underlyingzip_twithout keeping a reference to it. When theZipArchiveobject is freed while the stream is still open, as in the report where$zgets reassigned inside the read loop, the object destructor closes thezip_tand the stream stops reading early. cmb69 diagnosed this on the issue. The fix keeps the archive object alive for the stream's lifetime, so the borrowed handle stays valid until the stream is closed.One case this does not cover is calling
$zip->close()or reopening the same object while a stream is open, which hits the same truncation by a different route. I can extend the fix to those paths if you prefer.