diff --git a/libretro-common/formats/png/rpng.c b/libretro-common/formats/png/rpng.c index 1c2b2de1d9..8831cab5a4 100644 --- a/libretro-common/formats/png/rpng.c +++ b/libretro-common/formats/png/rpng.c @@ -959,11 +959,6 @@ static bool read_chunk_header(uint8_t *buf, uint8_t *buf_end, dword[0] = '\0'; - /* Check whether reading the header will overflow - * the data buffer */ - if (buf_end - buf < 8) - return false; - for (i = 0; i < 4; i++) dword[i] = buf[i]; @@ -1019,6 +1014,10 @@ bool rpng_iterate_image(rpng_t *rpng) if (buf > rpng->buff_end) return false; + /* Check whether reading the header will overflow + * the data buffer */ + if (rpng->buff_end - buf < 8) + return false; if (!read_chunk_header(buf, rpng->buff_end, &chunk)) return false;