-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix GH-14402: Add support for serialization in SplPriorityQueue, SplMinHeap and SplMaxHeap #19447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix GH-14402: Add support for serialization in SplPriorityQueue, SplMinHeap and SplMaxHeap #19447
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the serialization format is unsafe when facing inheritance, since it doesn't clearly distinguish between “regular properties” and “internal state”. Please have a look at the serialization implementation of ext/random engines for a robust example and make sure to include proper error handling (i.e. throwing an \Exception
) when the data does not look as expected during unserialization. Silently doing nothing when the zval types do not match is not okay.
501e55d
to
bec66ee
Compare
I pushed a new version with 3 additional tests:
Tests I pushed are pretty verbose and human friendly, I wonder if they should look like |
I addressed all your comments in 3f041a3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we prevent serialization if the SPL_HEAP_CORRUPTED
flag is set?
I'm also noticing that this PR targets PHP 8.3. I'd argue this is more a feature rather than a bugfix and would recommend targeting master.
Maintenance-wise I think “technical tests” are preferable, this makes sure that they capture every nuance and with the diff output any failures are still pretty readable. You could also take a look at the serialization tests for ext/random. Given that it's a very new extension, I'd say it's in a good shape. And I made sure to very carefully maintain the tests there. |
Yes. I targeted 8.3 because of the bug label on the issue, but it definitely looks like a feature. Let's target master. |
3f041a3
to
5209c63
Compare
…plMinHeap and SplMaxHeap
…plMinHeap and SplMaxHeap
5209c63
to
2236ca2
Compare
4478ef7
to
bb54148
Compare
The two last commits rearrange tests with a more technical approach, adds some more tests and safety about the heap being corrupted. Also, more code form |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic now looks robust to me (didn't look at the test). But as I'm not familiar with the code, I would like to see someone else do a review.
|
||
object_properties_load(&intern->std, Z_ARRVAL_P(props)); | ||
if (EG(exception)) { | ||
RETURN_THROWS(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this one you should throw to wrap the exception into the “Invalid serialization data for %s object” one. When throwing while an exception is already active, the engine will automatically set $previous
:
RETURN_THROWS(); | |
zend_throw_exception_ex(NULL, 0, "Invalid serialization data for %s object", ZSTR_VAL(intern->std.ce->name)); | |
RETURN_THROWS(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case object_properties_load() sets one in the executor globals, alright I get it. PR updated
|
||
object_properties_load(&intern->std, Z_ARRVAL_P(props)); | ||
if (EG(exception)) { | ||
RETURN_THROWS(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
bb54148
to
04bb7cd
Compare
Thanks for the extensive review @TimWolla! |
Fix #14402