[PR #1142] [MERGED] Fix ReadFullyAsync with ArrayPool buffer in SevenZipArchive signature check #1580

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

📋 Pull Request Information

Original PR: https://github.com/adamhathcock/sharpcompress/pull/1142
Author: @Copilot
Created: 1/16/2026
Status: Merged
Merged: 1/16/2026
Merged by: @adamhathcock

Base: adam/async-creationHead: copilot/sub-pr-1132-another-one


📝 Commits (2)

  • 4b9b20d Initial plan
  • b0fde2b Fix ReadFullyAsync call to specify offset and count for ArrayPool buffer

📊 Changes

1 file changed (+1 additions, -1 deletions)

View changed files

📝 src/SharpCompress/Archives/SevenZip/SevenZipArchive.Factory.cs (+1 -1)

📄 Description

ArrayPool.Rent(6) may return buffers larger than 6 bytes, but ReadFullyAsync(buffer, cancellationToken) attempts to fill the entire buffer, causing reads beyond the intended 6-byte signature.

Changes

  • Changed ReadFullyAsync(buffer, cancellationToken) to ReadFullyAsync(buffer, 0, 6, cancellationToken) in SignatureMatchAsync
  • Now consistent with synchronous SignatureMatch which correctly uses ReadExact(buffer, 0, 6)
// Before: reads buffer.Length bytes (could be > 6)
if (!await stream.ReadFullyAsync(buffer, cancellationToken).ConfigureAwait(false))

// After: reads exactly 6 bytes
if (!await stream.ReadFullyAsync(buffer, 0, 6, cancellationToken).ConfigureAwait(false))

💡 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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/adamhathcock/sharpcompress/pull/1142 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 1/16/2026 **Status:** ✅ Merged **Merged:** 1/16/2026 **Merged by:** [@adamhathcock](https://github.com/adamhathcock) **Base:** `adam/async-creation` ← **Head:** `copilot/sub-pr-1132-another-one` --- ### 📝 Commits (2) - [`4b9b20d`](https://github.com/adamhathcock/sharpcompress/commit/4b9b20de42507eec517ea437a1d68dfba4fe5d27) Initial plan - [`b0fde2b`](https://github.com/adamhathcock/sharpcompress/commit/b0fde2b8c73751943984b769094de5d2675b0765) Fix ReadFullyAsync call to specify offset and count for ArrayPool buffer ### 📊 Changes **1 file changed** (+1 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/SharpCompress/Archives/SevenZip/SevenZipArchive.Factory.cs` (+1 -1) </details> ### 📄 Description `ArrayPool.Rent(6)` may return buffers larger than 6 bytes, but `ReadFullyAsync(buffer, cancellationToken)` attempts to fill the entire buffer, causing reads beyond the intended 6-byte signature. ## Changes - Changed `ReadFullyAsync(buffer, cancellationToken)` to `ReadFullyAsync(buffer, 0, 6, cancellationToken)` in `SignatureMatchAsync` - Now consistent with synchronous `SignatureMatch` which correctly uses `ReadExact(buffer, 0, 6)` ```csharp // Before: reads buffer.Length bytes (could be > 6) if (!await stream.ReadFullyAsync(buffer, cancellationToken).ConfigureAwait(false)) // After: reads exactly 6 bytes if (!await stream.ReadFullyAsync(buffer, 0, 6, cancellationToken).ConfigureAwait(false)) ``` <!-- START COPILOT CODING AGENT TIPS --> --- 💡 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](https://gh.io/copilot-coding-agent-tips) in the docs. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 22:21:13 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#1580