Skip to content

Commit

Permalink
Update bundled libjpeg-turbo to version 3.0.4
Browse files Browse the repository at this point in the history
[ChangeLog][Third-Party Code] libjpeg-turbo was updated to version 3.0.4

Pick-to: 6.8 6.8.0 6.7 6.7.3 6.5 6.2 5.15
Change-Id: Ifa437bfc9b99f386d792a045b0963f3690e322d9
Reviewed-by: Eskil Abrahamsen Blomfeldt <[email protected]>
  • Loading branch information
aavit committed Sep 18, 2024
1 parent e585b93 commit c1ee648
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 91 deletions.
4 changes: 2 additions & 2 deletions src/3rdparty/libjpeg/qt_attribution.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

"Description": "The Independent JPEG Group's JPEG software",
"Homepage": "http://libjpeg-turbo.virtualgl.org/",
"Version": "3.0.3",
"DownloadLocation": "https://github.com/libjpeg-turbo/libjpeg-turbo/releases/download/3.0.3/libjpeg-turbo-3.0.3.tar.gz",
"Version": "3.0.4",
"DownloadLocation": "https://github.com/libjpeg-turbo/libjpeg-turbo/releases/download/3.0.4/libjpeg-turbo-3.0.4.tar.gz",

"License": "Independent JPEG Group License and BSD 3-Clause \"New\" or \"Revised\" License",
"LicenseId": "IJG AND BSD-3-Clause",
Expand Down
102 changes: 79 additions & 23 deletions src/3rdparty/libjpeg/src/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,61 @@
3.0.4
=====

### Significant changes relative to 3.0.3:

1. Fixed an issue whereby the CPU usage of the default marker processor in the
decompressor grew exponentially with the number of markers. This caused an
unreasonable slow-down in `jpeg_read_header()` if an application called
`jpeg_save_markers()` to save markers of a particular type and then attempted
to decompress a JPEG image containing an excessive number of markers of that
type.

2. Hardened the default marker processor in the decompressor to guard against
an issue (exposed by 3.0 beta2[6]) whereby attempting to decompress a
specially-crafted malformed JPEG image (specifically an image with a complete
12-bit-per-sample Start Of Frame segment followed by an incomplete
8-bit-per-sample Start Of Frame segment) using buffered-image mode and input
prefetching caused a segfault if the `fill_input_buffer()` method in the
calling application's custom source manager incorrectly returned `FALSE` in
response to a prematurely-terminated JPEG data stream.

3. Fixed an issue in cjpeg whereby, when generating a 12-bit-per-sample or
16-bit-per-sample lossless JPEG image, specifying a point transform value
greater than 7 resulted in an error ("Invalid progressive/lossless parameters")
unless the `-precision` option was specified before the `-lossless` option.

4. Fixed a regression introduced by 3.0.3[3] that made it impossible for
calling applications to generate 12-bit-per-sample arithmetic-coded lossy JPEG
images using the TurboJPEG API.

5. Fixed an error ("Destination buffer is not large enough") that occurred when
attempting to generate a full-color lossless JPEG image using the TurboJPEG
Java API's `byte[] TJCompressor.compress()` method if the value of
`TJ.PARAM_SUBSAMP` was not `TJ.SAMP_444`.

6. Fixed a segfault in djpeg that occurred if a negative width was specified
with the `-crop` option. Since the cropping region width was read into an
unsigned 32-bit integer, a negative width was interpreted as a very large
value. With certain negative width and positive left boundary values, the
bounds checks in djpeg and `jpeg_crop_scanline()` overflowed and did not detect
the out-of-bounds width, which caused a buffer overrun in the upsampling or
color conversion routine. Both bounds checks now use 64-bit integers to guard
against overflow, and djpeg now checks for negative numbers when it parses the
crop specification from the command line.

7. Fixed an issue whereby the TurboJPEG lossless transformation function and
methods checked the specified cropping region against the source image
dimensions and level of chrominance subsampling rather than the destination
image dimensions and level of chrominance subsampling, which caused some
cropping regions to be unduly rejected when performing 90-degree rotation,
270-degree rotation, transposition, transverse transposition, or grayscale
conversion.

8. Fixed an issue whereby the TurboJPEG lossless transformation function and
methods did not honor `TJXOPT_COPYNONE`/`TJTransform.OPT_COPYNONE` unless it
was specified for all lossless transforms.


3.0.3
=====

Expand Down Expand Up @@ -38,10 +96,10 @@ easier to detect actual security issues, should they arise in the future.
`TJ.PARAM_MAXMEMORY` in the TurboJPEG Java API) and a corresponding TJBench
option (`-maxmemory`) for specifying the maximum amount of memory (in
megabytes) that will be allocated for intermediate buffers, which are used with
progressive JPEG compression and decompression, optimized baseline entropy
coding, lossless JPEG compression, and lossless transformation. The new
parameter and option serve the same purpose as the `max_memory_to_use` field in
the `jpeg_memory_mgr` struct in the libjpeg API, the `JPEGMEM` environment
progressive JPEG compression and decompression, Huffman table optimization,
lossless JPEG compression, and lossless transformation. The new parameter and
option serve the same purpose as the `max_memory_to_use` field in the
`jpeg_memory_mgr` struct in the libjpeg API, the `JPEGMEM` environment
variable, and the cjpeg/djpeg/jpegtran `-maxmemory` option.

3. Introduced a new parameter (`TJPARAM_MAXPIXELS` in the TurboJPEG C API and
Expand All @@ -68,7 +126,7 @@ within the functions.

2. Fixed two minor issues in the interblock smoothing algorithm that caused
mathematical (but not necessarily perceptible) edge block errors when
decompressing progressive JPEG images exactly two MCU blocks in width or that
decompressing progressive JPEG images exactly two DCT blocks in width or that
use vertical chrominance subsampling.

3. Fixed a regression introduced by 3.0 beta2[6] that, in rare cases, caused
Expand Down Expand Up @@ -179,11 +237,10 @@ through pointer arguments.
- `TJFLAG_LIMITSCANS`/`TJ.FLAG_LIMITSCANS` has been reimplemented as an
API parameter (`TJPARAM_SCANLIMIT`/`TJ.PARAM_SCANLIMIT`) that allows the number
of scans to be specified.
- Optimized baseline entropy coding (the computation of optimal Huffman
tables, as opposed to using the default Huffman tables) can now be specified,
using a new API parameter (`TJPARAM_OPTIMIZE`/`TJ.PARAM_OPTIMIZE`), a new
transform option (`TJXOPT_OPTIMIZE`/`TJTransform.OPT_OPTIMIZE`), and a new
TJBench option (`-optimize`.)
- Huffman table optimization can now be specified using a new API
parameter (`TJPARAM_OPTIMIZE`/`TJ.PARAM_OPTIMIZE`), a new transform option
(`TJXOPT_OPTIMIZE`/`TJTransform.OPT_OPTIMIZE`), and a new TJBench option
(`-optimize`.)
- Arithmetic entropy coding can now be specified or queried, using a new
API parameter (`TJPARAM_ARITHMETIC`/`TJ.PARAM_ARITHMETIC`), a new transform
option (`TJXOPT_ARITHMETIC`/`TJTransform.OPT_ARITHMETIC`), and a new TJBench
Expand Down Expand Up @@ -426,9 +483,9 @@ prevented libjpeg-turbo from working properly with other linkers and also
represented a potential security risk.

2. Fixed an issue whereby the `tjTransform()` function incorrectly computed the
MCU block size for 4:4:4 JPEG images with non-unary sampling factors and thus
unduly rejected some cropping regions, even though those regions aligned with
8x8 MCU block boundaries.
iMCU size for 4:4:4 JPEG images with non-unary sampling factors and thus unduly
rejected some cropping regions, even though those regions aligned with 8x8 iMCU
boundaries.

3. Fixed a regression introduced by 2.1 beta1[13] that caused the build system
to enable the Arm Neon SIMD extensions when targetting Armv6 and other legacy
Expand Down Expand Up @@ -1010,16 +1067,15 @@ encounters a warning from the underlying libjpeg API (the default behavior is
to allow the operation to complete unless a fatal error is encountered.)

5. Introduced a new flag in the TurboJPEG C and Java APIs (`TJFLAG_PROGRESSIVE`
and `TJ.FLAG_PROGRESSIVE`, respectively) that causes the library to use
progressive entropy coding in JPEG images generated by compression and
transform operations. Additionally, a new transform option
(`TJXOPT_PROGRESSIVE` in the C API and `TJTransform.OPT_PROGRESSIVE` in the
Java API) has been introduced, allowing progressive entropy coding to be
enabled for selected transforms in a multi-transform operation.
and `TJ.FLAG_PROGRESSIVE`, respectively) that causes compression and transform
operations to generate progressive JPEG images. Additionally, a new transform
option (`TJXOPT_PROGRESSIVE` in the C API and `TJTransform.OPT_PROGRESSIVE` in
the Java API) has been introduced, allowing progressive JPEG images to be
generated by selected transforms in a multi-transform operation.

6. Introduced a new transform option in the TurboJPEG API (`TJXOPT_COPYNONE` in
the C API and `TJTransform.OPT_COPYNONE` in the Java API) that allows the
copying of markers (including EXIF and ICC profile data) to be disabled for a
copying of markers (including Exif and ICC profile data) to be disabled for a
particular transform.

7. Added two functions to the TurboJPEG C API (`tjLoadImage()` and
Expand Down Expand Up @@ -1150,13 +1206,13 @@ bug that has existed since the introduction of libjpeg v7/v8 API/ABI emulation
in libjpeg-turbo v1.1.

7. The lossless transform features in jpegtran and the TurboJPEG API will now
always attempt to adjust the EXIF image width and height tags if the image size
always attempt to adjust the Exif image width and height tags if the image size
changed as a result of the transform. This behavior has always existed when
using libjpeg v8 API/ABI emulation. It was supposed to be available with
libjpeg v7 API/ABI emulation as well but did not work properly due to a bug.
Furthermore, there was never any good reason not to enable it with libjpeg v6b
API/ABI emulation, since the behavior is entirely internal. Note that
`-copy all` must be passed to jpegtran in order to transfer the EXIF tags from
`-copy all` must be passed to jpegtran in order to transfer the Exif tags from
the source image to the destination image.

8. Fixed several memory leaks in the TurboJPEG API library that could occur
Expand All @@ -1178,7 +1234,7 @@ for two reasons: it allows testers to more easily work around the 2 GB limit
in libFuzzer, and it allows developers of security-sensitive applications to
more easily defend against one of the progressive JPEG exploits (LJT-01-004)
identified in
[this report](http://www.libjpeg-turbo.org/pmwiki/uploads/About/TwoIssueswiththeJPEGStandard.pdf).
[this report](https://libjpeg-turbo.org/pmwiki/uploads/About/TwoIssueswiththeJPEGStandard.pdf).

10. TJBench will now run each benchmark for 1 second prior to starting the
timer, in order to improve the consistency of the results. Furthermore, the
Expand Down
6 changes: 3 additions & 3 deletions src/3rdparty/libjpeg/src/README.ijg
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ The library is intended to be reused in other applications.
In order to support file conversion and viewing software, we have included
considerable functionality beyond the bare JPEG coding/decoding capability;
for example, the color quantization modules are not strictly part of JPEG
decoding, but they are essential for output to colormapped file formats or
colormapped displays. These extra functions can be compiled out of the
library if not required for a particular application.
decoding, but they are essential for output to colormapped file formats. These
extra functions can be compiled out of the library if not required for a
particular application.

We have also included "jpegtran", a utility for lossless transcoding between
different JPEG processes, and "rdjpgcom" and "wrjpgcom", two simple
Expand Down
5 changes: 3 additions & 2 deletions src/3rdparty/libjpeg/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ JPEG images:
top of the TurboJPEG API. The TurboJPEG API is recommended for first-time
users of libjpeg-turbo. Refer to [tjexample.c](tjexample.c) and
[TJExample.java](java/TJExample.java) for examples of its usage and to
<http://libjpeg-turbo.org/Documentation/Documentation> for API documentation.
<https://libjpeg-turbo.org/Documentation/Documentation> for API
documentation.

- **libjpeg API**<br>
This is the de facto industry-standard API for compressing and decompressing
Expand Down Expand Up @@ -199,7 +200,7 @@ supported and which aren't.
NOTE: As of this writing, extensive research has been conducted into the
usefulness of DCT scaling as a means of data reduction and SmartScale as a
means of quality improvement. Readers are invited to peruse the research at
<http://www.libjpeg-turbo.org/About/SmartScale> and draw their own conclusions,
<https://libjpeg-turbo.org/About/SmartScale> and draw their own conclusions,
but it is the general belief of our project that these features have not
demonstrated sufficient usefulness to justify inclusion in libjpeg-turbo.

Expand Down
6 changes: 3 additions & 3 deletions src/3rdparty/libjpeg/src/jcdctmgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* libjpeg-turbo Modifications:
* Copyright (C) 1999-2006, MIYASAKA Masaru.
* Copyright 2009 Pierre Ossman <[email protected]> for Cendio AB
* Copyright (C) 2011, 2014-2015, 2022, D. R. Commander.
* Copyright (C) 2011, 2014-2015, 2022, 2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
Expand Down Expand Up @@ -114,8 +114,8 @@ flss(UINT16 val)
* Compute values to do a division using reciprocal.
*
* This implementation is based on an algorithm described in
* "How to optimize for the Pentium family of microprocessors"
* (http://www.agner.org/assem/).
* "Optimizing subroutines in assembly language:
* An optimization guide for x86 platforms" (https://agner.org/optimize).
* More information about the basic algorithm can be found in
* the paper "Integer Division Using Reciprocals" by Robert Alverson.
*
Expand Down
4 changes: 4 additions & 0 deletions src/3rdparty/libjpeg/src/jchuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,10 @@ encode_one_block_simd(working_state *state, JCOEFPTR block, int last_dc_val,
JOCTET _buffer[BUFSIZE], *buffer;
int localbuf = 0;

#ifdef ZERO_BUFFERS
memset(_buffer, 0, sizeof(_buffer));
#endif

LOAD_BUFFER()

buffer = jsimd_huff_encode_one_block(state, buffer, block, last_dc_val,
Expand Down
31 changes: 17 additions & 14 deletions src/3rdparty/libjpeg/src/jcmaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -751,22 +751,25 @@ jinit_c_master_control(j_compress_ptr cinfo, boolean transcode_only)
/* Validate parameters, determine derived values */
initial_setup(cinfo, transcode_only);

if (cinfo->master->lossless || /* TEMPORARY HACK ??? */
(cinfo->progressive_mode && !cinfo->arith_code))
cinfo->optimize_coding = TRUE; /* assume default tables no good for
progressive mode or lossless mode */
for (i = 0; i < NUM_HUFF_TBLS; i++) {
if (cinfo->dc_huff_tbl_ptrs[i] != NULL ||
cinfo->ac_huff_tbl_ptrs[i] != NULL) {
empty_huff_tables = FALSE;
break;
if (cinfo->arith_code)
cinfo->optimize_coding = FALSE;
else {
if (cinfo->master->lossless || /* TEMPORARY HACK ??? */
cinfo->progressive_mode)
cinfo->optimize_coding = TRUE; /* assume default tables no good for
progressive mode or lossless mode */
for (i = 0; i < NUM_HUFF_TBLS; i++) {
if (cinfo->dc_huff_tbl_ptrs[i] != NULL ||
cinfo->ac_huff_tbl_ptrs[i] != NULL) {
empty_huff_tables = FALSE;
break;
}
}
if (cinfo->data_precision == 12 && !cinfo->optimize_coding &&
(empty_huff_tables || using_std_huff_tables(cinfo)))
cinfo->optimize_coding = TRUE; /* assume default tables no good for
12-bit data precision */
}
if (cinfo->data_precision == 12 && !cinfo->arith_code &&
!cinfo->optimize_coding &&
(empty_huff_tables || using_std_huff_tables(cinfo)))
cinfo->optimize_coding = TRUE; /* assume default tables no good for 12-bit
data precision */

/* Initialize my private state */
if (transcode_only) {
Expand Down
5 changes: 3 additions & 2 deletions src/3rdparty/libjpeg/src/jcomapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
*
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1997, Thomas G. Lane.
* It was modified by The libjpeg-turbo Project to include only code relevant
* to libjpeg-turbo.
* libjpeg-turbo Modifications:
* Copyright (C) 2024, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
Expand Down Expand Up @@ -51,6 +51,7 @@ jpeg_abort(j_common_ptr cinfo)
* A bit kludgy to do it here, but this is the most central place.
*/
((j_decompress_ptr)cinfo)->marker_list = NULL;
((j_decompress_ptr)cinfo)->master->marker_list_end = NULL;
} else {
cinfo->global_state = CSTATE_START;
}
Expand Down
2 changes: 1 addition & 1 deletion src/3rdparty/libjpeg/src/jcparam.c
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ jpeg_set_defaults(j_compress_ptr cinfo)
* tables will be computed. This test can be removed if default tables
* are supplied that are valid for the desired precision.
*/
if (cinfo->data_precision == 12 && !cinfo->arith_code)
if (cinfo->data_precision == 12)
cinfo->optimize_coding = TRUE;

/* By default, use the simpler non-cosited sampling alignment */
Expand Down
10 changes: 10 additions & 0 deletions src/3rdparty/libjpeg/src/jcphuff.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,11 @@ encode_mcu_AC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
size_t bits[8 / SIZEOF_SIZE_T];
int max_coef_bits = cinfo->data_precision + 2;

#ifdef ZERO_BUFFERS
memset(values_unaligned, 0, sizeof(values_unaligned));
memset(bits, 0, sizeof(bits));
#endif

entropy->next_output_byte = cinfo->dest->next_output_byte;
entropy->free_in_buffer = cinfo->dest->free_in_buffer;

Expand Down Expand Up @@ -915,6 +920,11 @@ encode_mcu_AC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
size_t zerobits, signbits;
size_t bits[16 / SIZEOF_SIZE_T];

#ifdef ZERO_BUFFERS
memset(absvalues_unaligned, 0, sizeof(absvalues_unaligned));
memset(bits, 0, sizeof(bits));
#endif

entropy->next_output_byte = cinfo->dest->next_output_byte;
entropy->free_in_buffer = cinfo->dest->free_in_buffer;

Expand Down
8 changes: 5 additions & 3 deletions src/3rdparty/libjpeg/src/jdapistd.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* This file was part of the Independent JPEG Group's software:
* Copyright (C) 1994-1996, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright (C) 2010, 2015-2020, 2022-2023, D. R. Commander.
* Copyright (C) 2010, 2015-2020, 2022-2024, D. R. Commander.
* Copyright (C) 2015, Google, Inc.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
Expand Down Expand Up @@ -200,7 +200,8 @@ _jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset,
ERREXIT(cinfo, JERR_BAD_CROP_SPEC);

/* xoffset and width must fall within the output image dimensions. */
if (*width == 0 || *xoffset + *width > cinfo->output_width)
if (*width == 0 ||
(unsigned long long)(*xoffset) + *width > cinfo->output_width)
ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);

/* No need to do anything if the caller wants the entire width. */
Expand Down Expand Up @@ -482,7 +483,8 @@ _jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines)
ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);

/* Do not skip past the bottom of the image. */
if (cinfo->output_scanline + num_lines >= cinfo->output_height) {
if ((unsigned long long)cinfo->output_scanline + num_lines >=
cinfo->output_height) {
num_lines = cinfo->output_height - cinfo->output_scanline;
cinfo->output_scanline = cinfo->output_height;
(*cinfo->inputctl->finish_input_pass) (cinfo);
Expand Down
Loading

0 comments on commit c1ee648

Please sign in to comment.