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

Don't call self.inner.read() with empty buffer #4

Merged
merged 1 commit into from
Mar 16, 2018

Conversation

mdsteele
Copy link
Contributor

Alas, I have just learned the hard way that some Read implementations (in this case, flate2::read::GzEncoder) don't behave nicely when read() is called with an empty buffer (you'd think they'd just return Ok(0), but GzEncoder gets confused). However, the Read implementation for newc::Reader calls self.inner.read() with a buffer limited in length to the size of the remaining data, which could be zero even if the original buffer was nonempty. (And so I had a bug where copying data from an entry in a gzipped cpio archive would fail.)

This PR adds the simple workaround of not bothering to call self.inner.read() if limit is zero. I think this is probably slightly better anyway, even for better-behaved inner readers, since self.inner.read() could potentially involve a syscall or some other relatively expensive operation, and there's no reason to do that if we already know we won't be returning any data.

@jcreekmore jcreekmore merged commit 2655db2 into jcreekmore:master Mar 16, 2018
@mdsteele mdsteele deleted the empty branch March 17, 2018 16:00
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.

2 participants