Skip to content

fix: handle integers beyond 64-bit in array indexes and round precision - #2144

Open
nagibatorz wants to merge 4 commits into
Shopify:mainfrom
nagibatorz:nagibatorz/bignum-index-round-2142
Open

nagibatorz wants to merge 4 commits into
Shopify:mainfrom
nagibatorz:nagibatorz/bignum-index-round-2142

Conversation

@nagibatorz

Copy link
Copy Markdown

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.

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Array indexes and round precisions beyond a 64-bit integer raise Liquid error: internal

1 participant