Skip to content

gh-155907: Raise OSError and KeyboardInterrupt when reading marshal data - #155909

Open
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:marshal-read-errors
Open

gh-155907: Raise OSError and KeyboardInterrupt when reading marshal data#155909
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:marshal-read-errors

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Aug 16, 2026

Copy link
Copy Markdown
Member

r_string(), r_byte() and PyMarshal_ReadLastObjectFromFile() did not check ferror() nor call PyErr_CheckSignals(), so a genuine I/O error or a read interrupted by Ctrl-C was reported as EOFError, as if the file had simply ended.

>>> import _testcapi, os
>>> os.mkdir('d')
>>> _testcapi.pymarshal_read_object_from_file('d')
EOFError: EOF read where object expected      # before
IsADirectoryError: [Errno 21] Is a directory  # after

The documentation of these functions listed only EOFError, ValueError and TypeError, which was inaccurate even before this change (MemoryError is raised when the read buffer cannot be allocated), so the lists are removed.

…shal data

Reading marshalled data from a FILE* did not check ferror() nor signals,
so an I/O error or a Ctrl-C was reported as EOFError.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34091564 | 📁 Comparing 2c5579a against main (7a845ce)

  🔍 Preview build  

2 files changed
± c-api/marshal.html
± whatsnew/changelog.html

@serhiy-storchaka

Copy link
Copy Markdown
Member Author

Failure on Windows is expected -- this is a bug #155905.

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

Labels

awaiting core review needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant