mirror of
https://github.com/libretro/RetroArch
synced 2025-02-06 00:39:53 +00:00
Optimize read_chunk_header
This commit is contained in:
parent
107b640bc0
commit
33f9ef90d8
@ -947,16 +947,15 @@ static bool read_chunk_header(uint8_t *buf, uint8_t *buf_end,
|
|||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i;
|
||||||
uint8_t dword[4];
|
uint8_t dword[4];
|
||||||
|
uint8_t *dword_ptr = NULL;
|
||||||
|
uint8_t *buf_ptr = NULL;
|
||||||
|
|
||||||
dword[0] = '\0';
|
dword[0] = '\0';
|
||||||
|
|
||||||
/* Check whether reading the header will overflow
|
for ( dword_ptr = &dword[0], buf_ptr = &buf[0]
|
||||||
* the data buffer */
|
; dword_ptr < dword + 4
|
||||||
if (buf_end - buf < 8)
|
; dword_ptr++, buf_ptr++)
|
||||||
return false;
|
*dword_ptr = *buf_ptr;
|
||||||
|
|
||||||
for (i = 0; i < 4; i++)
|
|
||||||
dword[i] = buf[i];
|
|
||||||
|
|
||||||
chunk->size = dword_be(dword);
|
chunk->size = dword_be(dword);
|
||||||
|
|
||||||
@ -1010,6 +1009,10 @@ bool rpng_iterate_image(rpng_t *rpng)
|
|||||||
if (buf > rpng->buff_end)
|
if (buf > rpng->buff_end)
|
||||||
return false;
|
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))
|
if (!read_chunk_header(buf, rpng->buff_end, &chunk))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user