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

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.16new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-bugAn unexpected behavior, bug, or errortype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions