Fix GH-21682: Add NOT_SERIALIZABLE to ZipArchive#21708
Conversation
DanielEScherzer
left a comment
There was a problem hiding this comment.
Marking as "request changes" so that this doesn't merge until we can evaluate the impact of #21497
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.
2d9a1c1 to
0feac9f
Compare
@iliaal does this change things? Specifically, you should now be able to round-trip by serializing with closeString() and unserializing with openString() CC @tstarling |
|
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 |
|
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 |
Part of #21682, split from #21694 after review feedback.
ZipArchivewraps a libzip archive handle that can't survive serialization.serialize()produces a string, but unserializing it returns an object wherenumFilesreports 0 and the archive contents are gone.Adds
@not-serializablesoserialize()throws instead of producing a broken object.The UAF exploit test
bug72434.phptinstantiatedZipArchiveviaunserialize(). WithNOT_SERIALIZABLE,unserialize()rejects the class and closes the UAF vector. The test also moves toext/zip/tests/since it exercisesZipArchive.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.