Bug report
Bug description:
gettext.GNUTranslations parses a .mo file by unpacking its header and seek
tables with struct.unpack, but never checks the file is long enough. A
truncated file (shorter than the 20-byte header) or one whose seek tables point
past the end raises a raw struct.error instead of the OSError the module
already raises for other malformed input (a bad magic number, a bad version, or
an out-of-range string offset). The documentation states OSError is raised for
problems while reading the file, so the struct.error is an undocumented leak.
import gettext, io
gettext.GNUTranslations(io.BytesIO(b"\xde\x12\x04\x95")) # raises struct.error
CPython versions tested on:
3.13, 3.14, 3.15, 3.16
Operating systems tested on:
macOS
Linked PRs
Bug report
Bug description:
gettext.GNUTranslationsparses a.mofile by unpacking its header and seektables with
struct.unpack, but never checks the file is long enough. Atruncated file (shorter than the 20-byte header) or one whose seek tables point
past the end raises a raw
struct.errorinstead of theOSErrorthe modulealready raises for other malformed input (a bad magic number, a bad version, or
an out-of-range string offset). The documentation states
OSErroris raised forproblems while reading the file, so the
struct.erroris an undocumented leak.import gettext, io
gettext.GNUTranslations(io.BytesIO(b"\xde\x12\x04\x95")) # raises struct.error
CPython versions tested on:
3.13, 3.14, 3.15, 3.16
Operating systems tested on:
macOS
Linked PRs