Repository navigation
fix: handle integers beyond 64-bit in array indexes and round precision - #2144
Open
nagibatorz wants to merge 4 commits into
Open
nagibatorz wants to merge 4 commits into
nagibatorz wants to merge 4 commits into
Conversation
An integer that does not fit in a C long, used as an array index, makes Ruby raise RangeError, which Liquid reports as an internal error. An out-of-range index should be nil like any index past the end. Repro for Shopify#2142.
Array#[] converts its argument to a C long and raises RangeError for an integer that does not fit, which Liquid reported as an internal error. Rescue it for integer keys on arrays and return nil, like any index past the end. Part of Shopify#2142.
Float#round/Integer#round convert the precision to a C long and raise RangeError for a bignum, which Liquid reported as an internal error. A huge precision should be clamped, like truncatewords clamps its word count. Repro for Shopify#2142.
Float#round/Integer#round convert the precision to a C long and raise RangeError for a bignum, which Liquid reported as an internal error. Clamp the precision to [-MAX_I32, MAX_I32], like truncatewords clamps its word count, so a huge precision rounds to the value itself (positive) or to zero (negative). Fixes Shopify#2142.
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.
Fixes #2142. An integer that doesn't fit in a C long, used as an array index or as the precision of round, makes Ruby raise RangeError, which Liquid reported as an internal error. Array#[] with such an index now returns nil, like any index past the end, and round clamps the precision to the 32-bit integer range, like truncatewords clamps its word count. Validation: new tests fail on clean main and pass with the fix; full suite 1063 runs, 0 failures.