Fix reference numbering for null values and value references#44
Open
alex-radch wants to merge 2 commits intoStringEpsilon:mainfrom
Open
Fix reference numbering for null values and value references#44alex-radch wants to merge 2 commits intoStringEpsilon:mainfrom
alex-radch wants to merge 2 commits intoStringEpsilon:mainfrom
Conversation
599aa21 to
3103e93
Compare
Owner
|
Did you write the code with help of an LLM? The PR description very much reads so. |
Author
|
No, the code was written only by me, LLM helped me only with PR description. When I was looking for a PHP de/serialization library for .NET, I found this one right away, so I didn't look at other implementations. I checked on 10+ different serialized strings from project I'm working on, but none of them have |
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
This PR fixes two bugs in reference handling during deserialization that caused incorrect reference resolution in complex serialized structures.
Problem
When deserializing PHP serialized strings containing references, the library would fail with errors like:
or
This happened because the reference numbering in the library did not match PHP's actual numbering scheme.
Root Causes
PHP's serialize() counts ALL values in reference numbering, including null. The library was always assigning reference index 0 to null tokens instead of incrementing the counter.
PHP has two types of references:
In PHP's serialization, value references are counted towards reference numbering, but variable references are not. The library was treating both the same way (not counting either).
Example
Given input with multiple value references like r:12 appearing several times before r:49, the library would resolve r:49 to the wrong token because each r:12 should have shifted the numbering by 1.
Changes
Testing