Skip to content

Commit 4dbc293

Browse files
committed
Fix buf image mode decompr err w/ short prog JPEGs
Regression introduced by 6d91e95 Because we're now using a 5x5 smoothing window when decompressing progressive JPEG images, we need to ensure that the whole_image virtual array contains at least five rows. Previously that was not always the case unless the progressive JPEG image being decompressed had at least five iMCU rows. Since an iMCU has a height of (8 * the vertical sampling factor), attempting to decompress 4:2:2 and 4:4:4 images <= 32 pixels in height or 4:2:0 images <= 64 pixels in height triggered a JERR_BAD_VIRTUAL_ACCESS error in decompress_smooth_data(), because access_rows exceeded the number of rows in the virtual array. Fixes #613
1 parent 59337a6 commit 4dbc293

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ OS X/PowerPC systems if AltiVec instructions are not enabled at compile time.
1717
This allows both AltiVec-equipped (PowerPC G4 and G5) and non-AltiVec-equipped
1818
(PowerPC G3) CPUs to be supported using the same build of libjpeg-turbo.
1919

20+
4. Fixed an error ("Bogus virtual array access") that occurred when attempting
21+
to decompress a progressive JPEG image with a height less than or equal to
22+
(32 * the vertical sampling factor) using buffered image mode. This was a
23+
regression introduced by 2.1 beta1[6(b)].
24+
2025

2126
2.1.3
2227
=====

jdcoefct.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Copyright (C) 1994-1997, Thomas G. Lane.
66
* libjpeg-turbo Modifications:
77
* Copyright 2009 Pierre Ossman <[email protected]> for Cendio AB
8-
* Copyright (C) 2010, 2015-2016, 2019-2020, D. R. Commander.
8+
* Copyright (C) 2010, 2015-2016, 2019-2020, 2022, D. R. Commander.
99
* Copyright (C) 2015, 2020, Google, Inc.
1010
* For conditions of distribution and use, see the accompanying README.ijg
1111
* file.
@@ -835,18 +835,21 @@ jinit_d_coef_controller(j_decompress_ptr cinfo, boolean need_full_buffer)
835835

836836
for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
837837
ci++, compptr++) {
838+
JDIMENSION num_rows =
839+
(JDIMENSION)jround_up((long)compptr->height_in_blocks,
840+
(long)compptr->v_samp_factor);
838841
access_rows = compptr->v_samp_factor;
839842
#ifdef BLOCK_SMOOTHING_SUPPORTED
840843
/* If block smoothing could be used, need a bigger window */
841-
if (cinfo->progressive_mode)
844+
if (cinfo->progressive_mode) {
842845
access_rows *= 5;
846+
num_rows = MAX(num_rows, access_rows);
847+
}
843848
#endif
844849
coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
845850
((j_common_ptr)cinfo, JPOOL_IMAGE, TRUE,
846851
(JDIMENSION)jround_up((long)compptr->width_in_blocks,
847-
(long)compptr->h_samp_factor),
848-
(JDIMENSION)jround_up((long)compptr->height_in_blocks,
849-
(long)compptr->v_samp_factor),
852+
(long)compptr->h_samp_factor), num_rows,
850853
(JDIMENSION)access_rows);
851854
}
852855
coef->pub.consume_data = consume_data;

0 commit comments

Comments
 (0)