From ea5d1343374f861ab7a6089f5ae0dceb52aa1c9d Mon Sep 17 00:00:00 2001 From: twinaphex Date: Wed, 19 Aug 2020 18:15:54 +0200 Subject: [PATCH] Revert "Optimize read_chunk_header" This reverts commit 33f9ef90d8c821abbc1752c70866e97a6f17dfe3. --- libretro-common/formats/png/rpng.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/libretro-common/formats/png/rpng.c b/libretro-common/formats/png/rpng.c index d54100f43b..9359d98f3a 100644 --- a/libretro-common/formats/png/rpng.c +++ b/libretro-common/formats/png/rpng.c @@ -947,15 +947,16 @@ static bool read_chunk_header(uint8_t *buf, uint8_t *buf_end, { unsigned i; uint8_t dword[4]; - uint8_t *dword_ptr = NULL; - uint8_t *buf_ptr = NULL; - dword[0] = '\0'; + dword[0] = '\0'; - for ( dword_ptr = &dword[0], buf_ptr = &buf[0] - ; dword_ptr < dword + 4 - ; dword_ptr++, buf_ptr++) - *dword_ptr = *buf_ptr; + /* 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]; chunk->size = dword_be(dword); @@ -1009,10 +1010,6 @@ 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;