From 051d962318c041a907cf5ce8442d074185de7f73 Mon Sep 17 00:00:00 2001 From: DRC Date: Sat, 16 Apr 2011 18:53:26 +0000 Subject: [PATCH] The previous attempt to handle unexpected markers in the data stream caused breakage in applications that attempted to set bytes_in_buffer to a larger value than the actual size of the JPEG image. The latter behavior was causing the fast decoder to be used for the last MCU in the image under certain circumstances, and this sometimes caused the EOI marker to be encountered by the fast decoder, which was treating it as an "unexpected" marker and throwing an error. Now, the fast decoder simply hands off the decoding of the block to the slow decoder if any marker is encountered. git-svn-id: svn+ssh://svn.code.sf.net/p/libjpeg-turbo/code/trunk@584 632fc199-4ca6-4c93-a231-07263d6284db --- jdhuff.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/jdhuff.c b/jdhuff.c index f6b6e00..b795462 100644 --- a/jdhuff.c +++ b/jdhuff.c @@ -740,9 +740,9 @@ decode_mcu_fast (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) } } - if (cinfo->unread_marker != 0 && ! cinfo->entropy->insufficient_data) { - WARNMS(cinfo, JWRN_HIT_MARKER); - cinfo->entropy->insufficient_data = TRUE; + if (cinfo->unread_marker != 0) { + cinfo->unread_marker = 0; + return FALSE; } br_state.bytes_in_buffer -= (buffer - br_state.next_input_byte); @@ -784,7 +784,8 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) usefast = 0; } - if (cinfo->src->bytes_in_buffer < BUFSIZE * cinfo->blocks_in_MCU) + if (cinfo->src->bytes_in_buffer < BUFSIZE * cinfo->blocks_in_MCU + || cinfo->unread_marker != 0) usefast = 0; /* If we've run out of data, just leave the MCU set to zeroes. @@ -793,9 +794,10 @@ decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) if (! entropy->pub.insufficient_data) { if (usefast) { - if (!decode_mcu_fast(cinfo, MCU_data)) return FALSE; + if (!decode_mcu_fast(cinfo, MCU_data)) goto use_slow; } else { + use_slow: if (!decode_mcu_slow(cinfo, MCU_data)) return FALSE; } -- 2.40.0