Skip to content

Quote unprintable values through _message_text in three integer refusals (closes #2863) - #2865

Merged
fametrano merged 2 commits into
btclib-org:mainfrom
nosmile99:fix/2863-unprintable-integer-refusals
Oct 30, 2026
Merged

fametrano merged 2 commits into
btclib-org:mainfrom
nosmile99:fix/2863-unprintable-integer-refusals

Conversation

@nosmile99

Copy link
Copy Markdown
Contributor

Closes #2863

Three integer refusals built their message with a plain f-string interpolation of the refused value, so a Fraction whose numerator runs past Python's 4300-digit str() limit left as a builtin ValueError instead of the library's BTClibTypeError. The three sites now quote through utils._message_text, which describes a value str() cannot write instead of quoting it:

  • var_int.parse's max_size refusal
  • var_int.serialize's refusal
  • obfuscation.obfuscate's offset refusal

Verification: reproduced all three as builtin ValueError on main, then confirmed BTClibTypeError after the fix. Two new regression tests pass Fraction(10**4400, 3) to each entry point and expect BTClibTypeError; both fail on the unfixed code (stashed-src comparison) and pass with the fix. The var_int, obfuscation, and integer-policy suites pass together, and ruff check plus ruff format are clean on the changed files.

Out of scope, noted for the maintainer: the negative-offset refusal in obfuscation quotes its value directly too, so a negative int past the digit limit would leave the same way (as a builtin ValueError instead of BTClibValueError). Left untouched since the issue scopes to the three integer refusals.

…als (closes btclib-org#2863)

Signed-off-by: nosmile99 <nosmile99@users.noreply.github.com>
@fametrano

Copy link
Copy Markdown
Member

Thanks, @nosmile99. I approved the eight workflow runs waiting on c531ac5 after reading the diff, which touches nothing under .github/. A review follows once they report.

@nosmile99

Copy link
Copy Markdown
Contributor Author

Lint fix pushed (cfba123): the lint failure was mypy strict on the three new regression tests — they intentionally pass a Fraction where int is typed, to exercise the refusal path. Added the repo-standard # type: ignore[arg-type] to those three call sites (same pattern as the other intentional wrong-type args in tests/).

Verified locally in the project env: mypy clean on both test files, tests/var_int_test.py + tests/obfuscation_test.py 50 passed, ruff check and ruff format --check clean on the changed files.

@fametrano fametrano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @nosmile99. One thing holds this pull request: the second commit, cfba123, has no Signed-off-by: line.

The fix is right and meets ISS #2863's Done when. On main, var_int.serialize, var_int.parse(max_size=) and obfuscation.obfuscate(offset=) each raise a builtin ValueError ("Exceeds the limit (4300 digits)") for Fraction(10**4400, 3). With your change each raises BTClibTypeError with a Fraction str() cannot write. Both new tests fail on main and pass on your head, the # type: ignore[arg-type] follows the tree's precedent (tests/amount_test.py), and no other refusal in scope quotes an unprintable value.

main requires a Signed-off-by: trailer on every commit, added by its author: it is your attestation, so we cannot add it for you. cfba123 was committed as nosmile0110@gmail.com, so the trailer must name that address. It is the tip, so this is enough, followed by a force-push:

git -c user.email=nosmile0110@gmail.com commit --amend --no-edit -s

The suggestions below are optional. They make the tests match the whole description the fix writes, as tests/amount_test.py does (a Fraction str\(\) cannot write$), not only the message's prefix. Apply them with the sign-off, or leave them.

Comment thread tests/var_int_test.py Resolved
Comment thread tests/obfuscation_test.py Resolved
Comment thread tests/obfuscation_test.py Resolved
The new tests intentionally pass a Fraction where int is typed, to
exercise the refusal path; mark the three call sites with the
repo-standard type: ignore[arg-type] so strict mypy passes.

Signed-off-by: nosmile99 <nosmile0110@gmail.com>
@nosmile99
nosmile99 force-pushed the fix/2863-unprintable-integer-refusals branch from cfba123 to 06af90f Compare October 30, 2026 12:01
@nosmile99

Copy link
Copy Markdown
Contributor Author

Thanks, @fametrano — both items are in, force-pushed as 06af90fd:

  • Tip commit now carries Signed-off-by: nosmile99 <nosmile0110@gmail.com> (amended, no other change to that commit).
  • All three optional suggestions applied: the var_int and offset regression tests now match the whole description (a Fraction str\(\) cannot write$), and the offset test docstring says what it checks. Both updated tests pass locally (2 passed).

@fametrano fametrano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @nosmile99. Approved at 06af90f.

The three refusals #2863 names now quote through _message_text. Each new test fails on the old code with the builtin ValueError: Exceeds the limit (4300 digits), and the max_size assertion catches a regression of that line on its own. Both commits are signed off, mypy is clean on the four touched files, and every check passed on this head.

Your second commit's message names only the type: ignore lines, so the squash body says what that commit also changed.

@fametrano
fametrano merged commit 686f625 into btclib-org:main Oct 30, 2026
26 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.

Three integer refusals raise ValueError for a Fraction too large to print

2 participants