Repository navigation
fix(flags): guard against option index colliding with SPECIAL_INTEGERS in serialization - #590
Open
reginaldalfret wants to merge 1 commit into
Conversation
…S in serialization When a flag has >= 252 options, option indices at or above MAX_OPTION_LENGTH (252) previously collided with SPECIAL_INTEGERS during deserialization (252 deserialized as NULL, 253 as false, 254 as true, 255 as an unlisted value). Guard matchedIndex < MAX_OPTION_LENGTH so higher option indices are safely preserved via unlisted value transport. Signed-off-by: Reginald Alfret <reginaldalfret@gmail.com>
Contributor
|
@reginaldalfret is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
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.
What?
This PR guards option indices against colliding with \SPECIAL_INTEGERS\ in \packages/flags/src/lib/serialization.ts\ by checking \matchedIndex < MAX_OPTION_LENGTH\ before returning the option index.
Why?
In \serialization.ts, \MAX_OPTION_LENGTH = 252\ was defined to reserve byte values 252–255 for \SPECIAL_INTEGERS:
However, in \serialize():
\\ s
const matchedIndex = matchIndex(options, value);
if (matchedIndex > -1) return matchedIndex;
\
If a flag had 252 or more options, an option at index 252 returned \252, which deserialized as
ull. An option at index 253 deserialized as \alse, index 254 as \ rue, and index 255 attempted to read from the unlisted spillover array (resulting in \undefined\ or crashes). Furthermore, any index >= 256 would be truncated by \Uint8Array\ (\index & 0xFF), corrupting the value.
How?