Skip to content

Commit

Permalink
Merge libjpeg-turbo 2.0.5
Browse files Browse the repository at this point in the history
* tag '2.0.5':
  TurboJPEG: Make global error handling thread-safe
  ChangeLog.md: Add missing sub-header for 2.0.5
  ChangeLog.md: List CVE ID fixed by previous commit
  rdppm.c: Fix buf overrun caused by bad binary PPM
  Build: Add missing jpegtran-icc test dependency
  rdswitch.c: Eliminate spaces before semicolons
  TJCompressor.compress(int): Fix YUV-to-JPEG error
  Bump version to 2.0.5; Document previous commit
  MIPS DSPr2: Work around various 'make test' errors
  MIPS DSPr2: Fix compiler warning with -mdspr2
  MIPS SIMD: Always honor JSIMD_FORCE* env vars
  Test: Honor CMAKE_CROSSCOMPILING_EMULATOR variable
  • Loading branch information
kornelski committed Aug 15, 2020
2 parents 6d95c51 + ae87a95 commit b3e7390
Show file tree
Hide file tree
Showing 11 changed files with 174 additions and 73 deletions.
81 changes: 55 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if(CMAKE_EXECUTABLE_SUFFIX)
endif()

project(mozjpeg C)
set(VERSION 4.0.0)
set(VERSION 4.0.1)
string(REPLACE "." ";" VERSION_TRIPLET ${VERSION})
list(GET VERSION_TRIPLET 0 VERSION_MAJOR)
list(GET VERSION_TRIPLET 1 VERSION_MINOR)
Expand Down Expand Up @@ -453,6 +453,21 @@ if(NOT INLINE_WORKS)
endif()
message(STATUS "INLINE = ${INLINE} (FORCE_INLINE = ${FORCE_INLINE})")

if(WITH_TURBOJPEG)
if(MSVC)
set(THREAD_LOCAL "__declspec(thread)")
else()
set(THREAD_LOCAL "__thread")
endif()
check_c_source_compiles("${THREAD_LOCAL} int i; int main(void) { i = 0; return i; }" HAVE_THREAD_LOCAL)
if(HAVE_THREAD_LOCAL)
message(STATUS "THREAD_LOCAL = ${THREAD_LOCAL}")
else()
message(WARNING "Thread-local storage is not available. The TurboJPEG API library's global error handler will not be thread-safe.")
unset(THREAD_LOCAL)
endif()
endif()

if(UNIX AND NOT APPLE)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/conftest.map "VERS_1 { global: *; };")
set(CMAKE_REQUIRED_FLAGS
Expand Down Expand Up @@ -923,12 +938,18 @@ foreach(libtype ${TEST_LIBTYPES})
set(suffix -static)
endif()
if(WITH_TURBOJPEG)
add_test(tjunittest-${libtype} tjunittest${suffix})
add_test(tjunittest-${libtype}-alloc tjunittest${suffix} -alloc)
add_test(tjunittest-${libtype}-yuv tjunittest${suffix} -yuv)
add_test(tjunittest-${libtype}-yuv-alloc tjunittest${suffix} -yuv -alloc)
add_test(tjunittest-${libtype}-yuv-nopad tjunittest${suffix} -yuv -noyuvpad)
add_test(tjunittest-${libtype}-bmp tjunittest${suffix} -bmp)
add_test(tjunittest-${libtype}
${CMAKE_CROSSCOMPILING_EMULATOR} tjunittest${suffix})
add_test(tjunittest-${libtype}-alloc
${CMAKE_CROSSCOMPILING_EMULATOR} tjunittest${suffix} -alloc)
add_test(tjunittest-${libtype}-yuv
${CMAKE_CROSSCOMPILING_EMULATOR} tjunittest${suffix} -yuv)
add_test(tjunittest-${libtype}-yuv-alloc
${CMAKE_CROSSCOMPILING_EMULATOR} tjunittest${suffix} -yuv -alloc)
add_test(tjunittest-${libtype}-yuv-nopad
${CMAKE_CROSSCOMPILING_EMULATOR} tjunittest${suffix} -yuv -noyuvpad)
add_test(tjunittest-${libtype}-bmp
${CMAKE_CROSSCOMPILING_EMULATOR} tjunittest${suffix} -bmp)

set(MD5_PPM_GRAY_TILE 89d3ca21213d9d864b50b4e4e7de4ca6)
set(MD5_PPM_420_8x8_TILE 847fceab15c5b7b911cb986cf0f71de3)
Expand All @@ -953,22 +974,23 @@ foreach(libtype ${TEST_LIBTYPES})
${CMAKE_COMMAND} -E copy_if_different ${TESTIMAGES}/testorig.ppm
testout_tile.ppm)
add_test(tjbench-${libtype}-tile
tjbench${suffix} testout_tile.ppm 95 -rgb -quiet -tile -benchtime 0.01
-warmup 0)
${CMAKE_CROSSCOMPILING_EMULATOR} tjbench${suffix} testout_tile.ppm 95
-rgb -quiet -tile -benchtime 0.01 -warmup 0)
set_tests_properties(tjbench-${libtype}-tile
PROPERTIES DEPENDS tjbench-${libtype}-tile-cp)

foreach(tile 8 16 32 64 128)
add_test(tjbench-${libtype}-tile-gray-${tile}x${tile}-cmp
${MD5CMP} ${MD5_PPM_GRAY_TILE}
${CMAKE_CROSSCOMPILING_EMULATOR} ${MD5CMP} ${MD5_PPM_GRAY_TILE}
testout_tile_GRAY_Q95_${tile}x${tile}.ppm)
foreach(subsamp 420 422)
add_test(tjbench-${libtype}-tile-${subsamp}-${tile}x${tile}-cmp
${MD5CMP} ${MD5_PPM_${subsamp}_${tile}x${tile}_TILE}
${CMAKE_CROSSCOMPILING_EMULATOR} ${MD5CMP}
${MD5_PPM_${subsamp}_${tile}x${tile}_TILE}
testout_tile_${subsamp}_Q95_${tile}x${tile}.ppm)
endforeach()
add_test(tjbench-${libtype}-tile-444-${tile}x${tile}-cmp
${MD5CMP} ${MD5_PPM_444_TILE}
${CMAKE_CROSSCOMPILING_EMULATOR} ${MD5CMP} ${MD5_PPM_444_TILE}
testout_tile_444_Q95_${tile}x${tile}.ppm)
foreach(subsamp gray 420 422 444)
set_tests_properties(tjbench-${libtype}-tile-${subsamp}-${tile}x${tile}-cmp
Expand All @@ -980,19 +1002,22 @@ foreach(libtype ${TEST_LIBTYPES})
${CMAKE_COMMAND} -E copy_if_different ${TESTIMAGES}/testorig.ppm
testout_tilem.ppm)
add_test(tjbench-${libtype}-tilem
tjbench${suffix} testout_tilem.ppm 95 -rgb -fastupsample -quiet -tile
-benchtime 0.01 -warmup 0)
${CMAKE_CROSSCOMPILING_EMULATOR} tjbench${suffix} testout_tilem.ppm 95
-rgb -fastupsample -quiet -tile -benchtime 0.01 -warmup 0)
set_tests_properties(tjbench-${libtype}-tilem
PROPERTIES DEPENDS tjbench-${libtype}-tilem-cp)

add_test(tjbench-${libtype}-tile-420m-8x8-cmp
${MD5CMP} ${MD5_PPM_420M_8x8_TILE} testout_tilem_420_Q95_8x8.ppm)
${CMAKE_CROSSCOMPILING_EMULATOR} ${MD5CMP} ${MD5_PPM_420M_8x8_TILE}
testout_tilem_420_Q95_8x8.ppm)
add_test(tjbench-${libtype}-tile-422m-8x8-cmp
${MD5CMP} ${MD5_PPM_422M_8x8_TILE} testout_tilem_422_Q95_8x8.ppm)
${CMAKE_CROSSCOMPILING_EMULATOR} ${MD5CMP} ${MD5_PPM_422M_8x8_TILE}
testout_tilem_422_Q95_8x8.ppm)
foreach(tile 16 32 64 128)
foreach(subsamp 420 422)
add_test(tjbench-${libtype}-tile-${subsamp}m-${tile}x${tile}-cmp
${MD5CMP} ${MD5_PPM_${subsamp}M_TILE}
${CMAKE_CROSSCOMPILING_EMULATOR} ${MD5CMP}
${MD5_PPM_${subsamp}M_TILE}
testout_tilem_${subsamp}_Q95_${tile}x${tile}.ppm)
endforeach()
endforeach()
Expand All @@ -1010,9 +1035,10 @@ foreach(libtype ${TEST_LIBTYPES})

macro(add_bittest PROG NAME ARGS OUTFILE INFILE MD5SUM)
add_test(${PROG}-${libtype}-${NAME}
${PROG}${suffix} ${ARGS} -outfile ${OUTFILE} ${INFILE})
${CMAKE_CROSSCOMPILING_EMULATOR} ${PROG}${suffix} ${ARGS}
-outfile ${OUTFILE} ${INFILE})
add_test(${PROG}-${libtype}-${NAME}-cmp
${MD5CMP} ${MD5SUM} ${OUTFILE})
${CMAKE_CROSSCOMPILING_EMULATOR} ${MD5CMP} ${MD5SUM} ${OUTFILE})
set_tests_properties(${PROG}-${libtype}-${NAME}-cmp PROPERTIES
DEPENDS ${PROG}-${libtype}-${NAME})
if(${ARGC} GREATER 6)
Expand All @@ -1033,12 +1059,14 @@ foreach(libtype ${TEST_LIBTYPES})
${MD5_PPM_RGB_ISLOW} cjpeg-${libtype}-rgb-islow)

add_test(djpeg-${libtype}-rgb-islow-icc-cmp
${MD5CMP} b06a39d730129122e85c1363ed1bbc9e testout_rgb_islow.icc)
${CMAKE_CROSSCOMPILING_EMULATOR} ${MD5CMP}
b06a39d730129122e85c1363ed1bbc9e testout_rgb_islow.icc)
set_tests_properties(djpeg-${libtype}-rgb-islow-icc-cmp PROPERTIES
DEPENDS djpeg-${libtype}-rgb-islow)

add_bittest(jpegtran icc "-copy;all;-icc;${TESTIMAGES}/test2.icc"
testout_rgb_islow2.jpg testout_rgb_islow.jpg ${MD5_JPEG_RGB_ISLOW2})
testout_rgb_islow2.jpg testout_rgb_islow.jpg
${MD5_JPEG_RGB_ISLOW2} cjpeg-${libtype}-rgb-islow)

if(NOT WITH_12BIT)
# CC: RGB->RGB565 SAMP: fullsize IDCT: islow ENT: huff
Expand Down Expand Up @@ -1251,7 +1279,7 @@ foreach(libtype ${TEST_LIBTYPES})

# Context rows: Yes Intra-iMCU row: No iMCU row prefetch: No ENT: prog huff
add_test(cjpeg-${libtype}-420-islow-prog
cjpeg${suffix} -dct int -prog
${CMAKE_CROSSCOMPILING_EMULATOR} cjpeg${suffix} -dct int -prog
-outfile testout_420_islow_prog.jpg ${TESTIMAGES}/testorig.ppm)
add_bittest(djpeg 420-islow-prog-crop62x62_71_71
"-dct;int;-crop;62x62+71+71;-ppm"
Expand All @@ -1268,15 +1296,15 @@ foreach(libtype ${TEST_LIBTYPES})

# Context rows: No Intra-iMCU row: Yes ENT: huff
add_test(cjpeg-${libtype}-444-islow
cjpeg${suffix} -dct int -sample 1x1
${CMAKE_CROSSCOMPILING_EMULATOR} cjpeg${suffix} -dct int -sample 1x1
-outfile testout_444_islow.jpg ${TESTIMAGES}/testorig.ppm)
add_bittest(djpeg 444-islow-skip1_6 "-dct;int;-skip;1,6;-ppm"
testout_444_islow_skip1,6.ppm testout_444_islow.jpg
${MD5_PPM_444_ISLOW_SKIP1_6} cjpeg-${libtype}-444-islow)

# Context rows: No Intra-iMCU row: No ENT: prog huff
add_test(cjpeg-${libtype}-444-islow-prog
cjpeg${suffix} -dct int -prog -sample 1x1
${CMAKE_CROSSCOMPILING_EMULATOR} cjpeg${suffix} -dct int -prog -sample 1x1
-outfile testout_444_islow_prog.jpg ${TESTIMAGES}/testorig.ppm)
add_bittest(djpeg 444-islow-prog-crop98x98_13_13
"-dct;int;-crop;98x98+13+13;-ppm"
Expand All @@ -1286,8 +1314,9 @@ foreach(libtype ${TEST_LIBTYPES})
# Context rows: No Intra-iMCU row: No ENT: arith
if(WITH_ARITH_ENC)
add_test(cjpeg-${libtype}-444-islow-ari
cjpeg${suffix} -dct int -arithmetic -sample 1x1
-outfile testout_444_islow_ari.jpg ${TESTIMAGES}/testorig.ppm)
${CMAKE_CROSSCOMPILING_EMULATOR} cjpeg${suffix} -dct int -arithmetic
-sample 1x1 -outfile testout_444_islow_ari.jpg
${TESTIMAGES}/testorig.ppm)
if(WITH_ARITH_DEC)
add_bittest(djpeg 444-islow-ari-crop37x37_0_0
"-dct;int;-crop;37x37+0+0;-ppm"
Expand Down
38 changes: 34 additions & 4 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
2.0.5
=====

### Significant changes relative to 2.0.4:

1. Worked around issues in the MIPS DSPr2 SIMD extensions that caused failures
in the libjpeg-turbo regression tests. Specifically, the
`jsimd_h2v1_downsample_dspr2()` and `jsimd_h2v2_downsample_dspr2()` functions
in the MIPS DSPr2 SIMD extensions are now disabled until/unless they can be
fixed, and other functions that are incompatible with big endian MIPS CPUs are
disabled when building libjpeg-turbo for such CPUs.

2. Fixed an oversight in the `TJCompressor.compress(int)` method in the
TurboJPEG Java API that caused an error ("java.lang.IllegalStateException: No
source image is associated with this instance") when attempting to use that
method to compress a YUV image.

3. Fixed an issue (CVE-2020-13790) in the PPM reader that caused a buffer
overrun in cjpeg, TJBench, or the `tjLoadImage()` function if one of the values
in a binary PPM/PGM input file exceeded the maximum value defined in the file's
header and that maximum value was less than 255. libjpeg-turbo 1.5.0 already
included a similar fix for binary PPM/PGM files with maximum values greater
than 255.

4. The TurboJPEG API library's global error handler, which is used in functions
such as `tjBufSize()` and `tjLoadImage()` that do not require a TurboJPEG
instance handle, is now thread-safe on platforms that support thread-local
storage.


2.0.4
=====

Expand Down Expand Up @@ -562,10 +592,10 @@ application was linked against.

3. Fixed a couple of issues in the PPM reader that would cause buffer overruns
in cjpeg if one of the values in a binary PPM/PGM input file exceeded the
maximum value defined in the file's header. libjpeg-turbo 1.4.2 already
included a similar fix for ASCII PPM/PGM files. Note that these issues were
not security bugs, since they were confined to the cjpeg program and did not
affect any of the libjpeg-turbo libraries.
maximum value defined in the file's header and that maximum value was greater
than 255. libjpeg-turbo 1.4.2 already included a similar fix for ASCII PPM/PGM
files. Note that these issues were not security bugs, since they were confined
to the cjpeg program and did not affect any of the libjpeg-turbo libraries.

4. Fixed an issue whereby attempting to decompress a JPEG file with a corrupt
header using the `tjDecompressToYUV2()` function would cause the function to
Expand Down
2 changes: 1 addition & 1 deletion doc/html/group___turbo_j_p_e_g.html
Original file line number Diff line number Diff line change
Expand Up @@ -2129,7 +2129,7 @@ <h2 class="groupheader">Function Documentation</h2>
<p>Returns a descriptive error message explaining why the last command failed. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">handle</td><td>a handle to a TurboJPEG compressor, decompressor, or transformer instance, or NULL if the error was generated by a global function (but note that retrieving the error message for a global function is not thread-safe.)</td></tr>
<tr><td class="paramname">handle</td><td>a handle to a TurboJPEG compressor, decompressor, or transformer instance, or NULL if the error was generated by a global function (but note that retrieving the error message for a global function is thread-safe only on platforms that support thread-local storage.)</td></tr>
</table>
</dd>
</dl>
Expand Down
13 changes: 10 additions & 3 deletions java/org/libjpegturbo/turbojpeg/TJCompressor.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C)2011-2015, 2018 D. R. Commander. All Rights Reserved.
* Copyright (C)2011-2015, 2018, 2020 D. R. Commander. All Rights Reserved.
* Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -377,8 +377,15 @@ else if (srcBuf != null) {
* #getCompressedSize} to obtain the size of the JPEG image.
*/
public byte[] compress(int flags) throws TJException {
checkSourceImage();
byte[] buf = new byte[TJ.bufSize(srcWidth, srcHeight, subsamp)];
byte[] buf;
if (srcYUVImage != null) {
buf = new byte[TJ.bufSize(srcYUVImage.getWidth(),
srcYUVImage.getHeight(),
srcYUVImage.getSubsamp())];
} else {
checkSourceImage();
buf = new byte[TJ.bufSize(srcWidth, srcHeight, subsamp)];
}
compress(buf, flags);
return buf;
}
Expand Down
3 changes: 3 additions & 0 deletions jconfigint.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
/* How to obtain function inlining. */
#define INLINE @INLINE@

/* How to obtain thread-local storage */
#define THREAD_LOCAL @THREAD_LOCAL@

/* Define to the full name of this package. */
#define PACKAGE_NAME "@CMAKE_PROJECT_NAME@"

Expand Down
Loading

0 comments on commit b3e7390

Please sign in to comment.