From 1067e2859a618f1456c94639deff5f05a447f595 Mon Sep 17 00:00:00 2001 From: 0xMrNiko Date: Mon, 13 Jul 2026 00:22:16 +0530 Subject: [PATCH] Fix APNG push/sequential frame-count divergence (#891) When a leading fcTL has an incorrect frame size it is ignored and PNG_FIRST_FRAME_HIDDEN is set. The progressive reader was still calling frame_end_fn after the default IDAT, completing 1 frame while the sequential reader completed 0. Skip the frame_end callback for the hidden default image to align both read paths. --- pngpread.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pngpread.c b/pngpread.c index 978559adeb..4a8eef85c1 100644 --- a/pngpread.c +++ b/pngpread.c @@ -591,8 +591,14 @@ png_push_read_IDAT(png_struct *png_ptr) png_error(png_ptr, "Not enough compressed data"); #ifdef PNG_READ_APNG_SUPPORTED - if (png_ptr->frame_end_fn != NULL) - (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read); + /* Default image is not an animation frame when the leading fcTL was + * ignored; match sequential reader (no frame_end for hidden frame). + */ + if ((png_ptr->apng_flags & PNG_FIRST_FRAME_HIDDEN) == 0) + { + if (png_ptr->frame_end_fn != NULL) + (*(png_ptr->frame_end_fn))(png_ptr, png_ptr->num_frames_read); + } png_ptr->num_frames_read++; #endif