From 8162eddf041e0be26f5c671bb6528723c55fed9d Mon Sep 17 00:00:00 2001 From: DRC Date: Mon, 8 Aug 2022 16:02:34 -0500 Subject: [PATCH] Fix issues w/ partial img decompr + buf img mode Fixes #611 --- ChangeLog.md | 9 +++++++++ jdapistd.c | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 59ca516cc..b0d166ea1 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -23,6 +23,15 @@ iMCU (8 * the vertical sampling factor) using buffered-image mode with interblock smoothing enabled. This was a regression introduced by 2.1 beta1[6(b)]. +5. Fixed two issues that prevented partial image decompression from working +properly with buffered-image mode: + + - Attempting to call `jpeg_crop_scanline()` after +`jpeg_start_decompress()` but before `jpeg_start_output()` resulted in an error +("Improper call to JPEG library in state 207".) + - Attempting to use `jpeg_skip_scanlines()` resulted in an error ("Bogus +virtual array access") under certain circumstances. + 2.1.3 ===== diff --git a/jdapistd.c b/jdapistd.c index f9908a7ae..02cd0cb93 100644 --- a/jdapistd.c +++ b/jdapistd.c @@ -163,7 +163,8 @@ jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset, my_master_ptr master = (my_master_ptr)cinfo->master; #endif - if (cinfo->global_state != DSTATE_SCANNING || cinfo->output_scanline != 0) + if ((cinfo->global_state != DSTATE_SCANNING && + cinfo->global_state != DSTATE_BUFIMAGE) || cinfo->output_scanline != 0) ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); if (!xoffset || !width) @@ -525,7 +526,7 @@ jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines) * all of the entropy decoding occurs in jpeg_start_decompress(), assuming * that the input data source is non-suspending. This makes skipping easy. */ - if (cinfo->inputctl->has_multiple_scans) { + if (cinfo->inputctl->has_multiple_scans || cinfo->buffered_image) { if (cinfo->upsample->need_context_rows) { cinfo->output_scanline += lines_to_skip; cinfo->output_iMCU_row += lines_to_skip / lines_per_iMCU_row;