Skip to content

validate ZIP central directory and throw on corruption#39

Open
splitbrain wants to merge 4 commits into
masterfrom
claude/validate-zip-corruption-QNM1u
Open

validate ZIP central directory and throw on corruption#39
splitbrain wants to merge 4 commits into
masterfrom
claude/validate-zip-corruption-QNM1u

Conversation

@splitbrain
Copy link
Copy Markdown
Owner

The readCentralDir() scan for the End-of-Central-Directory signature
silently fell through when it was missing, leaving the file pointer
past EOF and feeding null to unpack(). That surfaced as PHP warnings
("unpack(): Type V: not enough input") rather than a meaningful error.

Detect both the missing EOCD signature and a failed unpack() and raise
ArchiveCorruptedException instead, matching the error handling used
elsewhere in the package. Added tests covering a non-ZIP payload and
a file too short to hold an EOCD record.

claude added 4 commits May 12, 2026 23:02
The readCentralDir() scan for the End-of-Central-Directory signature
silently fell through when it was missing, leaving the file pointer
past EOF and feeding null to unpack(). That surfaced as PHP warnings
("unpack(): Type V: not enough input") rather than a meaningful error.

Detect both the missing EOCD signature and a failed unpack() and raise
ArchiveCorruptedException instead, matching the error handling used
elsewhere in the package. Added tests covering a non-ZIP payload and
a file too short to hold an EOCD record.
Drop the $found flag: after the loop, $bytes can only equal the EOCD
signature if we broke out, since the check runs on every iteration.
Three ZIP record signatures were sprinkled through the file as raw
byte literals (one as a uint32 in the EOCD scan, three more as
"\x50\x4b..." strings on write). Pull them out as SIG_* class
constants and convert the EOCD scan to a 4-byte sliding string
buffer so reads and writes share a single source of truth.
CI failed only on PHP 8.0 / windows-latest. Replace tempnam() with the
sys_get_temp_dir() + md5(uniqid()) pattern the rest of the suite uses,
and explicitly close the Zip handle in finally so Windows can unlink
the temp file (open handles block deletion).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants