Skip to content

Fix GH-21682: Add NOT_SERIALIZABLE to ZipArchive#21708

Open
iliaal wants to merge 2 commits into
php:masterfrom
iliaal:fix/gh-21682-ziparchive-not-serializable-zip
Open

Fix GH-21682: Add NOT_SERIALIZABLE to ZipArchive#21708
iliaal wants to merge 2 commits into
php:masterfrom
iliaal:fix/gh-21682-ziparchive-not-serializable-zip

Conversation

@iliaal

@iliaal iliaal commented Apr 10, 2026

Copy link
Copy Markdown
Contributor

Part of #21682, split from #21694 after review feedback.

ZipArchive wraps a libzip archive handle that can't survive serialization. serialize() produces a string, but unserializing it returns an object where numFiles reports 0 and the archive contents are gone.

Adds @not-serializable so serialize() throws instead of producing a broken object.

The UAF exploit test bug72434.phpt instantiated ZipArchive via unserialize(). With NOT_SERIALIZABLE, unserialize() rejects the class and closes the UAF vector. The test also moves to ext/zip/tests/ since it exercises ZipArchive.

Per the discussion on #21694, ZipArchive::closeString() (in flight as #21497) gives subclasses a way to capture archive state, so this decision is worth revisiting once that lands.

@DanielEScherzer DanielEScherzer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking as "request changes" so that this doesn't merge until we can evaluate the impact of #21497

iliaal added 2 commits June 13, 2026 09:33
ZipArchive allowed serialization, producing a string that unserializes
into an empty object with no open file handle. Add the
@not-serializable annotation so serialize() throws an exception.

Closes phpGH-21682
bug72434.phpt tested a UAF via unserialize() of ZipArchive. With
NOT_SERIALIZABLE, unserialize() rejects the class entirely, preventing
the UAF by construction. Update the test to verify the rejection and
move it to ext/zip/tests since it requires the zip extension.
@iliaal iliaal force-pushed the fix/gh-21682-ziparchive-not-serializable-zip branch from 2d9a1c1 to 0feac9f Compare June 13, 2026 13:37
@DanielEScherzer

Copy link
Copy Markdown
Member

Per the discussion on #21694, ZipArchive::closeString() (in flight as #21497) gives subclasses a way to capture archive state, so this decision is worth revisiting once that lands.

@iliaal does this change things? Specifically, you should now be able to round-trip by serializing with closeString() and unserializing with openString()

CC @tstarling

@iliaal

iliaal commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

closeString()/openString() are an explicit, manual round-trip; they don't touch serialize(). The flag blocks the implicit serialize(), which still returns a broken object (numFiles 0) and still feeds the bug72434 UAF. That's unchanged by closeString existing.

Until ZipArchive actually implements serialization (and handles file-backed archives, which have no string export), the broken object and the UAF are real and the serialize/unserialize block is still needed. The flag and __serialize are mutually exclusive, so whoever implements that later just drops the flag. I'd add it now.

@tstarling

Copy link
Copy Markdown
Contributor

I think the change is still appropriate. ZipArchive holds uncommitted changes to the underlying file. If serialization was implemented then it would have to restore the state including uncommitted changes, as distinct from the archive file contents. For example ZipArchive::unchangeAll() makes this distinction visible to the user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants