Exception when disposing RarArchive #718

Closed
opened 2026-01-29 22:16:21 +00:00 by claunia · 0 comments
Owner

Originally created by @RawScape on GitHub (Nov 15, 2025).

Originally assigned to: @Copilot on GitHub.

I ran into an exception when disposing RarArchive after processing a damaged archive.

System.ArgumentNullException: Value cannot be null. (Parameter 'array')
   at System.Buffers.SharedArrayPool`1.Return(T[] array, Boolean clearArray)
   at SharpCompress.Compressors.Rar.UnpackV1.Unpack.Dispose() in /_/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs:line 32
   at SharpCompress.Archives.Rar.RarArchive.Dispose() in /_/SharpCompress/Archives/Rar/RarArchive.cs:line 35

I checked in SharpCompress.Compressors.Rar.UnpackV1.Unpack and found:

public override void Dispose()
{
    if (!disposed)
    {
        base.Dispose();
        if (!externalWindow)
        {
            ArrayPool<byte>.Shared.Return(window);
            window = null;
        }
        rarVM.Dispose();
        disposed = true;
    }
}

since "window" was "null" at this point I added a check fo this:

public override void Dispose()
{
    if (!disposed)
    {
        base.Dispose();
        if (!externalWindow && window is not null)
        {
            ArrayPool<byte>.Shared.Return(window);
            window = null;
        }
        rarVM.Dispose();
        disposed = true;
    }
}
Originally created by @RawScape on GitHub (Nov 15, 2025). Originally assigned to: @Copilot on GitHub. I ran into an exception when disposing RarArchive after processing a damaged archive. ``` System.ArgumentNullException: Value cannot be null. (Parameter 'array') at System.Buffers.SharedArrayPool`1.Return(T[] array, Boolean clearArray) at SharpCompress.Compressors.Rar.UnpackV1.Unpack.Dispose() in /_/SharpCompress/Compressors/Rar/UnpackV1/Unpack.cs:line 32 at SharpCompress.Archives.Rar.RarArchive.Dispose() in /_/SharpCompress/Archives/Rar/RarArchive.cs:line 35 ``` I checked in SharpCompress.Compressors.Rar.UnpackV1.Unpack and found: ``` public override void Dispose() { if (!disposed) { base.Dispose(); if (!externalWindow) { ArrayPool<byte>.Shared.Return(window); window = null; } rarVM.Dispose(); disposed = true; } } ``` since "window" was "null" at this point I added a check fo this: ``` public override void Dispose() { if (!disposed) { base.Dispose(); if (!externalWindow && window is not null) { ArrayPool<byte>.Shared.Return(window); window = null; } rarVM.Dispose(); disposed = true; } } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#718