Skip to content

marshal reports EOFError for I/O errors when reading from a FILE* #155907

Description

@serhiy-storchaka

Bug report

The functions which read marshalled data from a FILE* never check ferror(), so a genuine I/O error is reported as if the file had simply ended.

>>> import _testcapi, os
>>> os.mkdir('d')
>>> _testcapi.pymarshal_read_object_from_file('d')
Traceback (most recent call last):
  ...
EOFError: EOF read where object expected

The real error is EISDIR. PyMarshal_ReadLongFromFile(), PyMarshal_ReadShortFromFile() and PyMarshal_ReadLastObjectFromFile() behave the same way.

Signals are not checked either, so a read interrupted by Ctrl-C is reported as EOFError instead of raising KeyboardInterrupt.

Doc/c-api/marshal.rst also documents only EOFError, ValueError and TypeError for these functions, which is inaccurate even today -- MemoryError is raised when the read buffer cannot be allocated.

Related: gh-101006 stopped EOFError from overriding an already set exception, but nothing sets OSError in the first place.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15pre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions