Skip to content

Commit b3e7390

Browse files
committed
Merge libjpeg-turbo 2.0.5
* 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
2 parents 6d95c51 + ae87a95 commit b3e7390

File tree

11 files changed

+174
-73
lines changed

11 files changed

+174
-73
lines changed

CMakeLists.txt

Lines changed: 55 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if(CMAKE_EXECUTABLE_SUFFIX)
55
endif()
66

77
project(mozjpeg C)
8-
set(VERSION 4.0.0)
8+
set(VERSION 4.0.1)
99
string(REPLACE "." ";" VERSION_TRIPLET ${VERSION})
1010
list(GET VERSION_TRIPLET 0 VERSION_MAJOR)
1111
list(GET VERSION_TRIPLET 1 VERSION_MINOR)
@@ -453,6 +453,21 @@ if(NOT INLINE_WORKS)
453453
endif()
454454
message(STATUS "INLINE = ${INLINE} (FORCE_INLINE = ${FORCE_INLINE})")
455455

456+
if(WITH_TURBOJPEG)
457+
if(MSVC)
458+
set(THREAD_LOCAL "__declspec(thread)")
459+
else()
460+
set(THREAD_LOCAL "__thread")
461+
endif()
462+
check_c_source_compiles("${THREAD_LOCAL} int i; int main(void) { i = 0; return i; }" HAVE_THREAD_LOCAL)
463+
if(HAVE_THREAD_LOCAL)
464+
message(STATUS "THREAD_LOCAL = ${THREAD_LOCAL}")
465+
else()
466+
message(WARNING "Thread-local storage is not available. The TurboJPEG API library's global error handler will not be thread-safe.")
467+
unset(THREAD_LOCAL)
468+
endif()
469+
endif()
470+
456471
if(UNIX AND NOT APPLE)
457472
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/conftest.map "VERS_1 { global: *; };")
458473
set(CMAKE_REQUIRED_FLAGS
@@ -923,12 +938,18 @@ foreach(libtype ${TEST_LIBTYPES})
923938
set(suffix -static)
924939
endif()
925940
if(WITH_TURBOJPEG)
926-
add_test(tjunittest-${libtype} tjunittest${suffix})
927-
add_test(tjunittest-${libtype}-alloc tjunittest${suffix} -alloc)
928-
add_test(tjunittest-${libtype}-yuv tjunittest${suffix} -yuv)
929-
add_test(tjunittest-${libtype}-yuv-alloc tjunittest${suffix} -yuv -alloc)
930-
add_test(tjunittest-${libtype}-yuv-nopad tjunittest${suffix} -yuv -noyuvpad)
931-
add_test(tjunittest-${libtype}-bmp tjunittest${suffix} -bmp)
941+
add_test(tjunittest-${libtype}
942+
${CMAKE_CROSSCOMPILING_EMULATOR} tjunittest${suffix})
943+
add_test(tjunittest-${libtype}-alloc
944+
${CMAKE_CROSSCOMPILING_EMULATOR} tjunittest${suffix} -alloc)
945+
add_test(tjunittest-${libtype}-yuv
946+
${CMAKE_CROSSCOMPILING_EMULATOR} tjunittest${suffix} -yuv)
947+
add_test(tjunittest-${libtype}-yuv-alloc
948+
${CMAKE_CROSSCOMPILING_EMULATOR} tjunittest${suffix} -yuv -alloc)
949+
add_test(tjunittest-${libtype}-yuv-nopad
950+
${CMAKE_CROSSCOMPILING_EMULATOR} tjunittest${suffix} -yuv -noyuvpad)
951+
add_test(tjunittest-${libtype}-bmp
952+
${CMAKE_CROSSCOMPILING_EMULATOR} tjunittest${suffix} -bmp)
932953

933954
set(MD5_PPM_GRAY_TILE 89d3ca21213d9d864b50b4e4e7de4ca6)
934955
set(MD5_PPM_420_8x8_TILE 847fceab15c5b7b911cb986cf0f71de3)
@@ -953,22 +974,23 @@ foreach(libtype ${TEST_LIBTYPES})
953974
${CMAKE_COMMAND} -E copy_if_different ${TESTIMAGES}/testorig.ppm
954975
testout_tile.ppm)
955976
add_test(tjbench-${libtype}-tile
956-
tjbench${suffix} testout_tile.ppm 95 -rgb -quiet -tile -benchtime 0.01
957-
-warmup 0)
977+
${CMAKE_CROSSCOMPILING_EMULATOR} tjbench${suffix} testout_tile.ppm 95
978+
-rgb -quiet -tile -benchtime 0.01 -warmup 0)
958979
set_tests_properties(tjbench-${libtype}-tile
959980
PROPERTIES DEPENDS tjbench-${libtype}-tile-cp)
960981

961982
foreach(tile 8 16 32 64 128)
962983
add_test(tjbench-${libtype}-tile-gray-${tile}x${tile}-cmp
963-
${MD5CMP} ${MD5_PPM_GRAY_TILE}
984+
${CMAKE_CROSSCOMPILING_EMULATOR} ${MD5CMP} ${MD5_PPM_GRAY_TILE}
964985
testout_tile_GRAY_Q95_${tile}x${tile}.ppm)
965986
foreach(subsamp 420 422)
966987
add_test(tjbench-${libtype}-tile-${subsamp}-${tile}x${tile}-cmp
967-
${MD5CMP} ${MD5_PPM_${subsamp}_${tile}x${tile}_TILE}
988+
${CMAKE_CROSSCOMPILING_EMULATOR} ${MD5CMP}
989+
${MD5_PPM_${subsamp}_${tile}x${tile}_TILE}
968990
testout_tile_${subsamp}_Q95_${tile}x${tile}.ppm)
969991
endforeach()
970992
add_test(tjbench-${libtype}-tile-444-${tile}x${tile}-cmp
971-
${MD5CMP} ${MD5_PPM_444_TILE}
993+
${CMAKE_CROSSCOMPILING_EMULATOR} ${MD5CMP} ${MD5_PPM_444_TILE}
972994
testout_tile_444_Q95_${tile}x${tile}.ppm)
973995
foreach(subsamp gray 420 422 444)
974996
set_tests_properties(tjbench-${libtype}-tile-${subsamp}-${tile}x${tile}-cmp
@@ -980,19 +1002,22 @@ foreach(libtype ${TEST_LIBTYPES})
9801002
${CMAKE_COMMAND} -E copy_if_different ${TESTIMAGES}/testorig.ppm
9811003
testout_tilem.ppm)
9821004
add_test(tjbench-${libtype}-tilem
983-
tjbench${suffix} testout_tilem.ppm 95 -rgb -fastupsample -quiet -tile
984-
-benchtime 0.01 -warmup 0)
1005+
${CMAKE_CROSSCOMPILING_EMULATOR} tjbench${suffix} testout_tilem.ppm 95
1006+
-rgb -fastupsample -quiet -tile -benchtime 0.01 -warmup 0)
9851007
set_tests_properties(tjbench-${libtype}-tilem
9861008
PROPERTIES DEPENDS tjbench-${libtype}-tilem-cp)
9871009

9881010
add_test(tjbench-${libtype}-tile-420m-8x8-cmp
989-
${MD5CMP} ${MD5_PPM_420M_8x8_TILE} testout_tilem_420_Q95_8x8.ppm)
1011+
${CMAKE_CROSSCOMPILING_EMULATOR} ${MD5CMP} ${MD5_PPM_420M_8x8_TILE}
1012+
testout_tilem_420_Q95_8x8.ppm)
9901013
add_test(tjbench-${libtype}-tile-422m-8x8-cmp
991-
${MD5CMP} ${MD5_PPM_422M_8x8_TILE} testout_tilem_422_Q95_8x8.ppm)
1014+
${CMAKE_CROSSCOMPILING_EMULATOR} ${MD5CMP} ${MD5_PPM_422M_8x8_TILE}
1015+
testout_tilem_422_Q95_8x8.ppm)
9921016
foreach(tile 16 32 64 128)
9931017
foreach(subsamp 420 422)
9941018
add_test(tjbench-${libtype}-tile-${subsamp}m-${tile}x${tile}-cmp
995-
${MD5CMP} ${MD5_PPM_${subsamp}M_TILE}
1019+
${CMAKE_CROSSCOMPILING_EMULATOR} ${MD5CMP}
1020+
${MD5_PPM_${subsamp}M_TILE}
9961021
testout_tilem_${subsamp}_Q95_${tile}x${tile}.ppm)
9971022
endforeach()
9981023
endforeach()
@@ -1010,9 +1035,10 @@ foreach(libtype ${TEST_LIBTYPES})
10101035

10111036
macro(add_bittest PROG NAME ARGS OUTFILE INFILE MD5SUM)
10121037
add_test(${PROG}-${libtype}-${NAME}
1013-
${PROG}${suffix} ${ARGS} -outfile ${OUTFILE} ${INFILE})
1038+
${CMAKE_CROSSCOMPILING_EMULATOR} ${PROG}${suffix} ${ARGS}
1039+
-outfile ${OUTFILE} ${INFILE})
10141040
add_test(${PROG}-${libtype}-${NAME}-cmp
1015-
${MD5CMP} ${MD5SUM} ${OUTFILE})
1041+
${CMAKE_CROSSCOMPILING_EMULATOR} ${MD5CMP} ${MD5SUM} ${OUTFILE})
10161042
set_tests_properties(${PROG}-${libtype}-${NAME}-cmp PROPERTIES
10171043
DEPENDS ${PROG}-${libtype}-${NAME})
10181044
if(${ARGC} GREATER 6)
@@ -1033,12 +1059,14 @@ foreach(libtype ${TEST_LIBTYPES})
10331059
${MD5_PPM_RGB_ISLOW} cjpeg-${libtype}-rgb-islow)
10341060

10351061
add_test(djpeg-${libtype}-rgb-islow-icc-cmp
1036-
${MD5CMP} b06a39d730129122e85c1363ed1bbc9e testout_rgb_islow.icc)
1062+
${CMAKE_CROSSCOMPILING_EMULATOR} ${MD5CMP}
1063+
b06a39d730129122e85c1363ed1bbc9e testout_rgb_islow.icc)
10371064
set_tests_properties(djpeg-${libtype}-rgb-islow-icc-cmp PROPERTIES
10381065
DEPENDS djpeg-${libtype}-rgb-islow)
10391066

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

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

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

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

12771305
# Context rows: No Intra-iMCU row: No ENT: prog huff
12781306
add_test(cjpeg-${libtype}-444-islow-prog
1279-
cjpeg${suffix} -dct int -prog -sample 1x1
1307+
${CMAKE_CROSSCOMPILING_EMULATOR} cjpeg${suffix} -dct int -prog -sample 1x1
12801308
-outfile testout_444_islow_prog.jpg ${TESTIMAGES}/testorig.ppm)
12811309
add_bittest(djpeg 444-islow-prog-crop98x98_13_13
12821310
"-dct;int;-crop;98x98+13+13;-ppm"
@@ -1286,8 +1314,9 @@ foreach(libtype ${TEST_LIBTYPES})
12861314
# Context rows: No Intra-iMCU row: No ENT: arith
12871315
if(WITH_ARITH_ENC)
12881316
add_test(cjpeg-${libtype}-444-islow-ari
1289-
cjpeg${suffix} -dct int -arithmetic -sample 1x1
1290-
-outfile testout_444_islow_ari.jpg ${TESTIMAGES}/testorig.ppm)
1317+
${CMAKE_CROSSCOMPILING_EMULATOR} cjpeg${suffix} -dct int -arithmetic
1318+
-sample 1x1 -outfile testout_444_islow_ari.jpg
1319+
${TESTIMAGES}/testorig.ppm)
12911320
if(WITH_ARITH_DEC)
12921321
add_bittest(djpeg 444-islow-ari-crop37x37_0_0
12931322
"-dct;int;-crop;37x37+0+0;-ppm"

ChangeLog.md

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
2.0.5
2+
=====
3+
4+
### Significant changes relative to 2.0.4:
5+
6+
1. Worked around issues in the MIPS DSPr2 SIMD extensions that caused failures
7+
in the libjpeg-turbo regression tests. Specifically, the
8+
`jsimd_h2v1_downsample_dspr2()` and `jsimd_h2v2_downsample_dspr2()` functions
9+
in the MIPS DSPr2 SIMD extensions are now disabled until/unless they can be
10+
fixed, and other functions that are incompatible with big endian MIPS CPUs are
11+
disabled when building libjpeg-turbo for such CPUs.
12+
13+
2. Fixed an oversight in the `TJCompressor.compress(int)` method in the
14+
TurboJPEG Java API that caused an error ("java.lang.IllegalStateException: No
15+
source image is associated with this instance") when attempting to use that
16+
method to compress a YUV image.
17+
18+
3. Fixed an issue (CVE-2020-13790) in the PPM reader that caused a buffer
19+
overrun in cjpeg, TJBench, or the `tjLoadImage()` function if one of the values
20+
in a binary PPM/PGM input file exceeded the maximum value defined in the file's
21+
header and that maximum value was less than 255. libjpeg-turbo 1.5.0 already
22+
included a similar fix for binary PPM/PGM files with maximum values greater
23+
than 255.
24+
25+
4. The TurboJPEG API library's global error handler, which is used in functions
26+
such as `tjBufSize()` and `tjLoadImage()` that do not require a TurboJPEG
27+
instance handle, is now thread-safe on platforms that support thread-local
28+
storage.
29+
30+
131
2.0.4
232
=====
333

@@ -562,10 +592,10 @@ application was linked against.
562592

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

570600
4. Fixed an issue whereby attempting to decompress a JPEG file with a corrupt
571601
header using the `tjDecompressToYUV2()` function would cause the function to

doc/html/group___turbo_j_p_e_g.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,7 @@ <h2 class="groupheader">Function Documentation</h2>
21292129
<p>Returns a descriptive error message explaining why the last command failed. </p>
21302130
<dl class="params"><dt>Parameters</dt><dd>
21312131
<table class="params">
2132-
<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>
2132+
<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>
21332133
</table>
21342134
</dd>
21352135
</dl>

java/org/libjpegturbo/turbojpeg/TJCompressor.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C)2011-2015, 2018 D. R. Commander. All Rights Reserved.
2+
* Copyright (C)2011-2015, 2018, 2020 D. R. Commander. All Rights Reserved.
33
* Copyright (C)2015 Viktor Szathmáry. All Rights Reserved.
44
*
55
* Redistribution and use in source and binary forms, with or without
@@ -377,8 +377,15 @@ else if (srcBuf != null) {
377377
* #getCompressedSize} to obtain the size of the JPEG image.
378378
*/
379379
public byte[] compress(int flags) throws TJException {
380-
checkSourceImage();
381-
byte[] buf = new byte[TJ.bufSize(srcWidth, srcHeight, subsamp)];
380+
byte[] buf;
381+
if (srcYUVImage != null) {
382+
buf = new byte[TJ.bufSize(srcYUVImage.getWidth(),
383+
srcYUVImage.getHeight(),
384+
srcYUVImage.getSubsamp())];
385+
} else {
386+
checkSourceImage();
387+
buf = new byte[TJ.bufSize(srcWidth, srcHeight, subsamp)];
388+
}
382389
compress(buf, flags);
383390
return buf;
384391
}

jconfigint.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
/* How to obtain function inlining. */
88
#define INLINE @INLINE@
99

10+
/* How to obtain thread-local storage */
11+
#define THREAD_LOCAL @THREAD_LOCAL@
12+
1013
/* Define to the full name of this package. */
1114
#define PACKAGE_NAME "@CMAKE_PROJECT_NAME@"
1215

0 commit comments

Comments
 (0)