-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
binascii.a2b_uu() reads past the end of empty buffer #148093
Copy link
Copy link
Open
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
When pass an empty buffer to binascii.a2b_uu(), it reads a byte past the end of the empty buffer and returns the bytes object of the length encoded in that byte. For example:
>>> import binascii
>>> binascii.a2b_uu(memoryview(b'#86)C')[:0])
b'\x00\x00\x00'When pass an empty bytes or bytearray object, it returns the bytes object of length 32, because they always have a null byte past the end.
>>> binascii.a2b_uu(b'')
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'In general, reading past the end of the buffer is an undefined behavior. It can cause segfault if the empty buffer refers to the end of mmaped memory.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3.13bugs and security fixesbugs and security fixes3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error