-
Notifications
You must be signed in to change notification settings - Fork 18
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
Poor handling of truncated streams #27
Comments
The caller can detect truncated streams if it knows how many bytes it expects (gzip, PNG, etc.). |
There is a flag in the deflate block header that tells if it's the last block, so if the stream ends without hitting and ending a block with that flag, it's likely truncated. This should be pretty easy to check for. |
Ahh, so there's both an end of block marker and that bit. Yeah then we could have a method, e.g. |
Ah, I wasn't aware that callers generally knew how many bytes to expect. In that case, this probably doesn't matter much. I just noticed it because of the test to check for missing CRC. An Should Similarly, should |
Currently
InflateStream::update
nearly always returnsOk
for truncated streams, and this flows through to the higher level APIs. There should be some way to determine that more data is still expected, but I don't see how the current API allows for this. The documentation says to callInflateStream::update
until it returns 0 bytes, but none of the current callers do this, and I don't see how it can work. In general, the last call that passes some input data toInflateStream::update
will make progress, and then there is no further input data to pass, so the caller will never get 0 bytes returned.The one exception that I can see was introduced in #24, and that only occurs if there are less than 4 bytes currently available when in state
CheckCRC
. Actually, this check is wrong, because the CRC may be split over twoupdate
calls.The text was updated successfully, but these errors were encountered: