From c17fdcb1e7b59e6136620fe4a277b62649da25c6 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 25 Sep 2016 13:40:53 -0700 Subject: [PATCH] Util: Fix PNG identification on files too small to be a PNG --- CHANGES | 1 + src/util/png-io.c | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 234cfad89..c5307cd0b 100644 --- a/CHANGES +++ b/CHANGES @@ -14,6 +14,7 @@ Bugfixes: - Qt: Fix directory set unloading when replacing the ROM - GBA Savedata: Fix loading savestates with 512Mb Flash saves - Core: Fix importing save games as read-only + - Util: Fix PNG identification on files too small to be a PNG Misc: - All: Only update version info if needed - FFmpeg: Encoding cleanup diff --git a/src/util/png-io.c b/src/util/png-io.c index 5e2f69425..bac188c8d 100644 --- a/src/util/png-io.c +++ b/src/util/png-io.c @@ -116,7 +116,9 @@ void PNGWriteClose(png_structp png, png_infop info) { bool isPNG(struct VFile* source) { png_byte header[PNG_HEADER_BYTES]; - source->read(source, header, PNG_HEADER_BYTES); + if (source->read(source, header, PNG_HEADER_BYTES) < PNG_HEADER_BYTES) { + return false; + } return !png_sig_cmp(header, 0, PNG_HEADER_BYTES); }