Skip to content

Fix Identify returning incorrect frame count for animated PNGs#3101

Open
andreas-eriksson wants to merge 3 commits intoSixLabors:mainfrom
andreas-eriksson:ImageInfo.FrameMetadataCollection-not-populated-correctly-for-animated-png-images
Open

Fix Identify returning incorrect frame count for animated PNGs#3101
andreas-eriksson wants to merge 3 commits intoSixLabors:mainfrom
andreas-eriksson:ImageInfo.FrameMetadataCollection-not-populated-correctly-for-animated-png-images

Conversation

@andreas-eriksson
Copy link
Copy Markdown

@andreas-eriksson andreas-eriksson commented Apr 1, 2026

The Identify method had two bugs when processing fdAT (FrameData) chunks:

  1. A spurious Skip(4) before SkipChunkDataAndCrc caused the stream to be misaligned by 4 bytes, since chunk.Length already includes the 4-byte sequence number.

  2. Unlike Decode, which consumes all fdAT chunks for a frame in one shot via ReadScanlines + ReadNextFrameDataChunk, Identify processed them individually, calling InitializeFrameMetadata for each chunk and inflating the frame count.

The fix removes the extra Skip(4) and adds SkipRemainingFrameDataChunks to consume all continuation fdAT chunks for a frame, mirroring how ReadNextFrameDataChunk works during decoding.

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

The Identify method had two bugs when processing fdAT (FrameData) chunks:

1. A spurious Skip(4) before SkipChunkDataAndCrc caused the stream to
   be misaligned by 4 bytes, since chunk.Length already includes the
   4-byte sequence number.

2. Unlike Decode, which consumes all fdAT chunks for a frame in one shot
   via ReadScanlines + ReadNextFrameDataChunk, Identify processed them
   individually, calling InitializeFrameMetadata for each chunk and
   inflating the frame count.

The fix removes the extra Skip(4) and adds SkipRemainingFrameDataChunks
to consume all continuation fdAT chunks for a frame, mirroring how
ReadNextFrameDataChunk works during decoding.
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 1, 2026

CLA assistant check
All committers have signed the CLA.

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