Skip to content

gh-148093: Raise binascii.Error from binascii.a2b_uu on empty input#149077

Open
maurycy wants to merge 6 commits intopython:mainfrom
maurycy:a2buu-err
Open

gh-148093: Raise binascii.Error from binascii.a2b_uu on empty input#149077
maurycy wants to merge 6 commits intopython:mainfrom
maurycy:a2buu-err

Conversation

@maurycy
Copy link
Copy Markdown
Contributor

@maurycy maurycy commented Apr 27, 2026

Right now, binascii.a2b_uu with empty data reads one byte past the end of the input buffer. Per the discussion, it should raise binascii.Error.

Resolves #148093

@maurycy
Copy link
Copy Markdown
Contributor Author

maurycy commented Apr 27, 2026

cc @serhiy-storchaka

Comment thread Lib/test/test_binascii.py
self.assertRaises(binascii.Error, binascii.a2b_uu, b"!!!!")
self.assertRaises(binascii.Error, binascii.a2b_uu,
self.type2test(b""))
self.assertRaises(binascii.Error, binascii.a2b_uu,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need this second test case? The [:0] makes it an empty sequence?

Copy link
Copy Markdown
Contributor Author

@maurycy maurycy Apr 27, 2026

Choose a reason for hiding this comment

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

@sethmlarson

class MemoryviewBinASCIITest(BinASCIITest):
type2test = memoryview

memoryview(b"#86)C")[:0] is the actual UB case here: zero slice with larger underlying buffer

@serhiy-storchaka came up with it:

#148093 (comment)

Truth to be told, this BinASCIITest inheritance is very confusing and make lots of tests without self.type2test redundant but I didn't want to overhaul it. Do you want me to create a separate issue documenting problems with BinASCIITest?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

binascii.a2b_uu() reads past the end of empty buffer

2 participants