gettext.GNUTranslations raises struct.error instead of OSError on a malformed .mo file
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
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
- gh-153606
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at gettext.GNUTranslations and reproduce the truncated and out-of-range .mo cases described with io.BytesIO. The work is done when malformed input raises OSError consistently instead of leaking struct.error, with regression coverage for the reported cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- localization
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100