Skip to content

Commit

Permalink
Merge branch 'main' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
dcommander committed Mar 18, 2024
2 parents c8c5c2e + fe218ca commit cf357e8
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Expand Up @@ -149,7 +149,8 @@ jobs:
mkdir build
pushd build
cmake -G"Unix Makefiles" -DWITH_JPEG8=1 \
-DCMAKE_C_FLAGS='--std=gnu90 -Wall -Werror -Wextra -Wpedantic -pedantic-errors -Wdouble-promotion -Wformat-overflow=2 -Wformat-security -Wformat-signedness -Wformat-truncation=2 -Wformat-y2k -Wmissing-include-dirs -Wshift-overflow=2 -Wswitch-bool -Wno-unused-parameter -Wuninitialized -Wstrict-overflow=2 -Wstringop-overflow=4 -Wstringop-truncation -Wduplicated-branches -Wduplicated-cond -Wdeclaration-after-statement -Wshadow -Wunsafe-loop-optimizations -Wundef -Wcast-align -Wno-clobbered -Wjump-misses-init -Wno-sign-compare -Wlogical-op -Waggregate-return -Wstrict-prototypes -Wold-style-definition -Wmissing-prototypes -Wmissing-declarations -Wpacked -Wredundant-decls -Wnested-externs -Winline -Wno-long-long -Wdisabled-optimization -Wno-overlength-strings -fcf-protection' \
-DCMAKE_C_FLAGS='--std=gnu90 -Wall -Werror -Wextra -Wmost -Wnon-gcc -Wpedantic -pedantic-errors -Walloca -Wanon-enum-enum-conversion -Warray-bounds-pointer-arithmetic -Wbitfield-enum-conversion -Wc99-extensions -Wc2x-extensions -Wcast-function-type -Wcompound-token-split -Wdate-time -Wdeclaration-after-statement -Wdeprecated -Wdocumentation -Wdocumentation-pedantic -Wdouble-promotion -Wduplicate-decl-specifier -Wduplicate-enum -Wempty-init-stmt -Wexpansion-to-defined -Wextra-semi -Wformat=2 -Wformat-non-iso -Wno-format-nonliteral -Wformat-pedantic -Wformat-type-confusion -Wfour-char-constants -Wgcc-compat -Wgnu -Wheader-hygiene -Widiomatic-parentheses -Wignored-qualifiers -Wimplicit-fallthrough -Wno-implicit-int-conversion -Wincompatible-function-pointer-types -Wno-long-long -Wloop-analysis -Wmain -Wmax-tokens -Wmisleading-indentation -Wmissing-field-initializers -Wmissing-prototypes -Wmissing-variable-declarations -Wnewline-eof -Wnonportable-system-include-path -Wnullable-to-nonnull-conversion -Wold-style-cast -Wover-aligned -Wparentheses -Wpointer-arith -Wpragmas -Wpre-c2x-compat -Wredundant-parens -Wself-assign -Wshadow-all -Wshift-sign-overflow -Wno-shorten-64-to-32 -Wno-sign-conversion -Wsometimes-uninitialized -Wstatic-in-inline -Wstrict-prototypes -Wswitch-default -Wtautological-constant-in-range-compare -Wthread-safety -Wthread-safety-verbose -Wunaligned-access -Wundef -Wundef-prefix -Wundefined-func-template -Wuninitialized -Wunneeded-internal-declaration -Wunreachable-code-fallthrough -Wno-unused-command-line-argument -Wunused-member-function -Wno-unused-parameter -Wvariadic-macros -Wzero-as-null-pointer-constant -Wzero-length-array -fcf-protection' \
-DCMAKE_C_COMPILER=clang-14 \
..
export NUMCPUS=`grep -c '^processor' /proc/cpuinfo`
make -j$NUMCPUS --load-average=$NUMCPUS
Expand Down
14 changes: 7 additions & 7 deletions CMakeLists.txt
Expand Up @@ -423,7 +423,7 @@ if(MSVC)
add_definitions(-D_CRT_NONSTDC_NO_WARNINGS)
endif()

if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
# Use the maximum optimization level for release builds
foreach(var CMAKE_C_FLAGS_RELEASE CMAKE_C_FLAGS_RELWITHDEBINFO)
if(${var} MATCHES "-O2")
Expand Down Expand Up @@ -481,7 +481,7 @@ if(UNIX)
return 1; /* right shift is signed */
/* see if unsigned-shift hack will fix it. */
/* we can't just test exact value since it depends on width of long... */
res |= (~0L) << (32-4);
res |= 0xFFFFFFFFL << (32-4);
if (res == -0x7F7E80CL)
return 0; /* right shift is unsigned */
printf(\"Right shift isn't acting as I expect it to.\\\\n\");
Expand All @@ -494,7 +494,7 @@ if(UNIX)
endif()
endif()

if(NOT MSVC OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
if(NOT MSVC OR CMAKE_C_COMPILER_ID MATCHES "Clang")
check_c_source_compiles("extern const int table[1]; const int __attribute__((visibility(\"hidden\"))) table[1] = { 0 }; int main(void) { return table[0]; }"
HIDDEN_WORKS)
if(HIDDEN_WORKS)
Expand Down Expand Up @@ -940,7 +940,7 @@ if(CPU_TYPE STREQUAL "x86_64" OR CPU_TYPE STREQUAL "i386")
set(DEFAULT_FLOATTEST8 no-fp-contract)
endif()
elseif(CPU_TYPE STREQUAL "powerpc" OR CPU_TYPE STREQUAL "arm64")
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
if(CMAKE_C_COMPILER_VERSION VERSION_EQUAL 14.0.0 OR
CMAKE_C_COMPILER_VERSION VERSION_GREATER 14.0.0)
set(DEFAULT_FLOATTEST8 fp-contract)
Expand Down Expand Up @@ -982,7 +982,7 @@ endif()
if(CPU_TYPE STREQUAL "x86_64")
set(DEFAULT_FLOATTEST12 no-fp-contract)
elseif(CPU_TYPE STREQUAL "powerpc" OR CPU_TYPE STREQUAL "arm64")
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
if(CMAKE_C_COMPILER_VERSION VERSION_EQUAL 14.0.0 OR
CMAKE_C_COMPILER_VERSION VERSION_GREATER 14.0.0)
set(DEFAULT_FLOATTEST12 fp-contract)
Expand Down Expand Up @@ -1237,7 +1237,7 @@ foreach(libtype ${TEST_LIBTYPES})
set(MD5_PPM_3x2_FLOAT_NO_FP_CONTRACT ${MD5_PPM_3x2_FLOAT_SSE})
set(MD5_JPEG_3x2_FLOAT_PROG_FP_CONTRACT
${MD5_JPEG_3x2_FLOAT_PROG_NO_FP_CONTRACT})
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(MD5_PPM_3x2_FLOAT_FP_CONTRACT 2da9de6ae869e88b8372de815d366b03)
else()
set(MD5_PPM_3x2_FLOAT_FP_CONTRACT ${MD5_PPM_3x2_FLOAT_SSE})
Expand Down Expand Up @@ -1309,7 +1309,7 @@ foreach(libtype ${TEST_LIBTYPES})
set(MD5_PPM_3x2_FLOAT_NO_FP_CONTRACT f6bfab038438ed8f5522fbd33595dcdc)
set(MD5_JPEG_3x2_FLOAT_PROG_FP_CONTRACT
${MD5_JPEG_3x2_FLOAT_PROG_NO_FP_CONTRACT})
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
if(CMAKE_C_COMPILER_ID MATCHES "Clang")
set(MD5_PPM_3x2_FLOAT_FP_CONTRACT ${MD5_PPM_3x2_FLOAT_NO_FP_CONTRACT})
else()
set(MD5_PPM_3x2_FLOAT_FP_CONTRACT 0e917a34193ef976b679a6b069b1be26)
Expand Down
3 changes: 2 additions & 1 deletion src/cjpeg.c
Expand Up @@ -361,7 +361,8 @@ parse_switches(j_compress_ptr cinfo, int argc, char **argv,
if (!printed_version) {
fprintf(stderr, "%s version %s (build %s)\n",
PACKAGE_NAME, VERSION, BUILD);
fprintf(stderr, "%s\n\n", JCOPYRIGHT);
fprintf(stderr, JCOPYRIGHT1);
fprintf(stderr, JCOPYRIGHT2 "\n");
fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
JVERSION);
printed_version = TRUE;
Expand Down
3 changes: 2 additions & 1 deletion src/djpeg.c
Expand Up @@ -267,7 +267,8 @@ parse_switches(j_decompress_ptr cinfo, int argc, char **argv,
if (!printed_version) {
fprintf(stderr, "%s version %s (build %s)\n",
PACKAGE_NAME, VERSION, BUILD);
fprintf(stderr, "%s\n\n", JCOPYRIGHT);
fprintf(stderr, JCOPYRIGHT1);
fprintf(stderr, JCOPYRIGHT2 "\n");
fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
JVERSION);
printed_version = TRUE;
Expand Down
3 changes: 2 additions & 1 deletion src/jpegtran.c
Expand Up @@ -241,7 +241,8 @@ parse_switches(j_compress_ptr cinfo, int argc, char **argv,
if (!printed_version) {
fprintf(stderr, "%s version %s (build %s)\n",
PACKAGE_NAME, VERSION, BUILD);
fprintf(stderr, "%s\n\n", JCOPYRIGHT);
fprintf(stderr, JCOPYRIGHT1);
fprintf(stderr, JCOPYRIGHT2 "\n");
fprintf(stderr, "Emulating The Independent JPEG Group's software, version %s\n\n",
JVERSION);
printed_version = TRUE;
Expand Down
7 changes: 4 additions & 3 deletions src/jversion.h.in
Expand Up @@ -36,20 +36,21 @@
* their code
*/

#define JCOPYRIGHT \
#define JCOPYRIGHT1 \
"Copyright (C) 2009-2024 D. R. Commander\n" \
"Copyright (C) 2015, 2020 Google, Inc.\n" \
"Copyright (C) 2019-2020 Arm Limited\n" \
"Copyright (C) 2015-2016, 2018 Matthieu Darbois\n" \
"Copyright (C) 2011-2016 Siarhei Siamashka\n" \
"Copyright (C) 2015 Intel Corporation\n" \
"Copyright (C) 2015 Intel Corporation\n"
#define JCOPYRIGHT2 \
"Copyright (C) 2013-2014 Linaro Limited\n" \
"Copyright (C) 2013-2014 MIPS Technologies, Inc.\n" \
"Copyright (C) 2009, 2012 Pierre Ossman for Cendio AB\n" \
"Copyright (C) 2009-2011 Nokia Corporation and/or its subsidiary(-ies)\n" \
"Copyright (C) 1999-2006 MIYASAKA Masaru\n" \
"Copyright (C) 1999 Ken Murchison\n" \
"Copyright (C) 1991-2020 Thomas G. Lane, Guido Vollbeding"
"Copyright (C) 1991-2020 Thomas G. Lane, Guido Vollbeding\n"

#define JCOPYRIGHT_SHORT \
"Copyright (C) @COPYRIGHT_YEAR@ The libjpeg-turbo Project and many others"
5 changes: 3 additions & 2 deletions src/md5/md5hl.c
Expand Up @@ -6,7 +6,8 @@
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
* libjpeg-turbo Modifications:
* Copyright (C)2016, 2018-2019, 2022 D. R. Commander. All Rights Reserved.
* Copyright (C)2016, 2018-2019, 2022, 2024 D. R. Commander.
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -111,7 +112,7 @@ char *MD5FileChunk(const char *filename, char *buf, off_t ofs, off_t len)
n = len;
i = 0;
while (n > 0) {
if (n > sizeof(buffer))
if ((size_t)n > sizeof(buffer))
i = read(f, buffer, sizeof(buffer));
else
i = read(f, buffer, n);
Expand Down
7 changes: 7 additions & 0 deletions src/tjbench.c
Expand Up @@ -37,6 +37,9 @@
#include <math.h>
#include <errno.h>
#include <limits.h>
#if !defined(_MSC_VER) || _MSC_VER > 1600
#include <stdint.h>
#endif
#include <cdjpeg.h>
#include "./tjutil.h"
#include "./turbojpeg.h"
Expand Down Expand Up @@ -223,9 +226,11 @@ static int decomp(unsigned char **jpegBufs, size_t *jpegSizes, void *dstBuf,
pitch = scaledw * ps;

if (dstBuf == NULL) {
#if ULLONG_MAX > SIZE_MAX
if ((unsigned long long)pitch * (unsigned long long)scaledh *
(unsigned long long)sampleSize > (unsigned long long)((size_t)-1))
THROW("allocating destination buffer", "Image is too large");
#endif
if ((dstBuf = malloc((size_t)pitch * scaledh * sampleSize)) == NULL)
THROW_UNIX("allocating destination buffer");
dstBufAlloc = 1;
Expand Down Expand Up @@ -382,9 +387,11 @@ static int fullTest(tjhandle handle, void *srcBuf, int w, int h, int subsamp,
int ntilesw = 1, ntilesh = 1, pitch = w * ps;
const char *pfStr = pixFormatStr[pf];

#if ULLONG_MAX > SIZE_MAX
if ((unsigned long long)pitch * (unsigned long long)h *
(unsigned long long)sampleSize > (unsigned long long)((size_t)-1))
THROW("allocating temporary image buffer", "Image is too large");
#endif
if ((tmpBuf = malloc((size_t)pitch * h * sampleSize)) == NULL)
THROW_UNIX("allocating temporary image buffer");

Expand Down
6 changes: 6 additions & 0 deletions src/tjexample.c
Expand Up @@ -40,6 +40,10 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#if !defined(_MSC_VER) || _MSC_VER > 1600
#include <stdint.h>
#endif
#include <turbojpeg.h>


Expand Down Expand Up @@ -335,9 +339,11 @@ int main(int argc, char **argv)
outSubsamp = inSubsamp;

pixelFormat = TJPF_BGRX;
#if ULLONG_MAX > SIZE_MAX
if ((unsigned long long)width * height * tjPixelSize[pixelFormat] >
(unsigned long long)((size_t)-1))
THROW("allocating uncompressed image buffer", "Image is too large");
#endif
if ((imgBuf =
(unsigned char *)malloc(sizeof(unsigned char) * width * height *
tjPixelSize[pixelFormat])) == NULL)
Expand Down
10 changes: 7 additions & 3 deletions src/turbojpeg-mp.c
@@ -1,5 +1,5 @@
/*
* Copyright (C)2009-2023 D. R. Commander. All Rights Reserved.
* Copyright (C)2009-2024 D. R. Commander. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -180,7 +180,8 @@ DLLEXPORT int GET_NAME(tj3Decompress, BITS_IN_JSAMPLE)
}
setDecompParameters(this);
if (this->maxPixels &&
(unsigned long long)this->jpegWidth * this->jpegHeight > this->maxPixels)
(unsigned long long)this->jpegWidth * this->jpegHeight >
(unsigned long long)this->maxPixels)
THROW("Image is too large");
this->dinfo.out_color_space = pf2cs[pixelFormat];
#if BITS_IN_JSAMPLE != 16
Expand Down Expand Up @@ -366,8 +367,11 @@ DLLEXPORT _JSAMPLE *GET_NAME(tj3LoadImage, BITS_IN_JSAMPLE)
*pixelFormat = cs2pf[cinfo->in_color_space];

pitch = PAD((*width) * tjPixelSize[*pixelFormat], align);
if ((unsigned long long)pitch * (unsigned long long)(*height) >
if (
#if ULLONG_MAX > SIZE_MAX
(unsigned long long)pitch * (unsigned long long)(*height) >
(unsigned long long)((size_t)-1) ||
#endif
(dstBuf = (_JSAMPLE *)malloc(pitch * (*height) *
sizeof(_JSAMPLE))) == NULL)
THROW("Memory allocation failure");
Expand Down
16 changes: 14 additions & 2 deletions src/turbojpeg.c
Expand Up @@ -32,6 +32,9 @@

#include <ctype.h>
#include <limits.h>
#if !defined(_MSC_VER) || _MSC_VER > 1600
#include <stdint.h>
#endif
#include <jinclude.h>
#define JPEG_INTERNALS
#include <jpeglib.h>
Expand Down Expand Up @@ -946,8 +949,10 @@ DLLEXPORT size_t tj3JPEGBufSize(int width, int height, int jpegSubsamp)
mcuh = tjMCUHeight[jpegSubsamp];
chromasf = jpegSubsamp == TJSAMP_GRAY ? 0 : 4 * 64 / (mcuw * mcuh);
retval = PAD(width, mcuw) * PAD(height, mcuh) * (2ULL + chromasf) + 2048ULL;
#if ULLONG_MAX > ULONG_MAX
if (retval > (unsigned long long)((unsigned long)-1))
THROWG("Image is too large", 0);
#endif

bailout:
return (size_t)retval;
Expand Down Expand Up @@ -981,8 +986,10 @@ DLLEXPORT unsigned long TJBUFSIZE(int width, int height)
larger than the uncompressed input (we wouldn't mention it if it hadn't
happened before.) */
retval = PAD(width, 16) * PAD(height, 16) * 6ULL + 2048ULL;
#if ULLONG_MAX > ULONG_MAX
if (retval > (unsigned long long)((unsigned long)-1))
THROWG("Image is too large", (unsigned long)-1);
#endif

bailout:
return (unsigned long)retval;
Expand All @@ -1008,8 +1015,10 @@ DLLEXPORT size_t tj3YUVBufSize(int width, int align, int height, int subsamp)
if (pw == 0 || ph == 0) return 0;
else retval += (unsigned long long)stride * ph;
}
#if ULLONG_MAX > ULONG_MAX
if (retval > (unsigned long long)((unsigned long)-1))
THROWG("Image is too large", 0);
#endif

bailout:
return (size_t)retval;
Expand Down Expand Up @@ -1123,8 +1132,10 @@ DLLEXPORT size_t tj3YUVPlaneSize(int componentID, int width, int stride,
else stride = abs(stride);

retval = (unsigned long long)stride * (ph - 1) + pw;
#if ULLONG_MAX > ULONG_MAX
if (retval > (unsigned long long)((unsigned long)-1))
THROWG("Image is too large", 0);
#endif

bailout:
return (size_t)retval;
Expand Down Expand Up @@ -2350,7 +2361,8 @@ DLLEXPORT int tj3DecompressToYUVPlanes8(tjhandle handle,
}
setDecompParameters(this);
if (this->maxPixels &&
(unsigned long long)this->jpegWidth * this->jpegHeight > this->maxPixels)
(unsigned long long)this->jpegWidth * this->jpegHeight >
(unsigned long long)this->maxPixels)
THROW("Image is too large");
if (this->subsamp == TJSAMP_UNKNOWN)
THROW("Could not determine subsampling level of JPEG image");
Expand Down Expand Up @@ -2719,7 +2731,7 @@ DLLEXPORT int tj3Transform(tjhandle handle, const unsigned char *jpegBuf,
jpeg_read_header(dinfo, TRUE);
if (this->maxPixels &&
(unsigned long long)dinfo->image_width * dinfo->image_height >
this->maxPixels)
(unsigned long long)this->maxPixels)
THROW("Image is too large");
this->subsamp = getSubsamp(&this->dinfo);

Expand Down

0 comments on commit cf357e8

Please sign in to comment.