mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-03 21:23:38 +00:00
[PR #1104] Fix InvalidOperationException when RAR uncompressed size exceeds header value #1539
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Original Pull Request: https://github.com/adamhathcock/sharpcompress/pull/1104
State: closed
Merged: Yes
Changes Made
Core Fix:
RarStream.Read()andRarStream.ReadImplAsync()from_position != Lengthto_position < LengthTest Coverage:
Rar_StreamValidation_OnlyThrowsOnPrematureEnd): Validates normal extraction succeeds across RAR, RAR5, RAR4, and RAR2 formats without throwing when position >= expected lengthRar_StreamValidation_ThrowsOnTruncatedStream): VerifiesInvalidOperationExceptionIS thrown when a RAR stream ends prematurely (position < expected length)TruncatedStream): Created to simulate corrupted/truncated RAR files for negative testingThis allows successful extraction of RAR archives where headers underestimate the uncompressed size, while still catching truncated/corrupted extractions.
<issue_title>InvalidOperationException when extracting RAR - 0.42.0, 0.42.1, 0.43.0</issue_title>
><issue_description>Extracting RAR files now raise InvalidOperationException
>
> Message:
> System.InvalidOperationException : unpacked file size does not match header: expected 22369776 found 31148016
>
> Stack Trace:
> RarStream.ReadImplAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancellationToken)
> RarStream.ReadAsync(Memory`1 buffer, CancellationToken cancellationToken)
> Stream.</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
>
><comment_new>@adamhathcock
> I assume this worked with versions earlier than 0.42.0?
>
> What OS and can you give me a sample file?</comment_new>
>
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.