Skip to content

Route tenfn's teen branch through millfn's bounds check - #273

Open
afonsojanu wants to merge 1 commit into
jaraco:mainfrom
afonsojanu:fix/tenfn-out-of-range-indexerror
Open

afonsojanu wants to merge 1 commit into
jaraco:mainfrom
afonsojanu:fix/tenfn-out-of-range-indexerror

Conversation

@afonsojanu

Copy link
Copy Markdown

Fixes #242.

number_to_words is documented to raise NumOutOfRangeError once the magnitude goes past the supported mill table, and millfn already enforces that bound. tenfn's regular branch calls millfn correctly, but its teen branch (tens == 1) indexed mill directly instead, so a magnitude past decillion leaked a bare IndexError there rather than the documented exception. Anyone following the documented contract and catching NumOutOfRangeError around number_to_words would still crash on inputs above roughly 10^36.

Fixed by swapping the direct index for the same millfn call the other branch already uses, so both paths share one bounds check.

Added a test directly on tenfn plus a couple of number_to_words cases straight from the issue's own repro (1036, 1040, 10**100). Confirmed all three fail with the old IndexError before this change and pass with it. Full suite: 211 passed, 16 pre-existing xfail, nothing else touched.

number_to_words is documented to raise NumOutOfRangeError once the
magnitude goes past the mill table, and millfn already enforces that.
tenfn's non-teen branch calls millfn correctly, but the teen branch
(tens == 1) indexed mill directly instead, so a magnitude of 12 or
higher leaked a bare IndexError there rather than the documented
exception. Anyone catching NumOutOfRangeError around number_to_words
would still crash on inputs above roughly 10^36.

Fixed by swapping the direct index for the same millfn call the other
branch already uses. Added a direct test on tenfn plus a couple of
number_to_words cases from the issue's own repro (10**36, 10**40,
10**100), confirmed both fail on the old code and pass now.

Fixes jaraco#242.
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.

number_to_words leaks IndexError instead of NumOutOfRangeError for huge inputs

1 participant