Fix panic in format64_to_fixed when rounding carries past all integer digits#56
Merged
Merged
Conversation
… digits Check round_index == -1 before calling result.get(round_index) in the rounding loop, preventing an out-of-bounds read when the carry propagates through all integer digits (e.g. 9.5 with fraction_digits=0 should produce "10" but instead panics in debug builds). Fixes boa-dev#55
HalidOdat
approved these changes
Jul 5, 2026
HalidOdat
left a comment
Member
There was a problem hiding this comment.
Looks great to me! Thank you for the contribution!! (and sorry for the delay 😅)
I'll adjust the round_index to be usize type (as well as Cursor) to ensure that this type of issue with negative indices does not happen again, and will release a fix ASAP 😄
Member
|
Note: Had to close and re-open to trigger the CI to run 😄 |
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
Fixes #55.
format64_to_fixedpanics in debug builds when rounding causes a carry that propagates through all integer digits (e.g.9.5withfraction_digits=0).Root Cause
The rounding loop calls
result.get(round_index)before checkinground_index == -1, causing an out-of-bounds read when every integer digit is9and the carry reaches index-1.Fix
Move the
round_index == -1boundary check before theresult.get()call, and split it from thec == b'-'check into its own branch.Tests
Added
rounding_carry_past_all_digitsandrounding_carry_negativetests. All 70 tests pass.