Optionally allow trailing data in bufread::XzDecoder
#86
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some xz streams have unrelated data afterward. In particular, Linux kernel initrd files are the concatenation of multiple cpio archives, each of which can be compressed with a different compressor.
read::XzDecoder
andbufread::XzDecoder
returnInvalidData
in this case, which makes it difficult to detect the EOF, unwrap the underlying stream, and continue reading with a different decompressor. (write::XzDecoder
returnsOk(0)
after the end of the xz stream, which is less ambiguous.) Multi-decoder mode doesn't address this, since that only handles the case where the following data is also an xz stream.liblzma properly returns
StreamEnd
here; we just need to detect it. However, the xz test suite contains some tests with trailing garbage, and thexz
command-line tool is designed to fail on those unless--single-stream
is specified. For compatibility, we probably can't allow trailing garbage by default, but we can provide an option. Add anallow_trailing_data()
toggle tobufread::XzDecoder
, and stop accepting bytes inread()
if we reachStreamEnd
with that toggle enabled.Do not add a similar option to
read::XzDecoder
, since it's only useful if the underlying stream is synced to the end of the xz stream afterward, andread::XzDecoder
can't ensure that.Also add an additional test verifying that
write::XzDecoder
refuses to accept additional bytes after the xz stream reachesStreamEnd
.