Skip to content

ZipArchiveEntry.Open expectedly throws an ArgumentOutOfRangeException #127834

@rjacobw

Description

@rjacobw

Describe the bug

ZipArchiveEntry.cs incorrectly assumes that constructing a MemoryStream with a negative length is "okay" (see ZipArchiveEntry.GetCompressedData) The reality is that the MemoryStream constructor now throws an ArgumentOutOfRangeException (here) when an unchecked cast causes an uint to wrap around.

This appears to be new to netcore (versus netframework), and does cause unexpected failures where none had previously existed.

To Reproduce

Call ZipArchiveEntry.Open on a very large entry (> int.MaxValue).

Exceptions (if any)

ArgumentOutOfRangeException is thrown from the MemoryStream constructor.

Further technical details

This is no longer true -

<ZipArchiveEntry.cs>

// if _uncompressedSize > int.MaxValue, it's still okay, because MemoryStream will just
// grow as data is copied into it
_storedUncompressedData = new MemoryStream((int)_uncompressedSize);
<MemoryStream.cs>

public MemoryStream(int capacity)
{
    ArgumentOutOfRangeException.ThrowIfNegative(capacity);
    ArgumentOutOfRangeException.ThrowIfGreaterThan(capacity, MemStreamMaxLength);

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions