sharpcompress icon indicating copy to clipboard operation
sharpcompress copied to clipboard

Reading from 7z entry stream using `Read(Span<byte>)` might read too many bytes

Open Molinarius opened this issue 3 years ago • 0 comments

With .NET 5 and .NET 6, I noticed that reading from an entry stream from certain 7z file reads too many bytes when the Read(Span<byte>) overload is used.

E.g.:

using (var archive = SevenZipArchive.Open("test.7z"))
{
    var entry = archive.Entries.First(entry => entry.Key == "test.txt");
    using (var stream = entry.OpenEntryStream())
    {
        byte[] buffer = new byte[1024];
        int bytesRead = stream.Read(buffer.AsSpan()); // stream.Read(buffer, 0, 1024) works
        Console.WriteLine(bytesRead);
    }
}

With the sample 7z file attached (I had to put it into a zip file test.zip to be able to upload it), this reads 18 bytes instead of the expected 12 bytes. The Read(byte[], int, int) overload works for me as expected.

Using version 0.30.1 from NuGet.

Molinarius avatar Feb 11 '22 10:02 Molinarius