Fix Arraypool rent without try/finally block#129158
Open
alinpahontu2912 wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens System.Formats.Tar against ArrayPool<byte> buffer leaks by ensuring all rented arrays are returned via try/finally, even when an exception occurs during stream I/O or header processing.
Changes:
- Wrap
ArrayPool<byte>.Shared.Rent(...)usages intry/finallyin writer paths so buffers are always returned. - Wrap
ArrayPool<byte>.Shared.Rent(...)usages intry/finallyin reader paths and stream-advancing/copy helpers to prevent leaks on read failures. - Ensure temporary pooled buffers used for padding / metadata generation are returned on all exit paths.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarWriter.cs | Ensures pooled buffers used during async entry writes and final record writes are always returned. |
| src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHelpers.cs | Ensures pooled buffers in stream advance/copy helpers are always returned, even on read/write failures. |
| src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Write.cs | Ensures pooled buffers for async padding writes and extended-attribute stream generation are always returned. |
| src/libraries/System.Formats.Tar/src/System/Formats/Tar/TarHeader.Read.cs | Ensures pooled buffers used while reading headers and metadata blocks are always returned on all paths. |
Member
|
Is this needed with Unsafe code best practices in mind? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.