Skip to content

fix signed overflow reading long digit strings in as_i, <i> and <t> - #481

Merged
ohler55 merged 1 commit into
ohler55:developfrom
shamsManna:digit-overflow-check
Nov 6, 2026
Merged

ohler55 merged 1 commit into
ohler55:developfrom
shamsManna:digit-overflow-check

Conversation

@shamsManna

Copy link
Copy Markdown
Contributor

Ox::Sax::Value#as_i, object mode <i>, and both copies of parse_double_time (as_time and object mode <t>) add up document digits in a long or time_t with no overflow check, so a long digit string is signed overflow and wraps to whatever the document wants: as_i on 9223372036854775808 gives -9223372036854775808, 18446744073709551617 gives 1 from both as_i and <i>, and as_time on 18446744073709551617.5 gives 1970-01-01 00:00:01.5. the integer paths now stop accumulating before LONG_MAX, still check the rest of the digits, and hand the text to rb_cstr_to_inum so the caller gets the real Integer (which also covers values past 2**31 on windows, where long is 32 bits), and the time paths return Qnil once the seconds would pass the largest time_t, so they fall through to Time.parse, which raises the same way it already does for non-numeric text. ubsan flagged all four sites before the change and test/number_overflow_test.rb covers them.

@ohler55
ohler55 merged commit 7a17429 into ohler55:develop Nov 6, 2026
20 checks passed
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.

2 participants