Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Molinarius opened this issue Feb 11, 2022 · 0 comments

Comments

@Molinarius
Copy link

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.

adamhathcock added a commit to Erior/sharpcompress that referenced this issue Jun 22, 2022
adamhathcock added a commit that referenced this issue Jun 22, 2022
ReadOnlySubStream overrides and adds logic #636
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants