Skip to content

Commit

Permalink
COMP: Updated to jpeg9f to address ubsan failures
Browse files Browse the repository at this point in the history
  • Loading branch information
hjmjohnson committed Mar 13, 2023
1 parent b37e416 commit e80db20
Show file tree
Hide file tree
Showing 56 changed files with 8,592 additions and 7,031 deletions.
176 changes: 112 additions & 64 deletions Modules/ThirdParty/JPEG/src/itkjpeg/README

Large diffs are not rendered by default.

210 changes: 210 additions & 0 deletions Modules/ThirdParty/JPEG/src/itkjpeg/change.log
@@ -1,6 +1,216 @@
CHANGE LOG for Independent JPEG Group's JPEG software


Version 9f 14-Jan-2024
-----------------------

Add build system for C++Builder/RAD Studio.

Add ARM64EC (Emulation Compatible) platform support in the
Visual Studio build.


Version 9e 16-Jan-2022
-----------------------

Include alternate user interface files for cjpeg/djpeg.

jcparam.c: change default chrominance DC quantization factor
for lossless support. Note: Requires rebuild of test images.

rdgif.c, cderror.h: add sanity check for GIF image dimensions.
Thank to Casper Sun for cjpeg potential vulnerability report.

Add ARM and ARM64 platform support in the Visual Studio build.


Version 9d 12-Jan-2020
-----------------------

Optimize the optimal Huffman code table generation to produce
slightly smaller files. Thank to John Korejwa for suggestion.
Note: Requires rebuild of testimgp.jpg.

Decoding Huffman: Use default tables if tables are not defined.
Thank to Simone Azzalin for report (Motion JPEG),
and to Martin Strunz for hint.

Add sanity check in optimal Huffman code table generation.
Thank to Adam Farley for suggestion.

rdtarga.c: use read_byte(), with EOF check, instead of getc()
in read_*_pixel().
Thank to Chijin Zhou for cjpeg potential vulnerability report.

jmemnobs.c: respect the max_memory_to_use setting in
jpeg_mem_available() computation. Thank to Sheng Shu and
Dongdong She for djpeg potential vulnerability report.

jdarith.c, jdhuff.c: avoid left shift of negative value
compiler warning in decode_mcu_AC_refine().
Thank to Indu Bhagat for suggestion.

Add x64 (64-bit) platform support, avoid compiler warnings.
Thank to Jonathan Potter, Feiyun Wang, and Sheng Shu for suggestion.

Adjust libjpeg version specification for pkg-config file.
Thank to Chen Chen for suggestion.

Restore GIF read and write support from libjpeg version 6a.
Thank to Wolfgang Werner (W.W.) Heinz for suggestion.

Improve consistency in raw (downsampled) image data processing mode.
Thank to Zhongyuan Zhou for hint.

Avoid out of bounds array read (AC derived table pointers)
in start pass in jdhuff.c. Thank to Peng Li for report.

Improve code sanity (jdhuff.c).
Thank to Reza Mirzazade farkhani for reports.

Add jpegtran -drop option; add options to the crop extension and wipe
to fill the extra area with content from the source image region,
instead of gray out.


Version 9c 14-Jan-2018
-----------------------

jpegtran: add an option to the -wipe switch to fill the region
with the average of adjacent blocks, instead of gray out.
Thank to Caitlyn Feddock and Maddie Ziegler for inspiration.

Make range extension bits adjustable (in jpegint.h).
Thank to Robin Watts for suggestion.

Provide macros for fflush() and ferror() in jinclude.h in order
to facilitate adaption by applications using an own FILE class.
Thank to Gerhard Huber for suggestion.

Add libjpeg pkg-config file. Thank to Mark Lavi, Vincent Torri,
Patrick McMunn, and Huw Davies for suggestion.

Add sanity checks in cjpeg image reader modules.
Thank to Bingchang, Liu for reports.


Version 9b 17-Jan-2016
-----------------------

Improvements and optimizations in DCT and color calculations.
Normalize range limit array composition and access pattern.
Thank to Sia Furler and Maddie Ziegler for inspiration.

Use merged upsample with scaled DCT sizes larger than 8.
Thank to Taylor Hatala for inspiration.

Check for excessive comment lengths in argument parsing in wrjpgcom.c.
Thank to Julian Cohen for hint.

Add makefile.b32 for use with Borland C++ 32-bit (bcc32).
Thank to Joe Slater for contribution.

Document 'f' specifier for jpegtran -crop specification.
Thank to Michele Martone for suggestion.

Use defined value from header instead of hardwired number in rdswitch.c.
Thank to Robert Sprowson for hint.


Version 9a 19-Jan-2014
-----------------------

Add support for wide gamut color spaces (JFIF version 2).
Improve clarity and accuracy in color conversion modules.
Note: Requires rebuild of test images.

Extend the bit depth support to all values from 8 to 12
(BITS_IN_JSAMPLE configuration option in jmorecfg.h).
jpegtran now supports N bits sample data precision with all N from 8 to 12
in a single instance. Thank to Roland Fassauer for inspiration.

Try to resolve issues with new boolean type definition.
Thank also to v4hn for suggestion.

Enable option to use default Huffman tables for lossless compression
(for hardware solution), and in this case improve lossless RGB compression
with reversible color transform. Thank to Benny Alexandar for hint.

Extend the entropy decoding structure, so that extraneous bytes between
compressed scan data and following marker can be reported correctly.
Thank to Nigel Tao for hint.

Add jpegtran -wipe option and extension for -crop.
Thank to Andrew Senior, David Clunie, and Josef Schmid for suggestion.


Version 9 13-Jan-2013
----------------------

Add cjpeg -rgb1 option to create an RGB JPEG file, and insert
a simple reversible color transform into the processing which
significantly improves the compression.
The recommended command for lossless coding of RGB images is now
cjpeg -rgb1 -block 1 -arithmetic.
As said, this option improves the compression significantly, but
the files are not compatible with JPEG decoders prior to IJG v9
due to the included color transform.
The used color transform and marker signaling is compatible with
other JPEG standards (e.g., JPEG-LS part 2).

Remove the automatic de-ANSI-fication support (Automake 1.12).
Thank also to Nitin A Kamble for suggestion.

Add remark for jpeg_mem_dest() in jdatadst.c.
Thank to Elie-Gregoire Khoury for the hint.

Support files with invalid component identifiers (created
by Adobe PDF). Thank to Robin Watts for the suggestion.

Adapt full buffer case in jcmainct.c for use with scaled DCT.
Thank to Sergii Biloshytskyi for the suggestion.

Add type identifier for declaration of noreturn functions.
Thank to Brett L. Moore for the suggestion.

Correct argument type in format string, avoid compiler warnings.
Thank to Vincent Torri for hint.

Add missing #include directives in configuration checks, avoid
configuration errors. Thank to John Spencer for the hint.


Version 8d 15-Jan-2012
-----------------------

Add cjpeg -rgb option to create RGB JPEG files.
Using this switch suppresses the conversion from RGB
colorspace input to the default YCbCr JPEG colorspace.
This feature allows true lossless JPEG coding of RGB color images.
The recommended command for this purpose is currently
cjpeg -rgb -block 1 -arithmetic.
SmartScale capable decoder (introduced with IJG JPEG 8) required.
Thank to Michael Koch for the initial suggestion.

Add option to disable the region adjustment in the transupp crop code.
Thank to Jeffrey Friedl for the suggestion.

Thank to Richard Jones and Edd Dawson for various minor corrections.

Thank to Akim Demaille for configure.ac cleanup.


Version 8c 16-Jan-2011
-----------------------

Add option to compression library and cjpeg (-block N) to use
different DCT block size.
All N from 1 to 16 are possible. Default is 8 (baseline format).
Larger values produce higher compression,
smaller values produce higher quality.
SmartScale capable decoder (introduced with IJG JPEG 8) required.


Version 8b 16-May-2010
-----------------------

Expand Down
10 changes: 5 additions & 5 deletions Modules/ThirdParty/JPEG/src/itkjpeg/jaricom.c
@@ -1,16 +1,16 @@
/*
* jaricom.c
*
* Developed 1997-2009 by Guido Vollbeding.
* Developed 1997-2011 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file.
*
* This file contains probability estimation tables for common use in
* arithmetic entropy encoding and decoding routines.
*
* This data represents Table D.2 in the JPEG spec (ISO/IEC IS 10918-1
* and CCITT Recommendation ITU-T T.81) and Table 24 in the JBIG spec
* (ISO/IEC IS 11544 and CCITT Recommendation ITU-T T.82).
* This data represents Table D.3 in the JPEG spec (D.2 in the draft),
* ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81, and Table 24
* in the JBIG spec, ISO/IEC IS 11544 and CCITT Recommendation ITU-T T.82.
*/

#define JPEG_INTERNALS
Expand Down Expand Up @@ -147,7 +147,7 @@ const INT32 jpeg_aritab[113+1] = {
V( 112, 0x59eb, 112, 111, 1 ),
/*
* This last entry is used for fixed probability estimate of 0.5
* as recommended in Section 10.3 Table 5 of ITU-T Rec. T.851.
* as suggested in Section 10.3 Table 5 of ITU-T Rec. T.851.
*/
V( 113, 0x5a1d, 113, 113, 0 )
};
36 changes: 18 additions & 18 deletions Modules/ThirdParty/JPEG/src/itkjpeg/jcapimin.c
Expand Up @@ -33,12 +33,12 @@ jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
int i;

/* Guard against version mismatches between library and caller. */
cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
if (version != JPEG_LIB_VERSION)
ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
if (structsize != SIZEOF(struct jpeg_compress_struct))
ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
(int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
(int) SIZEOF(struct jpeg_compress_struct), (int) structsize);

/* For debugging purposes, we zero the whole master structure.
* But the application has already set the err pointer, and may have set
Expand Down Expand Up @@ -81,7 +81,7 @@ jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)

cinfo->script_space = NULL;

cinfo->input_gamma = 1.0; /* in case application forgets */
cinfo->input_gamma = 1.0; /* in case application forgets */

/* OK, I'm ready */
cinfo->global_state = CSTATE_START;
Expand Down Expand Up @@ -169,15 +169,15 @@ jpeg_finish_compress (j_compress_ptr cinfo)
(*cinfo->master->prepare_for_pass) (cinfo);
for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
if (cinfo->progress != NULL) {
cinfo->progress->pass_counter = (long) iMCU_row;
cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
cinfo->progress->pass_counter = (long) iMCU_row;
cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
}
/* We bypass the main controller and invoke coef controller directly;
* all work is being done from the coefficient buffer.
*/
if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
ERREXIT(cinfo, JERR_CANT_SUSPEND);
ERREXIT(cinfo, JERR_CANT_SUSPEND);
}
(*cinfo->master->finish_pass) (cinfo);
}
Expand All @@ -198,7 +198,7 @@ jpeg_finish_compress (j_compress_ptr cinfo)

GLOBAL(void)
jpeg_write_marker (j_compress_ptr cinfo, int marker,
const JOCTET *dataptr, unsigned int datalen)
const JOCTET *dataptr, unsigned int datalen)
{
JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));

Expand All @@ -209,7 +209,7 @@ jpeg_write_marker (j_compress_ptr cinfo, int marker,
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

(*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
while (datalen--) {
(*write_marker_byte) (cinfo, *dataptr);
dataptr++;
Expand Down Expand Up @@ -244,14 +244,14 @@ jpeg_write_m_byte (j_compress_ptr cinfo, int val)
* To produce a pair of files containing abbreviated tables and abbreviated
* image data, one would proceed as follows:
*
* initialize JPEG object
* set JPEG parameters
* set destination to table file
* jpeg_write_tables(cinfo);
* set destination to image file
* jpeg_start_compress(cinfo, FALSE);
* write data...
* jpeg_finish_compress(cinfo);
* initialize JPEG object
* set JPEG parameters
* set destination to table file
* jpeg_write_tables(cinfo);
* set destination to image file
* jpeg_start_compress(cinfo, FALSE);
* write data...
* jpeg_finish_compress(cinfo);
*
* jpeg_write_tables has the side effect of marking all tables written
* (same as jpeg_suppress_tables(..., TRUE)). Thus a subsequent start_compress
Expand Down
9 changes: 5 additions & 4 deletions Modules/ThirdParty/JPEG/src/itkjpeg/jcapistd.c
Expand Up @@ -2,6 +2,7 @@
* jcapistd.c
*
* Copyright (C) 1994-1996, Thomas G. Lane.
* Modified 2013 by Guido Vollbeding.
* This file is part of the Independent JPEG Group's software.
* For conditions of distribution and use, see the accompanying README file.
*
Expand Down Expand Up @@ -41,7 +42,7 @@ jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

if (write_all_tables)
jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */

/* (Re)initialize error mgr and destination modules */
(*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
Expand Down Expand Up @@ -75,7 +76,7 @@ jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)

GLOBAL(JDIMENSION)
jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
JDIMENSION num_lines)
JDIMENSION num_lines)
{
JDIMENSION row_ctr, rows_left;

Expand Down Expand Up @@ -118,7 +119,7 @@ jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,

GLOBAL(JDIMENSION)
jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
JDIMENSION num_lines)
JDIMENSION num_lines)
{
JDIMENSION lines_per_iMCU_row;

Expand All @@ -145,7 +146,7 @@ jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
(*cinfo->master->pass_startup) (cinfo);

/* Verify that at least one iMCU row has been passed. */
lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_v_scaled_size;
if (num_lines < lines_per_iMCU_row)
ERREXIT(cinfo, JERR_BUFFER_SIZE);

Expand Down

0 comments on commit e80db20

Please sign in to comment.