Route tenfn's teen branch through millfn's bounds check - #273
Open
afonsojanu wants to merge 1 commit into
Open
afonsojanu wants to merge 1 commit into
afonsojanu wants to merge 1 commit into
Conversation
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.
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 #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.