google / wuffs

Wrangling Untrusted File Formats Safely
Other
4.16k stars 131 forks source link

example/zcat loops forever on short input files #96

Closed magical closed 1 year ago

magical commented 1 year ago

Trivial reproducer:

gen/bin/example-zcat </dev/null

Any valid prefix of a gzip file works too, e.g.

echo '1F 8B 08' | xxd -ps -r | strace gen/bin/example-zcat

The problem seems to be the I/O loop in zcat.c. It's happy to retry short reads as long as the decoder produces them, by reading more bytes from the input stream. When it detects EOF, it'll set src.meta.closed = true but then it never does anything based on that field and wuffs doesn't seem to care about it either. So it just loops forever, reading 0 bytes and hoping that, this time, the decoder will make progress.

(Tbh i'm not sure why it doesn't just bail out immediately on EOF. I guess to flush any unwritten state? But that seems like it's covered by the inner write loop. I'm not sure i completely understand the expected contract here.)

I haven't tried any of the other example programs, but it looks like bzcat (at least) likely has the same problem.

nigeltao commented 1 year ago

The fix is part of v0.3.1.

Thanks for the bug report.