Skip to content

[V3] Dispose PNG chunk buffers when a chunk read throws - #3282

Merged
JimBobSquarePants merged 3 commits into
release/3.2.xfrom
js/png-chunk-dispose-3.2
Nov 23, 2026
Merged

JimBobSquarePants merged 3 commits into
release/3.2.xfrom
js/png-chunk-dispose-3.2

Conversation

@JimBobSquarePants

Copy link
Copy Markdown
Member

Prerequisites

  • I have written a descriptive pull-request title
  • I have verified that there are no overlapping pull-requests open
  • I have verified that I am following the existing coding patterns and practice as demonstrated in the repository. These follow strict Stylecop rules 👮.
  • I have provided test coverage for my change (where applicable)

Description

Backport of #3203 and #3277 to 3.2.x. Fixes #3202 and #3215 on this line.

The PNG decoder allocates the chunk data before it reads the data, reads the CRC and, for IDAT and fdAT, restores the stream position. Each of these can throw, for example when the stream observes a cancellation request. The caller does not own the chunk yet, so the buffer was not disposed.

3.2.x did not have #3203, so this PR includes it. Without it, a cancellation during the data read still leaks the buffer.

Tests:

3.2.x has no DecoderOptions(Configuration) constructor and no TestMemoryAllocator.LiveBufferBytes, so the tests use the Configuration initializer and check only that every allocation is returned.

JimBobSquarePants and others added 3 commits November 23, 2026 11:50
…ffer-leak-on-cancel

fix: Dispose chunk data buffer in ReadChunkData when read is cancelled
(cherry picked from commit eefdbd9)
Both new tests cancelled at the seek after the direct IDAT data read, so
both covered only the CRC read. The position restore test now cancels
during the read that fills the CRC, which the position restore observes
first.

Also explain the ownership rule at the catch, remove an assignment that
has no effect, and use BinaryPrimitives and using directives in the tests.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ JimBobSquarePants
❌ EnesKartal
You have signed the CLA already but the status is still pending? Let us recheck it.

1 similar comment
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ JimBobSquarePants
❌ EnesKartal
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants