SDL_image: fix stbi__parse_png_file() reading too much bytes (00d94)

From 00d94547e0474224ac9530c2e18046ba08ad295e Mon Sep 17 00:00:00 2001
From: Thomas Bernard <[EMAIL REDACTED]>
Date: Sun, 23 Feb 2025 01:47:57 +0100
Subject: [PATCH] fix stbi__parse_png_file() reading too much bytes

just "rewind" the bytes that have been read past the IEND
chunk.

should fix #360 and #524

(cherry picked from commit 4e165ac1baf5bc6a0a9bb74bd1eed7c9c84dd67a)
---
 src/stb_image.h | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/stb_image.h b/src/stb_image.h
index 7ba9d30c9..61cbb400e 100644
--- a/src/stb_image.h
+++ b/src/stb_image.h
@@ -5395,6 +5395,10 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp, unsigned i
             STBI_FREE(z->expanded); z->expanded = NULL;
             // end of PNG chunk, read and skip CRC
             stbi__get32be(s);
+            if (s->io.skip && s->img_buffer_end > s->img_buffer) {
+               // rewind the additional bytes that have been read to the buffer
+               (s->io.skip)(s->io_user_data, (int)(s->img_buffer - s->img_buffer_end));
+            }
             return 1;
          }