Skip to content

Commit

Permalink
Update to libjpeg-turbo-2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
hfhchan committed Nov 13, 2021
1 parent 0e8b5fd commit 1ad889e
Show file tree
Hide file tree
Showing 374 changed files with 309 additions and 54 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ Since AWT is not supported on Android, only a subset of the TurboJPEG API can be
`.aar` binaries for integrating libjpeg-turbo directly into your app are available on the [releases](https://github.com/hfhchan/libjpeg-turbo-android-sample/releases) page.

## Installation
1. Unzip the file `libjpeg-turbo-2.1.0-***-release.aar.zip`.
1. Unzip the file `libjpeg-turbo-2.1.1-***-release.aar.zip`.
2. Place the `.aar` file into the `app/libs` folder.
3. Add the following snippet to the `dependencies` section of `app/build.gradle`:
`implementation files('libs/libjpeg-turbo-2.1.0-***-release.aar.zip')`
`implementation files('libs/libjpeg-turbo-2.1.1-***-release.aar.zip')`

# Licenses
This sample is licensed under the MIT License.

libjpeg-turbo is covered by three compatible BSD-style open source licenses. Please see the license text for libjpeg-turbo [here](libjpeg-turbo/src/main/cpp/libjpeg-turbo-2.1.0/LICENSE.md).
libjpeg-turbo is covered by three compatible BSD-style open source licenses. Please see the license text for libjpeg-turbo [here](libjpeg-turbo/src/main/cpp/libjpeg-turbo-2.1.1/LICENSE.md).

Sample image Bird Shore Animal licensed under the CC0 license from https://negativespace.co/bird-shore-animal/.
2 changes: 1 addition & 1 deletion libjpeg-turbo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ android {

externalNativeBuild {
cmake {
path file("src/main/cpp/libjpeg-turbo-2.1.0/CMakeLists.txt")
path file("src/main/cpp/libjpeg-turbo-2.1.1/CMakeLists.txt")
version '3.10.2'
}
}
Expand Down
6 changes: 3 additions & 3 deletions libjpeg-turbo/src/main/cpp/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
libjpeg-turbo-2.1.0/testimages
libjpeg-turbo-2.1.0/java/doc
libjpeg-turbo-2.1.0/doc
libjpeg-turbo-2.1.1/testimages
libjpeg-turbo-2.1.1/java/doc
libjpeg-turbo-2.1.1/doc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if(CMAKE_EXECUTABLE_SUFFIX)
endif()

project(libjpeg-turbo C)
set(VERSION 2.1.0)
set(VERSION 2.1.1)
string(REPLACE "." ";" VERSION_TRIPLET ${VERSION})
list(GET VERSION_TRIPLET 0 VERSION_MAJOR)
list(GET VERSION_TRIPLET 1 VERSION_MINOR)
Expand All @@ -25,6 +25,15 @@ pad_number(VERSION_MINOR 3)
pad_number(VERSION_REVISION 3)
set(LIBJPEG_TURBO_VERSION_NUMBER ${VERSION_MAJOR}${VERSION_MINOR}${VERSION_REVISION})

# CMake 3.14 and later sets CMAKE_MACOSX_BUNDLE to TRUE by default when
# CMAKE_SYSTEM_NAME is iOS, tvOS, or watchOS, which breaks the libjpeg-turbo
# build. (Specifically, when CMAKE_MACOSX_BUNDLE is TRUE, executables for
# Apple platforms are built as application bundles, which causes CMake to
# complain that our install() directives for executables do not specify a
# BUNDLE DESTINATION. Even if CMake did not complain, building executables as
# application bundles would break our iOS packages.)
set(CMAKE_MACOSX_BUNDLE FALSE)

string(TIMESTAMP DEFAULT_BUILD "%Y%m%d")
set(BUILD ${DEFAULT_BUILD} CACHE STRING "Build string (default: ${DEFAULT_BUILD})")

Expand Down Expand Up @@ -582,6 +591,9 @@ if(WITH_SIMD)
endif()
else()
add_library(simd OBJECT jsimd_none.c)
if(NOT WIN32 AND (CMAKE_POSITION_INDEPENDENT_CODE OR ENABLE_SHARED))
set_target_properties(simd PROPERTIES POSITION_INDEPENDENT_CODE 1)
endif()
endif()

if(WITH_JAVA)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
2.1.1
=====

### 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.

2. Fixed a regression introduced by 2.1 beta1[13] that prevented the Arm 32-bit
(AArch32) Neon SIMD extensions from building unless the C compiler flags
included `-mfloat-abi=softfp` or `-mfloat-abi=hard`.

3. Fixed an issue in the AArch32 Neon SIMD Huffman encoder whereby reliance on
undefined C compiler behavior led to crashes ("SIGBUS: illegal alignment") on
Android systems when running AArch32/Thumb builds of libjpeg-turbo built with
recent versions of Clang.

4. Added a command-line argument (`-copy icc`) to jpegtran that causes it to
copy only the ICC profile markers from the source file and discard any other
metadata.

5. libjpeg-turbo should now build and run on CHERI-enabled architectures, which
use capability pointers that are larger than the size of `size_t`.

6. Fixed a regression introduced by 2.1 beta1[5] that caused a segfault in the
64-bit SSE2 Huffman encoder when attempting to losslessly transform a
specially-crafted malformed JPEG image.


2.1.0
=====

Expand Down Expand Up @@ -284,15 +313,15 @@ JPEG images. This was known to cause a buffer overflow when attempting to
decompress some such images using `tjDecompressToYUV2()` or
`tjDecompressToYUVPlanes()`.

5. Fixed an issue, detected by ASan, whereby attempting to losslessly transform
a specially-crafted malformed JPEG image containing an extremely-high-frequency
coefficient block (junk image data that could never be generated by a
legitimate JPEG compressor) could cause the Huffman encoder's local buffer to
be overrun. (Refer to 1.4.0[9] and 1.4beta1[15].) Given that the buffer
overrun was fully contained within the stack and did not cause a segfault or
other user-visible errant behavior, and given that the lossless transformer
(unlike the decompressor) is not generally exposed to arbitrary data exploits,
this issue did not likely pose a security risk.
5. Fixed an issue (CVE-2020-17541), detected by ASan, whereby attempting to
losslessly transform a specially-crafted malformed JPEG image containing an
extremely-high-frequency coefficient block (junk image data that could never be
generated by a legitimate JPEG compressor) could cause the Huffman encoder's
local buffer to be overrun. (Refer to 1.4.0[9] and 1.4beta1[15].) Given that
the buffer overrun was fully contained within the stack and did not cause a
segfault or other user-visible errant behavior, and given that the lossless
transformer (unlike the decompressor) is not generally exposed to arbitrary
data exploits, this issue did not likely pose a security risk.

6. The Arm 64-bit (Armv8) Neon SIMD assembly code now stores constants in a
separate read-only data section rather than in the text section, to support
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ elseif(CPU_TYPE STREQUAL "arm64")
elseif(CPU_TYPE STREQUAL "arm")
check_c_source_compiles("
#if __ARM_PCS_VFP != 1
#error \"float ABI = softfp\"
#error \"float ABI != hard\"
#endif
int main(void) { return 0; }" HAVE_HARD_FLOAT)
if(HAVE_HARD_FLOAT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@
* flags (this defines __thumb__).
*/

#if defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) || \
defined(_M_ARM64)
/* NOTE: Both GCC and Clang define __GNUC__ */
#if (defined(__GNUC__) && (defined(__arm__) || defined(__aarch64__))) || \
defined(_M_ARM) || defined(_M_ARM64)
#if !defined(__thumb__) || defined(__thumb2__)
#define USE_CLZ_INTRINSIC
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ prepare_for_pass(j_compress_ptr cinfo)
master->pass_type = output_pass;
master->pass_number++;
#endif
/*FALLTHROUGH*/
FALLTHROUGH /*FALLTHROUGH*/
case output_pass:
/* Do a data-output pass. */
/* We need not repeat per-scan setup if prior optimization pass did it. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,13 @@
#define HAVE_BITSCANFORWARD
#endif
#endif

#if defined(__has_attribute)
#if __has_attribute(fallthrough)
#define FALLTHROUGH __attribute__((fallthrough));
#else
#define FALLTHROUGH
#endif
#else
#define FALLTHROUGH
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Copyright (C) 2011, 2015, 2018, 2021, D. R. Commander.
* Copyright (C) 2016, 2018, Matthieu Darbois.
* Copyright (C) 2020, Arm Limited.
* Copyright (C) 2021, Alex Richardson.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
Expand Down Expand Up @@ -52,8 +53,9 @@
* flags (this defines __thumb__).
*/

#if defined(__arm__) || defined(__aarch64__) || defined(_M_ARM) || \
defined(_M_ARM64)
/* NOTE: Both GCC and Clang define __GNUC__ */
#if (defined(__GNUC__) && (defined(__arm__) || defined(__aarch64__))) || \
defined(_M_ARM) || defined(_M_ARM64)
#if !defined(__thumb__) || defined(__thumb2__)
#define USE_CLZ_INTRINSIC
#endif
Expand Down Expand Up @@ -679,7 +681,7 @@ encode_mcu_AC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
emit_restart(entropy, entropy->next_restart_num);

#ifdef WITH_SIMD
cvalue = values = (JCOEF *)PAD((size_t)values_unaligned, 16);
cvalue = values = (JCOEF *)PAD((JUINTPTR)values_unaligned, 16);
#else
/* Not using SIMD, so alignment is not needed */
cvalue = values = values_unaligned;
Expand Down Expand Up @@ -944,7 +946,7 @@ encode_mcu_AC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
emit_restart(entropy, entropy->next_restart_num);

#ifdef WITH_SIMD
cabsvalue = absvalues = (JCOEF *)PAD((size_t)absvalues_unaligned, 16);
cabsvalue = absvalues = (JCOEF *)PAD((JUINTPTR)absvalues_unaligned, 16);
#else
/* Not using SIMD, so alignment is not needed */
cabsvalue = absvalues = absvalues_unaligned;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "jinclude.h"
#include "jpeglib.h"
#include "jdmaster.h"
#include "jconfigint.h"


/*
Expand Down Expand Up @@ -308,7 +309,7 @@ jpeg_consume_input(j_decompress_ptr cinfo)
/* Initialize application's data source module */
(*cinfo->src->init_source) (cinfo);
cinfo->global_state = DSTATE_INHEADER;
/*FALLTHROUGH*/
FALLTHROUGH /*FALLTHROUGH*/
case DSTATE_INHEADER:
retcode = (*cinfo->inputctl->consume_input) (cinfo);
if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ decode_mcu_slow(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
* behavior is, to the best of our understanding, innocuous, and it is
* unclear how to work around it without potentially affecting
* performance. Thus, we (hopefully temporarily) suppress UBSan integer
* overflow errors for this function.
* overflow errors for this function and decode_mcu_fast().
*/
s += state.last_dc_val[ci];
state.last_dc_val[ci] = s;
Expand Down Expand Up @@ -651,6 +651,12 @@ decode_mcu_slow(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
}


#if defined(__has_feature)
#if __has_feature(undefined_behavior_sanitizer)
__attribute__((no_sanitize("signed-integer-overflow"),
no_sanitize("unsigned-integer-overflow")))
#endif
#endif
LOCAL(boolean)
decode_mcu_fast(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
{
Expand Down Expand Up @@ -681,6 +687,9 @@ decode_mcu_fast(j_decompress_ptr cinfo, JBLOCKROW *MCU_data)

if (entropy->dc_needed[blkn]) {
int ci = cinfo->MCU_membership[blkn];
/* Refer to the comment in decode_mcu_slow() regarding the supression of
* a UBSan integer overflow error in this line of code.
*/
s += state.last_dc_val[ci];
state.last_dc_val[ci] = s;
if (block)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "jinclude.h"
#include "jdmainct.h"
#include "jconfigint.h"


/*
Expand Down Expand Up @@ -360,7 +361,7 @@ process_data_context_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
main_ptr->context_state = CTX_PREPARE_FOR_IMCU;
if (*out_row_ctr >= out_rows_avail)
return; /* Postprocessor exactly filled output buf */
/*FALLTHROUGH*/
FALLTHROUGH /*FALLTHROUGH*/
case CTX_PREPARE_FOR_IMCU:
/* Prepare to process first M-1 row groups of this iMCU row */
main_ptr->rowgroup_ctr = 0;
Expand All @@ -371,7 +372,7 @@ process_data_context_main(j_decompress_ptr cinfo, JSAMPARRAY output_buf,
if (main_ptr->iMCU_row_ctr == cinfo->total_iMCU_rows)
set_bottom_pointers(cinfo);
main_ptr->context_state = CTX_PROCESS_IMCU;
/*FALLTHROUGH*/
FALLTHROUGH /*FALLTHROUGH*/
case CTX_PROCESS_IMCU:
/* Call postprocessor using previously set pointers */
(*cinfo->post->post_process_data) (cinfo,
Expand Down
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-1997, Thomas G. Lane.
* libjpeg-turbo Modifications:
* Copyright (C) 2016, D. R. Commander.
* Copyright (C) 2016, 2021, D. R. Commander.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
Expand Down Expand Up @@ -1032,7 +1032,7 @@ free_pool(j_common_ptr cinfo, int pool_id)
large_pool_ptr next_lhdr_ptr = lhdr_ptr->next;
space_freed = lhdr_ptr->bytes_used +
lhdr_ptr->bytes_left +
sizeof(large_pool_hdr);
sizeof(large_pool_hdr) + ALIGN_SIZE - 1;
jpeg_free_large(cinfo, (void *)lhdr_ptr, space_freed);
mem->total_space_allocated -= space_freed;
lhdr_ptr = next_lhdr_ptr;
Expand All @@ -1045,7 +1045,7 @@ free_pool(j_common_ptr cinfo, int pool_id)
while (shdr_ptr != NULL) {
small_pool_ptr next_shdr_ptr = shdr_ptr->next;
space_freed = shdr_ptr->bytes_used + shdr_ptr->bytes_left +
sizeof(small_pool_hdr);
sizeof(small_pool_hdr) + ALIGN_SIZE - 1;
jpeg_free_small(cinfo, (void *)shdr_ptr, space_freed);
mem->total_space_allocated -= space_freed;
shdr_ptr = next_shdr_ptr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
* Copyright (C) 1991-1997, Thomas G. Lane.
* Modified 1997-2009 by Guido Vollbeding.
* libjpeg-turbo Modifications:
* Copyright (C) 2015-2016, 2019, D. R. Commander.
* Copyright (C) 2015-2016, 2019, 2021, D. R. Commander.
* Copyright (C) 2015, Google, Inc.
* Copyright (C) 2021, Alex Richardson.
* For conditions of distribution and use, see the accompanying README.ijg
* file.
*
Expand Down Expand Up @@ -47,6 +48,18 @@ typedef enum { /* Operating modes for buffer controllers */
/* JLONG must hold at least signed 32-bit values. */
typedef long JLONG;

/* JUINTPTR must hold pointer values. */
#ifdef __UINTPTR_TYPE__
/*
* __UINTPTR_TYPE__ is GNU-specific and available in GCC 4.6+ and Clang 3.0+.
* Fortunately, that is sufficient to support the few architectures for which
* sizeof(void *) != sizeof(size_t). The only other options would require C99
* or Clang-specific builtins.
*/
typedef __UINTPTR_TYPE__ JUINTPTR;
#else
typedef size_t JUINTPTR;
#endif

/*
* Left shift macro that handles a negative operand without causing any
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.TH JPEGTRAN 1 "26 October 2020"
.TH JPEGTRAN 1 "13 July 2021"
.SH NAME
jpegtran \- lossless transformation of JPEG files
.SH SYNOPSIS
Expand Down Expand Up @@ -247,6 +247,10 @@ comments and other metadata in the source file.
Copy only comment markers. This setting copies comments from the source file
but discards any other metadata.
.TP
.B \-copy icc
Copy only ICC profile markers. This setting copies the ICC profile from the
source file but discards any other metadata.
.TP
.B \-copy all
Copy all extra markers. This setting preserves miscellaneous markers
found in the source file, such as JFIF thumbnails, Exif data, and Photoshop
Expand All @@ -261,7 +265,7 @@ Additional switches recognized by jpegtran are:
.BI \-icc " file"
Embed ICC color management profile contained in the specified file. Note that
this will cause \fBjpegtran\fR to ignore any APP2 markers in the input file,
even if \fB-copy all\fR is specified.
even if \fB-copy all\fR or \fB-copy icc\fR is specified.
.TP
.BI \-maxmemory " N"
Set limit for amount of memory to use in processing large images. Value is
Expand Down
Loading

0 comments on commit 1ad889e

Please sign in to comment.