Skip to content

Fix synchronous reads called in async RAR unpacker paths#1305

Closed
Copilot wants to merge 2 commits into
masterfrom
copilot/fix-sync-methods-in-async-api
Closed

Fix synchronous reads called in async RAR unpacker paths#1305
Copilot wants to merge 2 commits into
masterfrom
copilot/fix-sync-methods-in-async-api

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 28, 2026

Async RAR extraction fails with NotSupportedException when the underlying stream is async-only (e.g., MultiVolumeReadOnlyAsyncStream), because Unpack29Async and Unpack5Async were calling sync methods that internally invoke readStream.Read(...).

Changes

  • Unpack.Async.cs — Added async counterparts for three sync methods used in Unpack29Async:

    • ReadTablesAsync() — mirrors ReadTables(), replacing unpReadBuf() calls with await unpReadBufAsync(). Uses heap-allocated arrays instead of stackalloc (not permitted in async methods).
    • ReadEndOfBlockAsync() — mirrors ReadEndOfBlock(), delegates to ReadTablesAsync().
    • ReadVMCodeAsync() — mirrors ReadVMCode(), replacing unpReadBuf() with await unpReadBufAsync().
    • Updated Unpack29Async to call all three async variants.
  • Unpack50.Async.cs — Updated Unpack5Async to call await ReadTablesAsync() instead of ReadTables() at both call sites.

Example (the failing path)

// Previously threw: NotSupportedException: Synchronous read is not supported in MultiVolumeReadOnlyAsyncStream
//   at Unpack.unpReadBuf()
//   at Unpack.ReadTables()        ← sync, called from async context
//   at Unpack.Unpack29Async(...)
await reader.WriteEntryToDirectoryAsync(outputPath);

…npack5Async)

Agent-Logs-Url: https://github.com/adamhathcock/sharpcompress/sessions/7f2fcb59-4a41-4b27-ab32-17afec510b5e

Co-authored-by: adamhathcock <527620+adamhathcock@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix sync methods used in Async APIs Fix synchronous reads called in async RAR unpacker paths Apr 28, 2026
Copilot AI requested a review from adamhathcock April 28, 2026 06:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Sync methods are used in Async API’s

2 participants