From c8f0791d4d668dbbae1d67a37ecf17950e09fc11 Mon Sep 17 00:00:00 2001 From: DRC Date: Sun, 17 Apr 2011 15:41:10 +0000 Subject: [PATCH] Detect unexpected markers found in JPEG datastream and throw a warning like libjpeg does. git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/branches/1_1@4379 3789f03b-4d11-0410-bbf8-ca57d06f2519 --- common/jpeg/jdhuff.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/common/jpeg/jdhuff.c b/common/jpeg/jdhuff.c index 0291bc97..a40c2ff5 100644 --- a/common/jpeg/jdhuff.c +++ b/common/jpeg/jdhuff.c @@ -621,6 +621,7 @@ decode_mcu_slow (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) if (val0 == 0xFF) { \ buffer++; \ if (val1 != 0) { \ + cinfo->unread_marker = val1; \ buffer -= 2; \ get_buffer &= ~0xFF; \ } \ @@ -737,6 +738,11 @@ decode_mcu_fast (j_decompress_ptr cinfo, JBLOCKROW *MCU_data) } } + if (cinfo->unread_marker != 0) { + cinfo->unread_marker = 0; + return FALSE; + } + br_state.bytes_in_buffer -= (buffer - br_state.next_input_byte); br_state.next_input_byte = buffer; BITREAD_SAVE_STATE(cinfo,entropy->bitstate); @@ -776,7 +782,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. @@ -785,9 +792,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.39.5