Status: New
Owner: [email protected]
Labels: Type-Defect Priority-Medium
New issue 328 by [email protected]: C++ GzipInputStream does not BackUp
unused bytes of the underlying stream
http://code.google.com/p/protobuf/issues/detail?id=328
Steps to reproduce the problem:
1. Write "test\ntest\nend\n" with GzipOutputStream to a file
2. continue writing uncompressed data to the file
3. Open file with FileInputStream
4. Wrap FileInputStream with GzipInputStream, read until "end\n"
5. Close GzipInputStream
6. Observe that subsequent reads on the FileInputStream fail from EOF,
instead of returning the uncompressed data.
Version: SVN revision 405
Additional complications arise for small buffer sizes: The zlib footer is
not necessarily read when all bytes are extracted from the GzipInputStream,
so after deletion the zlib footer will be the next thing read from the
underlying stream.
Attached is a patch to the unit tests that demonstrates the problem.
(comment out gzin->ExpectAtEnd()) for trying it without the patch below)
Proposed solution: Add a "bool ExpectAtEnd()" to GzipInputStream, that
returns true if and only if repeated calls to Next would not return any
more data, and zlib returns STREAM_END at some point. If more data is read,
the stream is Backed up to the previous position and false is returned.
On deletion, the GzipInputStream should check ExpectAtEnd(), and if true,
back up the input stream by the number of unused bytes in the zlib input
buffer.
The attached patch provides this, and should solve the issue.
Cheers,
Johannes Ebke
Attachments:
gzipinput_test.patch 3.1 KB
gzipinput_fix.patch 1.8 KB
--
You received this message because you are subscribed to the Google Groups "Protocol
Buffers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/protobuf?hl=en.