Skip to content

Commit

Permalink
LZMA EOS marker detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Erior committed Dec 9, 2023
1 parent 67be0cd commit 0320db6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/SharpCompress/Compressors/LZMA/LzmaStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,23 @@ public override int Read(byte[] buffer, int offset, int count)

if (_availableBytes == 0 && !_uncompressedChunk)
{
_rangeDecoder.ReleaseStream();
// Check range corruption scenario
if (
!_rangeDecoder.IsFinished
|| (_rangeDecoderLimit >= 0 && _rangeDecoder._total != _rangeDecoderLimit)
)
{
throw new DataErrorException();
// Stream might have End Of Stream marker
_outWindow.SetLimit(toProcess + 1);
if (!_decoder.Code(_dictionarySize, _outWindow, _rangeDecoder))
{
_rangeDecoder.ReleaseStream();
throw new DataErrorException();
}
}

_rangeDecoder.ReleaseStream();

_inputPosition += _rangeDecoder._total;
if (_outWindow.HasPending)
{
Expand Down
3 changes: 3 additions & 0 deletions tests/SharpCompress.Test/SevenZip/SevenZipArchiveTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public void SevenZipArchive_ZSTD_Split() =>
)
);

[Fact]
public void SevenZipArchive_EOS_FileRead() => ArchiveFileRead("7Zip.eos.7z");

[Fact]
public void SevenZipArchive_Delta_FileRead() => ArchiveFileRead("7Zip.delta.7z");

Expand Down
Binary file added tests/TestArchives/Archives/7Zip.eos.7z
Binary file not shown.

0 comments on commit 0320db6

Please sign in to comment.