indygreg / indygreg/python-zstandard
stream_reader() hangs (keeps spinning on CPU) when empty buffer is supplied
- Dominant language
- C
- Stars
- 642
- Forks
- 116
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 5
Description
Hi there!
We've run into an issue where bad input data caused the library to keep spinning in `decompression_reader.c:370` as seen on the screenshot from `py-spy` stacktrace dump.

Here's the code to reproduce this situation:
```
import zstandard
import io
decompressor = zstandard.ZstdDecompressor()
bad_input = b''
with decompressor.stream_reader(bad_input) as decompressing_reader:
with io.TextIOWrapper(decompressing_reader, encoding='utf-8', newline='\n') as reader:
for line in reader:
print(line)
```
Contributor guide
Research direction
Start at decompression_reader.c:370 and reproduce the hang with the Python example using an empty buffer and stream_reader(). Trace how the empty input is handled, then verify that the example terminates without spinning on CPU.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 48/100