Skip to content

Commit

Permalink
Update libjpeg-turbo from Chromium 114.0.5735.358
Browse files Browse the repository at this point in the history
Issue: 326748668
Reviewed-on: #3169
  • Loading branch information
dahlstrom-g authored May 8, 2024
2 parents a87dc14 + 1a9a82b commit 16073f4
Show file tree
Hide file tree
Showing 45 changed files with 1,190 additions and 911 deletions.
18 changes: 4 additions & 14 deletions third_party/libjpeg_turbo/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
# Do not use the targets in this file unless you need a certain libjpeg
# implementation. Use the meta target //third_party:jpeg instead.

import("//build/config/features.gni")
import("//build/config/sanitizers/sanitizers.gni")
if (current_cpu == "arm" || current_cpu == "arm64") {
import("//build/config/arm.gni")
}

assert(!is_ios, "This is not used on iOS, don't drag it in unintentionally")

source_set("libjpeg_headers") {
sources = [
"jconfig.h",
Expand All @@ -29,7 +28,7 @@ source_set("libjpeg_headers") {
}
}

if (nasm_exists && (current_cpu == "x86" || current_cpu == "x64")) {
if (current_cpu == "x86" || current_cpu == "x64") {
if (is_starboard) {
import("//starboard/build/nasm_assemble.gni")
} else {
Expand Down Expand Up @@ -162,10 +161,10 @@ static_library("simd") {
defines = []
}

if (current_cpu == "x86" && nasm_exists) {
if (current_cpu == "x86") {
deps += [ ":simd_asm" ]
sources = [ "simd/i386/jsimd.c" ]
} else if (current_cpu == "x64" && nasm_exists) {
} else if (current_cpu == "x64") {
deps += [ ":simd_asm" ]
sources = [ "simd/x86_64/jsimd.c" ]
} else if ((current_cpu == "arm" || current_cpu == "arm64") && arm_use_neon) {
Expand Down Expand Up @@ -200,9 +199,7 @@ static_library("simd") {

defines += [ "NEON_INTRINSICS" ]

if (!is_starboard) {
configs -= [ "//build/config/compiler:default_optimization" ]
}
configs += [ "//build/config/compiler:optimize_speed" ]

if (is_starboard && sb_is_modular && current_cpu == "arm") {
Expand Down Expand Up @@ -306,13 +303,6 @@ static_library("libjpeg") {
defines -= [ "NO_PUTENV" ]
}

if (is_clang_16) {
cflags_c = [
# jerror.c a function definition without a prototype
"-Wno-deprecated-non-prototype",
]
}

configs += [ ":libjpeg_config" ]

public_configs = [ ":libjpeg_config" ]
Expand Down
18 changes: 15 additions & 3 deletions third_party/libjpeg_turbo/BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Build Requirements
variable or the `ASM_NASM` environment variable. On Windows, use forward
slashes rather than backslashes in the path (for example,
**c:/nasm/nasm.exe**).
* NASM and Yasm are located in the CRB (Code Ready Builder) repository on
Red Hat Enterprise Linux 8 and in the PowerTools repository on RHEL
derivatives, which is not enabled by default.
* NASM and Yasm are located in the CRB (Code Ready Builder) or PowerTools
repository on Red Hat Enterprise Linux 8+ and derivatives, which is not
enabled by default.

### Un*x Platforms (including Linux, Mac, FreeBSD, Solaris, and Cygwin)

Expand Down Expand Up @@ -372,9 +372,13 @@ located (usually **/usr/bin**.) Next, execute the following commands:

cd {build_directory}
cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
-DCMAKE_INSTALL_PREFIX={install_path} \
[additional CMake flags] {source_directory}
make

*{install\_path}* is the path under which the libjpeg-turbo binaries should be
installed.


### 64-bit MinGW Build on Un*x (including Mac and Cygwin)

Expand All @@ -391,9 +395,13 @@ located (usually **/usr/bin**.) Next, execute the following commands:

cd {build_directory}
cmake -G"Unix Makefiles" -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake \
-DCMAKE_INSTALL_PREFIX={install_path} \
[additional CMake flags] {source_directory}
make

*{install\_path}* is the path under which the libjpeg-turbo binaries should be
installed.


Building libjpeg-turbo for iOS
------------------------------
Expand Down Expand Up @@ -429,6 +437,10 @@ iPhone 5S/iPad Mini 2/iPad Air and newer.
[additional CMake flags] {source_directory}
make

Replace `iPhoneOS` with `iPhoneSimulator` and `-miphoneos-version-min` with
`-miphonesimulator-version-min` to build libjpeg-turbo for the iOS simulator on
Macs with Apple silicon CPUs.


Building libjpeg-turbo for Android
----------------------------------
Expand Down
104 changes: 90 additions & 14 deletions third_party/libjpeg_turbo/ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,83 @@
2.1.5.1
=======

### Significant changes relative to 2.1.5:

1. The SIMD dispatchers in libjpeg-turbo 2.1.4 and prior stored the list of
supported SIMD instruction sets in a global variable, which caused an innocuous
race condition whereby the variable could have been initialized multiple times
if `jpeg_start_*compress()` was called simultaneously in multiple threads.
libjpeg-turbo 2.1.5 included an undocumented attempt to fix this race condition
by making the SIMD support variable thread-local. However, that caused another
issue whereby, if `jpeg_start_*compress()` was called in one thread and
`jpeg_read_*()` or `jpeg_write_*()` was called in a second thread, the SIMD
support variable was never initialized in the second thread. On x86 systems,
this led the second thread to incorrectly assume that AVX2 instructions were
always available, and when it attempted to use those instructions on older x86
CPUs that do not support them, an illegal instruction error occurred. The SIMD
dispatchers now ensure that the SIMD support variable is initialized before
dispatching based on its value.


2.1.5
=====

### Significant changes relative to 2.1.4:

1. Fixed issues in the build system whereby, when using the Ninja Multi-Config
CMake generator, a static build of libjpeg-turbo (a build in which
`ENABLE_SHARED` is `0`) could not be installed, a Windows installer could not
be built, and the Java regression tests failed.

2. Fixed a regression introduced by 2.0 beta1[15] that caused a buffer overrun
in the progressive Huffman encoder when attempting to transform a
specially-crafted malformed 12-bit-per-component JPEG image into a progressive
12-bit-per-component JPEG image using a 12-bit-per-component build of
libjpeg-turbo (`-DWITH_12BIT=1`.) Given that the buffer overrun was fully
contained within the progressive Huffman encoder structure and did not cause a
segfault or other user-visible errant behavior, given that the lossless
transformer (unlike the decompressor) is not generally exposed to arbitrary
data exploits, and given that 12-bit-per-component builds of libjpeg-turbo are
uncommon, this issue did not likely pose a security risk.

3. Fixed an issue whereby, when using a 12-bit-per-component build of
libjpeg-turbo (`-DWITH_12BIT=1`), passing samples with values greater than 4095
or less than 0 to `jpeg_write_scanlines()` caused a buffer overrun or underrun
in the RGB-to-YCbCr color converter.

4. Fixed a floating point exception that occurred when attempting to use the
jpegtran `-drop` and `-trim` options to losslessly transform a
specially-crafted malformed JPEG image.

5. Fixed an issue in `tjBufSizeYUV2()` whereby it returned a bogus result,
rather than throwing an error, if the `align` parameter was not a power of 2.
Fixed a similar issue in `tjCompressFromYUV()` whereby it generated a corrupt
JPEG image in certain cases, rather than throwing an error, if the `align`
parameter was not a power of 2.

6. Fixed an issue whereby `tjDecompressToYUV2()`, which is a wrapper for
`tjDecompressToYUVPlanes()`, used the desired YUV image dimensions rather than
the actual scaled image dimensions when computing the plane pointers and
strides to pass to `tjDecompressToYUVPlanes()`. This caused a buffer overrun
and subsequent segfault if the desired image dimensions exceeded the scaled
image dimensions.

7. Fixed an issue whereby, when decompressing a 12-bit-per-component JPEG image
(`-DWITH_12BIT=1`) using an alpha-enabled output color space such as
`JCS_EXT_RGBA`, the alpha channel was set to 255 rather than 4095.

8. Fixed an issue whereby the Java version of TJBench did not accept a range of
quality values.

9. Fixed an issue whereby, when `-progressive` was passed to TJBench, the JPEG
input image was not transformed into a progressive JPEG image prior to
decompression.


2.1.4
=====

### Significant changes relative to 2.1.3
### Significant changes relative to 2.1.3:

1. Fixed a regression introduced in 2.1.3 that caused build failures with
Visual Studio 2010.
Expand Down Expand Up @@ -36,7 +112,7 @@ virtual array access") under certain circumstances.
2.1.3
=====

### Significant changes relative to 2.1.2
### Significant changes relative to 2.1.2:

1. Fixed a regression introduced by 2.0 beta1[7] whereby cjpeg compressed PGM
input files into full-color JPEG images unless the `-grayscale` option was
Expand All @@ -60,7 +136,7 @@ be reproduced using the libjpeg API, not using djpeg.
2.1.2
=====

### Significant changes relative to 2.1.1
### Significant changes relative to 2.1.1:

1. Fixed a regression introduced by 2.1 beta1[13] that caused the remaining
GAS implementations of AArch64 (Arm 64-bit) Neon SIMD functions (which are used
Expand Down Expand Up @@ -92,7 +168,7 @@ image contains incomplete or corrupt image data.
2.1.1
=====

### Significant changes relative to 2.1.0
### Significant changes relative to 2.1.0:

1. Fixed a regression introduced in 2.1.0 that caused build failures with
non-GCC-compatible compilers for Un*x/Arm platforms.
Expand Down Expand Up @@ -121,7 +197,7 @@ transform a specially-crafted malformed JPEG image.
2.1.0
=====

### Significant changes relative to 2.1 beta1
### Significant changes relative to 2.1 beta1:

1. Fixed a regression introduced by 2.1 beta1[6(b)] whereby attempting to
decompress certain progressive JPEG images with one or more component planes of
Expand Down Expand Up @@ -156,10 +232,10 @@ progressive JPEG format described in the report
["Two Issues with the JPEG Standard"](https://libjpeg-turbo.org/pmwiki/uploads/About/TwoIssueswiththeJPEGStandard.pdf).

7. The PPM reader now throws an error, rather than segfaulting (due to a buffer
overrun) or generating incorrect pixels, if an application attempts to use the
`tjLoadImage()` function to load a 16-bit binary PPM file (a binary PPM file
with a maximum value greater than 255) into a grayscale image buffer or to load
a 16-bit binary PGM file into an RGB image buffer.
overrun, CVE-2021-46822) or generating incorrect pixels, if an application
attempts to use the `tjLoadImage()` function to load a 16-bit binary PPM file
(a binary PPM file with a maximum value greater than 255) into a grayscale
image buffer or to load a 16-bit binary PGM file into an RGB image buffer.

8. Fixed an issue in the PPM reader that caused incorrect pixels to be
generated when using the `tjLoadImage()` function to load a 16-bit binary PPM
Expand Down Expand Up @@ -325,11 +401,11 @@ methods in the TurboJPEG Java API.

2. Fixed or worked around multiple issues with `jpeg_skip_scanlines()`:

- Fixed segfaults or "Corrupt JPEG data: premature end of data segment"
errors in `jpeg_skip_scanlines()` that occurred when decompressing 4:2:2 or
4:2:0 JPEG images using merged (non-fancy) upsampling/color conversion (that
is, when setting `cinfo.do_fancy_upsampling` to `FALSE`.) 2.0.0[6] was a
similar fix, but it did not cover all cases.
- Fixed segfaults (CVE-2020-35538) or "Corrupt JPEG data: premature end of
data segment" errors in `jpeg_skip_scanlines()` that occurred when
decompressing 4:2:2 or 4:2:0 JPEG images using merged (non-fancy)
upsampling/color conversion (that is, when setting `cinfo.do_fancy_upsampling`
to `FALSE`.) 2.0.0[6] was a similar fix, but it did not cover all cases.
- `jpeg_skip_scanlines()` now throws an error if two-pass color
quantization is enabled. Two-pass color quantization never worked properly
with `jpeg_skip_scanlines()`, and the issues could not readily be fixed.
Expand Down
2 changes: 1 addition & 1 deletion third_party/libjpeg_turbo/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ best of our understanding.
The Modified (3-clause) BSD License
===================================

Copyright (C)2009-2022 D. R. Commander. All Rights Reserved.<br>
Copyright (C)2009-2023 D. R. Commander. All Rights Reserved.<br>
Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
6 changes: 3 additions & 3 deletions third_party/libjpeg_turbo/METADATA
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ description:
third_party {
identifier {
type: "ChromiumVersion"
value: "108.0.5359.243" # from https://chromereleases.googleblog.com/2023/09/long-term-support-channel-update-for_18.html
value: "114.0.5735.358" # from https://chromereleases.googleblog.com/2024/03/long-term-support-channel-update-for_26.html
}
identifier {
type: "Git"
value: "https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git"
version: "ed683925e4897a84b3bffc5c1414c85b97a129a3"
# from https://chromium.googlesource.com/chromium/src/+/108.0.5359.243/DEPS#1507
version: "aa4075f116e4312537d0d3e9dbd5e31096539f94"
# from https://chromium.googlesource.com/chromium/src/+/114.0.5735.358/DEPS#1514
}
last_upgrade_date {
year: 2021
Expand Down
12 changes: 6 additions & 6 deletions third_party/libjpeg_turbo/README.chromium
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
Name: libjpeg-turbo
URL: https://github.com/libjpeg-turbo/libjpeg-turbo/
Version: 2.1.4
Version: 2.1.5.1
License: Custom license
License File: LICENSE.md
Security Critical: yes
License Android Compatible: yes

Description:
This consists of the components:
* libjpeg-turbo 2.1.4
* libjpeg-turbo 2.1.5.1
* This file (README.chromium)
* A build file (BUILD.gn)
* An OWNERS file
* A codereview.settings file
* A DIR_METADATA file
* Patched header files used by Chromium
* Deleted unused directories: cmakescripts, doc, fuzz, java, release,
* Deleted unused directories: .github, cmakescripts, doc, fuzz, java, release,
sharedlib, simd/mips, simd/mips64, simd/powerpc, and win
* Deleted unused files: appveyor.yml, CMakeLists.txt, cjpeg.1, croptest.in,
djpeg.1, doxygen.config, doxygen-extra.css, .gitattributes, jpegtran.1,
md5/CMakeLists.txt, md5/md5cmp.c, rdjpgcom.1, simd/CMakeLists.txt, strtest.c,
tjbenchtest.in, tjbenchtest.java.in, tjexample.c, tjexampletest.in,
djpeg.1, doxygen.config, doxygen-extra.css, example.txt, .gitattributes,
jpegtran.1, md5/CMakeLists.txt, md5/md5cmp.c, rdjpgcom.1, simd/CMakeLists.txt,
strtest.c, tjbenchtest.in, tjbenchtest.java.in, tjexample.c, tjexampletest.in,
tjexampletest.java.in and wrjpgcom.1
* Deleted legacy Arm Neon assembly files (supporting old compiler versions that
do not generate performant code from intrinsics):
Expand Down
1 change: 0 additions & 1 deletion third_party/libjpeg_turbo/cmyk.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include <jinclude.h>
#define JPEG_INTERNALS
#include <jpeglib.h>
#include "jconfigint.h"


/* Fully reversible */
Expand Down
2 changes: 2 additions & 0 deletions third_party/libjpeg_turbo/djpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,9 @@ parse_switches(j_decompress_ptr cinfo, int argc, char **argv,
if (++argn >= argc) /* advance to next argument */
usage();
icc_filename = argv[argn];
#ifdef SAVE_MARKERS_SUPPORTED
jpeg_save_markers(cinfo, JPEG_APP0 + 2, 0xFFFF);
#endif

} else if (keymatch(arg, "map", 3)) {
/* Quantize to a color map taken from an input file. */
Expand Down
14 changes: 7 additions & 7 deletions third_party/libjpeg_turbo/jccolext.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) 1991-1996, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright (C) 2009-2012, 2015, D. R. Commander.
* Copyright (C) 2009-2012, 2015, 2022, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
Expand Down Expand Up @@ -48,9 +48,9 @@ rgb_ycc_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
outptr2 = output_buf[2][output_row];
output_row++;
for (col = 0; col < num_cols; col++) {
r = inptr[RGB_RED];
g = inptr[RGB_GREEN];
b = inptr[RGB_BLUE];
r = RANGE_LIMIT(inptr[RGB_RED]);
g = RANGE_LIMIT(inptr[RGB_GREEN]);
b = RANGE_LIMIT(inptr[RGB_BLUE]);
inptr += RGB_PIXELSIZE;
/* If the inputs are 0..MAXJSAMPLE, the outputs of these equations
* must be too; we do not need an explicit range-limiting operation.
Expand Down Expand Up @@ -100,9 +100,9 @@ rgb_gray_convert_internal(j_compress_ptr cinfo, JSAMPARRAY input_buf,
outptr = output_buf[0][output_row];
output_row++;
for (col = 0; col < num_cols; col++) {
r = inptr[RGB_RED];
g = inptr[RGB_GREEN];
b = inptr[RGB_BLUE];
r = RANGE_LIMIT(inptr[RGB_RED]);
g = RANGE_LIMIT(inptr[RGB_GREEN]);
b = RANGE_LIMIT(inptr[RGB_BLUE]);
inptr += RGB_PIXELSIZE;
/* Y */
outptr[col] = (JSAMPLE)((ctab[r + R_Y_OFF] + ctab[g + G_Y_OFF] +
Expand Down
Loading

0 comments on commit 16073f4

Please sign in to comment.