Index: src/OFInflateStream.m ================================================================== --- src/OFInflateStream.m +++ src/OFInflateStream.m @@ -671,11 +671,12 @@ return [_stream fileDescriptorForReading]; } - (bool)hasDataInReadBuffer { - return ([super hasDataInReadBuffer] || [_stream hasDataInReadBuffer]); + return ([super hasDataInReadBuffer] || [_stream hasDataInReadBuffer] || + _bufferLength - _bufferIndex > 0); } - (void)close { /* Give back our buffer to the stream, in case it's shared */ Index: src/OFLHAArchive.m ================================================================== --- src/OFLHAArchive.m +++ src/OFLHAArchive.m @@ -701,11 +701,12 @@ return [_stream fileDescriptorForReading]; } - (bool)hasDataInReadBuffer { - return ([super hasDataInReadBuffer] || [_stream hasDataInReadBuffer]); + return ([super hasDataInReadBuffer] || [_stream hasDataInReadBuffer] || + _bufferLength - _bufferIndex > 0); } - (void)close { /* Give back our buffer to the stream, in case it's shared */ @@ -791,10 +792,14 @@ @throw [OFNotOpenException exceptionWithObject: self]; if (_atEndOfStream) return 0; + if ([_stream isAtEndOfStream] && + ![_decompressedStream hasDataInReadBuffer]) + @throw [OFTruncatedDataException exception]; + if (length > _toRead) length = _toRead; ret = [_decompressedStream readIntoBuffer: buffer length: length]; Index: src/OFZIPArchive.m ================================================================== --- src/OFZIPArchive.m +++ src/OFZIPArchive.m @@ -795,10 +795,14 @@ @throw [OFNotOpenException exceptionWithObject: self]; if (_atEndOfStream) return 0; + if ([_stream isAtEndOfStream] && + ![_decompressedStream hasDataInReadBuffer]) + @throw [OFTruncatedDataException exception]; + #if SIZE_MAX >= UINT64_MAX if (length > UINT64_MAX) @throw [OFOutOfRangeException exception]; #endif