GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — marshal reports EOFError for I/O errors when reading from a FILE* · Issue #155907 · python/cpython

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

New issue
Copy link
New issue
Copy link
Closed
Closed
marshal reports EOFError for I/O errors when reading from a FILE*#155907
Copy link
Labels
3.16new features, bugs and security fixesnew features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errortype-featureA feature request or enhancementA feature request or enhancement

Description

@serhiy-storchaka
serhiy-storchaka
opened on Aug 16, 2026
Issue body actions

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

  • gh-155907: Raise OSError and KeyboardInterrupt when reading marshal data #155909
  • gh-155907: Move PyMarshal C API tests to test_capi #157417
  • gh-155907: Complete PyMarshal C API tests #157452

Activity

  1. serhiy-storchaka
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)
    3.14bugs and security fixesbugs and security fixes
    3.15bugs and security fixesbugs and security fixes
    3.16new features, bugs and security fixesnew features, bugs and security fixes
    on Aug 16, 2026
  2. serhiy-storchaka commented on Aug 29, 2026

    @serhiy-storchaka
    serhiy-storchaka
    on Aug 29, 2026
    MemberAuthor
    More actions

    The writing side has the same defect, so gh-155909 fixes it too.

    w_flush() and w_string() discard the result of fwrite(), so a failed or interrupted write to a FILE* is silently ignored:

    >>> import _testcapi, marshal
    >>> _testcapi.pymarshal_write_object_to_file(b'x' * 100000, '/dev/full', marshal.version)
    >>>

    PyMarshal_WriteObjectToFile() never converts the recorded WFERR_* code into an exception either, so an unmarshallable value is ignored as well, even though the function is documented to set the error indicator on failure. Only a lone TYPE_UNKNOWN byte reaches the file:

    >>> _testcapi.pymarshal_write_object_to_file(object(), 'f', marshal.version)
    >>> open('f', 'rb').read()
    b'\xbf'
  3. serhiy-storchaka
    added a commit that references this issue on Sep 4, 2026

    gh-155907: Fix error handling in the marshal C API (GH-155909)

    aaae15c
  4. serhiy-storchaka
    added
    type-featureA feature request or enhancementA feature request or enhancement
    topic-C-API
    and removed
    3.14bugs and security fixesbugs and security fixes
    3.15bugs and security fixesbugs and security fixes
    on Sep 4, 2026
  5. serhiy-storchaka
    closed this as completedon Sep 4, 2026
  6. clin1234
    added a commit that references this issue on Sep 12, 2026

    pythongh-155907: Fix error handling in the marshal C API (pythonGH-15…

    7ae6e67
  7. vstinner
    added 3 commits that reference this issue on Sep 13, 2026

    gh-155907: Move PyMarshal C API tests to test_capi (#157417)

    bbdf31d

    pythongh-155907: Complete PyMarshal C API tests

    54028e2

    pythongh-155907: Complete PyMarshal C API tests

    a4945b5
  8. johnslavik
    added a commit that references this issue on Sep 14, 2026

    pythongh-155907: Move PyMarshal C API tests to test_capi (python#157417)

    c262cdb
  9. vstinner
    added a commit that references this issue on Sep 14, 2026

    gh-155907: Complete PyMarshal C API tests (#157452)

    7adb4cc
  10. gpshead
    added 3 commits that reference this issue on Oct 11, 2026

    gh-159185: Document that PyMarshal_WriteObjectToFile can silently tru…

    b3714a5

    [3.15] gh-159185: Document that PyMarshal_WriteObjectToFile can silen…

    9ad8605

    [3.14] gh-159185: Document that PyMarshal_WriteObjectToFile can silen…

    f8a48fb
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 fixesnew features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-C-APItype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errortype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402520 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.