From 651da5f51cec72d575c6a2c2fa1f8948cdcbf6a0 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 17 Feb 2015 05:17:24 +0100 Subject: [PATCH] Fix potential memleak in MPNG_CHUNK_IDAT --- libretro-sdk/formats/mpng/mpng_decode.c | 37 ++++++++++++------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/libretro-sdk/formats/mpng/mpng_decode.c b/libretro-sdk/formats/mpng/mpng_decode.c index 70dfb584ba..80f449597a 100644 --- a/libretro-sdk/formats/mpng/mpng_decode.c +++ b/libretro-sdk/formats/mpng/mpng_decode.c @@ -234,32 +234,28 @@ bool png_decode(const void *userdata, size_t len, goto error; break; case MPNG_CHUNK_PLTE: - { - if (chunk.size % 3) - goto error; + if (chunk.size % 3) + goto error; - palette_len = chunk.size / 3; + palette_len = chunk.size / 3; - if (!mpng_read_plte(&ihdr, &chunk, pixels, palette, palette_len)) - goto error; - } + if (!mpng_read_plte(&ihdr, &chunk, pixels, palette, palette_len)) + goto error; break; case MPNG_CHUNK_TRNS: - { - if (format != FMT_ARGB8888 || !pixels || pixels != pixelsat) - goto error; + if (format != FMT_ARGB8888 || !pixels || pixels != pixelsat) + goto error; - if (ihdr.color_type == 2) - { - if (palette_len == 0) - goto error; - goto error; - } - else if (ihdr.color_type == 3) - goto error; - else + if (ihdr.color_type == 2) + { + if (palette_len == 0) goto error; + goto error; } + else if (ihdr.color_type == 3) + goto error; + else + goto error; break; case MPNG_CHUNK_IDAT: { @@ -335,6 +331,9 @@ bool png_decode(const void *userdata, size_t len, out = (uint8_t*)malloc(videofmt_byte_per_pixel(format) * ihdr.width * ihdr.height); + if (!out) + goto error; + /* TODO: deinterlace at random point */ /* run filters */