Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream_reader() hangs (keeps spinning on CPU) when empty buffer is supplied #194

Open
piotrdomagalski opened this issue Apr 27, 2023 · 3 comments
Labels

Comments

@piotrdomagalski
Copy link

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.

Screenshot 2023-04-27 at 09 37 32

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)
@indygreg indygreg added the bug label May 22, 2023
@indygreg
Copy link
Owner

Confirmed. Only reproduces in C backend. Not Rust nor FFI.

Thanks for the report.

@indygreg
Copy link
Owner

The bug here is that the C backend implementation of ZstdDecompressionReader.read1() will infinite loop for inputs conforming to the buffer protocol having 0 length. This appeared to evade test coverage (including fuzzing) because we never sent an empty input into the fuzz tests. I'll change that as part of fixing this.

@indygreg
Copy link
Owner

And adding fuzzing test coverage with empty inputs reveals that other methods also choke. e.g. readinto1() is also buggy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants