Skip to content

[De]CompressionStream - Only return non-null buffers to pool - #57

Merged
oleg-st merged 1 commit into
oleg-st:masterfrom
i3arnon:oom-null
Aug 24, 2025
Merged

oleg-st merged 1 commit into
oleg-st:masterfrom
i3arnon:oom-null

Conversation

@i3arnon

@i3arnon i3arnon commented Aug 24, 2025

Copy link
Copy Markdown
Contributor

This PR only returns the outputBuffer and inputBuffer in CompressionStream and DecompressionStream respectively when they are not null.

They are null in an edge case where the ArrayPool<byte>.Shared.Rent(..) call in the constructor throws an exception. Specifically when it throws an OutOfMemoryException.
This exception can be caught and handled (unlike other OOMs), however the process will crash due to the implementation of CompressionStream and DecompressionStream.

The instance was not disposed (since the constructor threw an exception).
Hence, the finalizer thread will try to call the destructors that call Dispose(false) and eventually reach ArrayPool<byte>.Shared.Return(..).
This call will throw with an ArgumentNullException which will crash the process (as unhandled exceptions from the finalizer thread do).

Although caught OOMs are an edge case, there's no reason this library should then cause a crash.

@oleg-st
oleg-st merged commit 8684377 into oleg-st:master Aug 24, 2025
@oleg-st

oleg-st commented Aug 24, 2025

Copy link
Copy Markdown
Owner

Thanks

@i3arnon
i3arnon deleted the oom-null branch August 24, 2025 17:58
@Agagamand Agagamand mentioned this pull request Oct 5, 2026
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.

2 participants