Skip to content

Fix binascii.a2b_uu empty input - #8389

Merged
youknowone merged 1 commit into
RustPython:mainfrom
doma17:fix-binascii-a2b-uu-empty-input
Jul 27, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
doma17:fix-binascii-a2b-uu-empty-input

Conversation

@doma17

@doma17 doma17 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Make binascii.a2b_uu(b\"\") raise binascii.Error, matching CPython.

Previously, empty input was treated as a UU length byte and returned 32 NUL
bytes. It is now rejected before decoding with binascii.Error: Missing length byte.

Testing

  • cargo run --release -- -m test test_binascii
  • prek run --all-files
  • cargo fmt --check
  • cargo clippy -p rustpython-stdlib -- -D warnings
  • cargo test -p rustpython-stdlib
  • Manual workspace test verification

Summary by CodeRabbit

  • Bug Fixes
    • Improved UU-encoded data handling when the input is empty.
    • Empty input now returns a clear “Missing length byte” error instead of being processed incorrectly.
    • Valid inputs continue to be decoded as expected.

Constraint: Match CPython's a2b_uu empty-input behavior.
Confidence: high
Scope-risk: narrow
Directive: Preserve decoding behavior for non-empty UU buffers.
Tested: prek run --all-files; test_binascii; cargo fmt --check; cargo clippy -p rustpython-stdlib -- -D warnings; cargo test -p rustpython-stdlib; manual full-suite verification
Assisted-by: Codex:gpt-5.6-sol
Copilot AI review requested due to automatic review settings July 27, 2026 06:49
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro Plus

Run ID: eaa6dc18-fab7-461e-8048-b36237e96cd0

📥 Commits

Reviewing files that changed from the base of the PR and between 5db61a0 and 53577b4.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_binascii.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • crates/stdlib/src/binascii.rs

📝 Walkthrough

Walkthrough

a2b_uu now raises a binascii error for empty input instead of treating it as a zero-length byte and returning padded data.

Changes

UU decoding validation

Layer / File(s) Summary
Reject empty UU input
crates/stdlib/src/binascii.rs
a2b_uu returns "Missing length byte" for empty input and uses the first byte for length calculation otherwise.

Estimated code review effort: 2 (Simple) | ~5 minutes

Suggested reviewers: copilot, shaharnaveh, yangsijun528

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: fixing empty-input handling in binascii.a2b_uu().
Linked Issues check ✅ Passed The change makes a2b_uu(b"") reject empty input with Missing length byte, matching the linked issue.
Out of Scope Changes check ✅ Passed The summary shows a narrowly scoped fix in one function with no unrelated code changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[x] test: cpython/Lib/test/test_binascii.py (TODO: 2)

dependencies:

dependent tests: (95 tests)

  • binascii: test_base64 test_binascii test_codecs test_ctypes test_descr test_hashlib test_hmac test_plistlib test_struct test_zlib
    • base64: test_email test_gettext test_httpservers test_smtplib test_urllib2 test_urllib2_localnet test_xmlrpc test_zoneinfo
      • http.server: test_logging test_robotparser
      • logging.handlers: test_concurrent_futures test_pkgutil
      • secrets: test_secrets
      • smtplib: test_smtpnet
      • ssl: test_asyncio test_ftplib test_httplib test_imaplib test_poplib test_ssl test_urllib test_venv
      • urllib.request: test_http_cookiejar test_pathlib test_pydoc test_sax test_site test_urllib2net test_urllibnet
    • email: test_email test_mailbox test_zipfile
      • importlib.metadata: test_importlib
      • mailbox: test_genericalias
      • pydoc: test_enum
    • http.server:
      • wsgiref.simple_server: test_wsgiref
    • plistlib:
      • platform: test__locale test__osx_support test_asyncio test_baseexception test_builtin test_cmath test_ctypes test_fcntl test_math test_mimetypes test_os test_platform test_posix test_regrtest test_shutil test_socket test_strptime test_sysconfig test_time test_winreg
    • quopri: test_quopri
    • zipfile: test_pdb test_zipapp test_zipfile test_zipfile64 test_zipimport test_zipimport_support
      • shutil: test_argparse test_bz2 test_compileall test_ctypes test_embed test_filecmp test_glob test_importlib test_inspect test_largefile test_launcher test_modulefinder test_peg_generator test_py_compile test_reprlib test_string_literals test_subprocess test_support test_tarfile test_tempfile test_traceback test_unicode_file

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR aligns RustPython’s binascii.a2b_uu() behavior with CPython by rejecting empty input and raising binascii.Error("Missing length byte"), instead of decoding an empty buffer as a UU length byte.

Changes:

  • Added an explicit empty-input guard in binascii.a2b_uu() that raises binascii.Error: Missing length byte.
  • Removed @unittest.expectedFailure decorators for test_uu and test_empty_string now that the behavior matches CPython.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
crates/stdlib/src/binascii.rs Adds the empty-input check to make a2b_uu(b"") raise binascii.Error with the CPython message.
Lib/test/test_binascii.py Enables upstream tests by removing expected-failure markers related to a2b_uu empty-input handling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@youknowone youknowone 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.

👍

@youknowone
youknowone merged commit 59e903d into RustPython:main Jul 27, 2026
26 of 27 checks passed
@doma17
doma17 deleted the fix-binascii-a2b-uu-empty-input branch July 27, 2026 14:24
youknowone pushed a commit to youknowone/RustPython that referenced this pull request Jul 29, 2026
Constraint: Match CPython's a2b_uu empty-input behavior.
Confidence: high
Scope-risk: narrow
Directive: Preserve decoding behavior for non-empty UU buffers.
Tested: prek run --all-files; test_binascii; cargo fmt --check; cargo clippy -p rustpython-stdlib -- -D warnings; cargo test -p rustpython-stdlib; manual full-suite verification
Assisted-by: Codex:gpt-5.6-sol
youknowone pushed a commit that referenced this pull request Sep 16, 2026
Constraint: Match CPython's a2b_uu empty-input behavior.
Confidence: high
Scope-risk: narrow
Directive: Preserve decoding behavior for non-empty UU buffers.
Tested: prek run --all-files; test_binascii; cargo fmt --check; cargo clippy -p rustpython-stdlib -- -D warnings; cargo test -p rustpython-stdlib; manual full-suite verification
Assisted-by: Codex:gpt-5.6-sol
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.

binascii.a2b_uu() returns data for empty input

3 participants