Skip to content

Reject non-bytes reader results in copy_stream - #379

Open
omrzk wants to merge 1 commit into
indygreg:mainfrom
omrzk:fix/copy-stream-read-types-375
Open

omrzk wants to merge 1 commit into
indygreg:mainfrom
omrzk:fix/copy-stream-read-types-375

Conversation

@omrzk

@omrzk omrzk commented Nov 8, 2026

Copy link
Copy Markdown

Passing a text stream to the C backend’s copy_stream() can crash the interpreter. Both compressor and decompressor ignore a failed PyBytes_AsStringAndSize() call and continue with invalid read-buffer state.

Return through the existing cleanup path when conversion fails, preserving TypeError. Tests use StringIO, invalid EOF/read values, and a type error after a valid chunk; they also reuse the same context for a successful stream afterward.

Validation on Python 3.14: warnings-as-errors C build; C suite 254 passed / 44 skipped / six subtests passed; CFFI suite 228 passed / 70 skipped. Before the fix, four isolated cases crashed with SIGSEGV and one reported a wrong decompression error; all ten regression/control subprocesses pass afterward. Ruff lint and changed-file format checks pass. Whole-repository format check finds an unchanged setup.py indentation difference; slow/fuzz CI profile, Rust, other Python versions and non-Linux platforms were not run.

Fixes #375.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ZstdDecompressor.copy_stream() crashes when the source's read() returns str

1 participant