Repository navigation
Conversation
There was no public way to list the entries of an archive before extracting it, which callers need to validate names and sizes. Add ListableInterface with listContents(), implemented by Zip (natively or with the PHP reader) and Tar. Zip::checkZipData() only tested whether the local file header signature occurs anywhere in the data, so any text containing "PK\x03\x04" passed. Check for an end of central directory record at the end of the data that points to a central directory inside it instead. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary of Changes
Two additions that callers need to validate archives before extracting them; both are backward compatible:
ListableInterface::listContents(string $archive): array, implemented byZip(withext-zipor the PHP reader) andTar. It returnsname(as stored, not sanitised),size(declared uncompressed size) andtype(file,directoryorother) for every entry without extracting anything. Until now there was no public way to see what an archive contains before writing it to disk. It is a separate interface, soExtractableInterfaceand custom adapters are unaffected; gzip/bzip2 hold a single stream and are not listable.Zip::checkZipData()only tested whether the local file header signaturePK\x03\x04occurs anywhere in the data, so arbitrary text containing it passed. It now requires an end of central directory record at the end of the data (followed by an optional comment of up to 65535 bytes) whose central directory lies inside the data. Empty archives and ZIP64 archives are accepted.Typed signatures for
ExtractableInterfacefollow in a separate 5.x PR.Testing Instructions
ZipTest::testListContents(native and PHP reader, with a directory entry and a../name),TarTest::testListContents, and the missing-archive cases.ZipTest::testCheckZipDataUsesTheEndOfCentralDirectory(text with the signature, too short, empty archive with and without comment, record pointing outside the data) andtestCheckZipDataRejectsTruncatedArchives. The existingtestCheckZipData(real ZIP and TAR fixtures) andtestCreatestill pass.All new tests fail on
4.x-dev.vendor/bin/phpunit, phpcs onsrc/and PHPStan are clean.Documentation Changes Required
docs/overview.mdgains a section "Listing the entries of an archive", including the strictercheckZipData(). The owner's documentation PR #49 says "Zip::checkZipData()is a weak test"; whichever of the two is merged second should drop that paragraph.Behaviour change in 4.x:
checkZipData()returnsfalsefor data that is not a complete ZIP archive (e.g. truncated downloads), where it used to returntrue.🤖 Generated with Claude Code