From d2b98a11470d85c8afb360631541732e49b50bc2 Mon Sep 17 00:00:00 2001 From: Eirik Aavitsland Date: Mon, 16 Sep 2024 11:24:52 +0200 Subject: [PATCH] Update bundled libjpeg-turbo to version 3.0.4 [ChangeLog][Third-Party Code] libjpeg-turbo was updated to version 3.0.4 Pick-to: 6.8.0 6.7 6.7.3 6.5 6.2 5.15 Change-Id: Ifa437bfc9b99f386d792a045b0963f3690e322d9 Reviewed-by: Eskil Abrahamsen Blomfeldt (cherry picked from commit c1ee64834a04f03587d0a95d63365620951e072e) Reviewed-by: Qt Cherry-pick Bot --- src/3rdparty/libjpeg/qt_attribution.json | 4 +- src/3rdparty/libjpeg/src/ChangeLog.md | 102 ++++++++++++++++++----- src/3rdparty/libjpeg/src/README.ijg | 6 +- src/3rdparty/libjpeg/src/README.md | 5 +- src/3rdparty/libjpeg/src/jcdctmgr.c | 6 +- src/3rdparty/libjpeg/src/jchuff.c | 4 + src/3rdparty/libjpeg/src/jcmaster.c | 31 +++---- src/3rdparty/libjpeg/src/jcomapi.c | 5 +- src/3rdparty/libjpeg/src/jcparam.c | 2 +- src/3rdparty/libjpeg/src/jcphuff.c | 10 +++ src/3rdparty/libjpeg/src/jdapistd.c | 8 +- src/3rdparty/libjpeg/src/jdmarker.c | 18 ++-- src/3rdparty/libjpeg/src/jerror.c | 2 - src/3rdparty/libjpeg/src/jmemnobs.c | 6 +- src/3rdparty/libjpeg/src/jpegint.h | 11 ++- src/3rdparty/libjpeg/src/jpeglib.h | 21 +++-- src/3rdparty/libjpeg/src/jquant1.c | 32 +++---- 17 files changed, 182 insertions(+), 91 deletions(-) diff --git a/src/3rdparty/libjpeg/qt_attribution.json b/src/3rdparty/libjpeg/qt_attribution.json index ae2fa94e736..bff272dec99 100644 --- a/src/3rdparty/libjpeg/qt_attribution.json +++ b/src/3rdparty/libjpeg/qt_attribution.json @@ -7,8 +7,8 @@ "Description": "The Independent JPEG Group's JPEG software", "Homepage": "http://libjpeg-turbo.virtualgl.org/", - "Version": "3.0.3", - "DownloadLocation": "https://github.com/libjpeg-turbo/libjpeg-turbo/releases/download/3.0.3/libjpeg-turbo-3.0.3.tar.gz", + "Version": "3.0.4", + "DownloadLocation": "https://github.com/libjpeg-turbo/libjpeg-turbo/releases/download/3.0.4/libjpeg-turbo-3.0.4.tar.gz", "License": "Independent JPEG Group License and BSD 3-Clause \"New\" or \"Revised\" License", "LicenseId": "IJG AND BSD-3-Clause", diff --git a/src/3rdparty/libjpeg/src/ChangeLog.md b/src/3rdparty/libjpeg/src/ChangeLog.md index 8039c5536da..8b1ebd8a642 100644 --- a/src/3rdparty/libjpeg/src/ChangeLog.md +++ b/src/3rdparty/libjpeg/src/ChangeLog.md @@ -1,3 +1,61 @@ +3.0.4 +===== + +### Significant changes relative to 3.0.3: + +1. Fixed an issue whereby the CPU usage of the default marker processor in the +decompressor grew exponentially with the number of markers. This caused an +unreasonable slow-down in `jpeg_read_header()` if an application called +`jpeg_save_markers()` to save markers of a particular type and then attempted +to decompress a JPEG image containing an excessive number of markers of that +type. + +2. Hardened the default marker processor in the decompressor to guard against +an issue (exposed by 3.0 beta2[6]) whereby attempting to decompress a +specially-crafted malformed JPEG image (specifically an image with a complete +12-bit-per-sample Start Of Frame segment followed by an incomplete +8-bit-per-sample Start Of Frame segment) using buffered-image mode and input +prefetching caused a segfault if the `fill_input_buffer()` method in the +calling application's custom source manager incorrectly returned `FALSE` in +response to a prematurely-terminated JPEG data stream. + +3. Fixed an issue in cjpeg whereby, when generating a 12-bit-per-sample or +16-bit-per-sample lossless JPEG image, specifying a point transform value +greater than 7 resulted in an error ("Invalid progressive/lossless parameters") +unless the `-precision` option was specified before the `-lossless` option. + +4. Fixed a regression introduced by 3.0.3[3] that made it impossible for +calling applications to generate 12-bit-per-sample arithmetic-coded lossy JPEG +images using the TurboJPEG API. + +5. Fixed an error ("Destination buffer is not large enough") that occurred when +attempting to generate a full-color lossless JPEG image using the TurboJPEG +Java API's `byte[] TJCompressor.compress()` method if the value of +`TJ.PARAM_SUBSAMP` was not `TJ.SAMP_444`. + +6. Fixed a segfault in djpeg that occurred if a negative width was specified +with the `-crop` option. Since the cropping region width was read into an +unsigned 32-bit integer, a negative width was interpreted as a very large +value. With certain negative width and positive left boundary values, the +bounds checks in djpeg and `jpeg_crop_scanline()` overflowed and did not detect +the out-of-bounds width, which caused a buffer overrun in the upsampling or +color conversion routine. Both bounds checks now use 64-bit integers to guard +against overflow, and djpeg now checks for negative numbers when it parses the +crop specification from the command line. + +7. Fixed an issue whereby the TurboJPEG lossless transformation function and +methods checked the specified cropping region against the source image +dimensions and level of chrominance subsampling rather than the destination +image dimensions and level of chrominance subsampling, which caused some +cropping regions to be unduly rejected when performing 90-degree rotation, +270-degree rotation, transposition, transverse transposition, or grayscale +conversion. + +8. Fixed an issue whereby the TurboJPEG lossless transformation function and +methods did not honor `TJXOPT_COPYNONE`/`TJTransform.OPT_COPYNONE` unless it +was specified for all lossless transforms. + + 3.0.3 ===== @@ -38,10 +96,10 @@ easier to detect actual security issues, should they arise in the future. `TJ.PARAM_MAXMEMORY` in the TurboJPEG Java API) and a corresponding TJBench option (`-maxmemory`) for specifying the maximum amount of memory (in megabytes) that will be allocated for intermediate buffers, which are used with -progressive JPEG compression and decompression, optimized baseline entropy -coding, lossless JPEG compression, and lossless transformation. The new -parameter and option serve the same purpose as the `max_memory_to_use` field in -the `jpeg_memory_mgr` struct in the libjpeg API, the `JPEGMEM` environment +progressive JPEG compression and decompression, Huffman table optimization, +lossless JPEG compression, and lossless transformation. The new parameter and +option serve the same purpose as the `max_memory_to_use` field in the +`jpeg_memory_mgr` struct in the libjpeg API, the `JPEGMEM` environment variable, and the cjpeg/djpeg/jpegtran `-maxmemory` option. 3. Introduced a new parameter (`TJPARAM_MAXPIXELS` in the TurboJPEG C API and @@ -68,7 +126,7 @@ within the functions. 2. Fixed two minor issues in the interblock smoothing algorithm that caused mathematical (but not necessarily perceptible) edge block errors when -decompressing progressive JPEG images exactly two MCU blocks in width or that +decompressing progressive JPEG images exactly two DCT blocks in width or that use vertical chrominance subsampling. 3. Fixed a regression introduced by 3.0 beta2[6] that, in rare cases, caused @@ -179,11 +237,10 @@ through pointer arguments. - `TJFLAG_LIMITSCANS`/`TJ.FLAG_LIMITSCANS` has been reimplemented as an API parameter (`TJPARAM_SCANLIMIT`/`TJ.PARAM_SCANLIMIT`) that allows the number of scans to be specified. - - Optimized baseline entropy coding (the computation of optimal Huffman -tables, as opposed to using the default Huffman tables) can now be specified, -using a new API parameter (`TJPARAM_OPTIMIZE`/`TJ.PARAM_OPTIMIZE`), a new -transform option (`TJXOPT_OPTIMIZE`/`TJTransform.OPT_OPTIMIZE`), and a new -TJBench option (`-optimize`.) + - Huffman table optimization can now be specified using a new API +parameter (`TJPARAM_OPTIMIZE`/`TJ.PARAM_OPTIMIZE`), a new transform option +(`TJXOPT_OPTIMIZE`/`TJTransform.OPT_OPTIMIZE`), and a new TJBench option +(`-optimize`.) - Arithmetic entropy coding can now be specified or queried, using a new API parameter (`TJPARAM_ARITHMETIC`/`TJ.PARAM_ARITHMETIC`), a new transform option (`TJXOPT_ARITHMETIC`/`TJTransform.OPT_ARITHMETIC`), and a new TJBench @@ -426,9 +483,9 @@ prevented libjpeg-turbo from working properly with other linkers and also represented a potential security risk. 2. Fixed an issue whereby the `tjTransform()` function incorrectly computed the -MCU block size for 4:4:4 JPEG images with non-unary sampling factors and thus -unduly rejected some cropping regions, even though those regions aligned with -8x8 MCU block boundaries. +iMCU size for 4:4:4 JPEG images with non-unary sampling factors and thus unduly +rejected some cropping regions, even though those regions aligned with 8x8 iMCU +boundaries. 3. Fixed a regression introduced by 2.1 beta1[13] that caused the build system to enable the Arm Neon SIMD extensions when targetting Armv6 and other legacy @@ -1010,16 +1067,15 @@ encounters a warning from the underlying libjpeg API (the default behavior is to allow the operation to complete unless a fatal error is encountered.) 5. Introduced a new flag in the TurboJPEG C and Java APIs (`TJFLAG_PROGRESSIVE` -and `TJ.FLAG_PROGRESSIVE`, respectively) that causes the library to use -progressive entropy coding in JPEG images generated by compression and -transform operations. Additionally, a new transform option -(`TJXOPT_PROGRESSIVE` in the C API and `TJTransform.OPT_PROGRESSIVE` in the -Java API) has been introduced, allowing progressive entropy coding to be -enabled for selected transforms in a multi-transform operation. +and `TJ.FLAG_PROGRESSIVE`, respectively) that causes compression and transform +operations to generate progressive JPEG images. Additionally, a new transform +option (`TJXOPT_PROGRESSIVE` in the C API and `TJTransform.OPT_PROGRESSIVE` in +the Java API) has been introduced, allowing progressive JPEG images to be +generated by selected transforms in a multi-transform operation. 6. Introduced a new transform option in the TurboJPEG API (`TJXOPT_COPYNONE` in the C API and `TJTransform.OPT_COPYNONE` in the Java API) that allows the -copying of markers (including EXIF and ICC profile data) to be disabled for a +copying of markers (including Exif and ICC profile data) to be disabled for a particular transform. 7. Added two functions to the TurboJPEG C API (`tjLoadImage()` and @@ -1150,13 +1206,13 @@ bug that has existed since the introduction of libjpeg v7/v8 API/ABI emulation in libjpeg-turbo v1.1. 7. The lossless transform features in jpegtran and the TurboJPEG API will now -always attempt to adjust the EXIF image width and height tags if the image size +always attempt to adjust the Exif image width and height tags if the image size changed as a result of the transform. This behavior has always existed when using libjpeg v8 API/ABI emulation. It was supposed to be available with libjpeg v7 API/ABI emulation as well but did not work properly due to a bug. Furthermore, there was never any good reason not to enable it with libjpeg v6b API/ABI emulation, since the behavior is entirely internal. Note that -`-copy all` must be passed to jpegtran in order to transfer the EXIF tags from +`-copy all` must be passed to jpegtran in order to transfer the Exif tags from the source image to the destination image. 8. Fixed several memory leaks in the TurboJPEG API library that could occur @@ -1178,7 +1234,7 @@ for two reasons: it allows testers to more easily work around the 2 GB limit in libFuzzer, and it allows developers of security-sensitive applications to more easily defend against one of the progressive JPEG exploits (LJT-01-004) identified in -[this report](http://www.libjpeg-turbo.org/pmwiki/uploads/About/TwoIssueswiththeJPEGStandard.pdf). +[this report](https://libjpeg-turbo.org/pmwiki/uploads/About/TwoIssueswiththeJPEGStandard.pdf). 10. TJBench will now run each benchmark for 1 second prior to starting the timer, in order to improve the consistency of the results. Furthermore, the diff --git a/src/3rdparty/libjpeg/src/README.ijg b/src/3rdparty/libjpeg/src/README.ijg index 8f3768265f6..1be35958cff 100644 --- a/src/3rdparty/libjpeg/src/README.ijg +++ b/src/3rdparty/libjpeg/src/README.ijg @@ -89,9 +89,9 @@ The library is intended to be reused in other applications. In order to support file conversion and viewing software, we have included considerable functionality beyond the bare JPEG coding/decoding capability; for example, the color quantization modules are not strictly part of JPEG -decoding, but they are essential for output to colormapped file formats or -colormapped displays. These extra functions can be compiled out of the -library if not required for a particular application. +decoding, but they are essential for output to colormapped file formats. These +extra functions can be compiled out of the library if not required for a +particular application. We have also included "jpegtran", a utility for lossless transcoding between different JPEG processes, and "rdjpgcom" and "wrjpgcom", two simple diff --git a/src/3rdparty/libjpeg/src/README.md b/src/3rdparty/libjpeg/src/README.md index 923e61d231c..17c8412774c 100644 --- a/src/3rdparty/libjpeg/src/README.md +++ b/src/3rdparty/libjpeg/src/README.md @@ -71,7 +71,8 @@ JPEG images: top of the TurboJPEG API. The TurboJPEG API is recommended for first-time users of libjpeg-turbo. Refer to [tjexample.c](tjexample.c) and [TJExample.java](java/TJExample.java) for examples of its usage and to - for API documentation. + for API + documentation. - **libjpeg API**
This is the de facto industry-standard API for compressing and decompressing @@ -199,7 +200,7 @@ supported and which aren't. NOTE: As of this writing, extensive research has been conducted into the usefulness of DCT scaling as a means of data reduction and SmartScale as a means of quality improvement. Readers are invited to peruse the research at - and draw their own conclusions, + and draw their own conclusions, but it is the general belief of our project that these features have not demonstrated sufficient usefulness to justify inclusion in libjpeg-turbo. diff --git a/src/3rdparty/libjpeg/src/jcdctmgr.c b/src/3rdparty/libjpeg/src/jcdctmgr.c index 7191ee73169..dbdbad6a28e 100644 --- a/src/3rdparty/libjpeg/src/jcdctmgr.c +++ b/src/3rdparty/libjpeg/src/jcdctmgr.c @@ -6,7 +6,7 @@ * libjpeg-turbo Modifications: * Copyright (C) 1999-2006, MIYASAKA Masaru. * Copyright 2009 Pierre Ossman for Cendio AB - * Copyright (C) 2011, 2014-2015, 2022, D. R. Commander. + * Copyright (C) 2011, 2014-2015, 2022, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -114,8 +114,8 @@ flss(UINT16 val) * Compute values to do a division using reciprocal. * * This implementation is based on an algorithm described in - * "How to optimize for the Pentium family of microprocessors" - * (http://www.agner.org/assem/). + * "Optimizing subroutines in assembly language: + * An optimization guide for x86 platforms" (https://agner.org/optimize). * More information about the basic algorithm can be found in * the paper "Integer Division Using Reciprocals" by Robert Alverson. * diff --git a/src/3rdparty/libjpeg/src/jchuff.c b/src/3rdparty/libjpeg/src/jchuff.c index 488c9b5c3a7..8cdd5bd35dc 100644 --- a/src/3rdparty/libjpeg/src/jchuff.c +++ b/src/3rdparty/libjpeg/src/jchuff.c @@ -542,6 +542,10 @@ encode_one_block_simd(working_state *state, JCOEFPTR block, int last_dc_val, JOCTET _buffer[BUFSIZE], *buffer; int localbuf = 0; +#ifdef ZERO_BUFFERS + memset(_buffer, 0, sizeof(_buffer)); +#endif + LOAD_BUFFER() buffer = jsimd_huff_encode_one_block(state, buffer, block, last_dc_val, diff --git a/src/3rdparty/libjpeg/src/jcmaster.c b/src/3rdparty/libjpeg/src/jcmaster.c index 161019763d4..5d89178348b 100644 --- a/src/3rdparty/libjpeg/src/jcmaster.c +++ b/src/3rdparty/libjpeg/src/jcmaster.c @@ -751,22 +751,25 @@ jinit_c_master_control(j_compress_ptr cinfo, boolean transcode_only) /* Validate parameters, determine derived values */ initial_setup(cinfo, transcode_only); - if (cinfo->master->lossless || /* TEMPORARY HACK ??? */ - (cinfo->progressive_mode && !cinfo->arith_code)) - cinfo->optimize_coding = TRUE; /* assume default tables no good for - progressive mode or lossless mode */ - for (i = 0; i < NUM_HUFF_TBLS; i++) { - if (cinfo->dc_huff_tbl_ptrs[i] != NULL || - cinfo->ac_huff_tbl_ptrs[i] != NULL) { - empty_huff_tables = FALSE; - break; + if (cinfo->arith_code) + cinfo->optimize_coding = FALSE; + else { + if (cinfo->master->lossless || /* TEMPORARY HACK ??? */ + cinfo->progressive_mode) + cinfo->optimize_coding = TRUE; /* assume default tables no good for + progressive mode or lossless mode */ + for (i = 0; i < NUM_HUFF_TBLS; i++) { + if (cinfo->dc_huff_tbl_ptrs[i] != NULL || + cinfo->ac_huff_tbl_ptrs[i] != NULL) { + empty_huff_tables = FALSE; + break; + } } + if (cinfo->data_precision == 12 && !cinfo->optimize_coding && + (empty_huff_tables || using_std_huff_tables(cinfo))) + cinfo->optimize_coding = TRUE; /* assume default tables no good for + 12-bit data precision */ } - if (cinfo->data_precision == 12 && !cinfo->arith_code && - !cinfo->optimize_coding && - (empty_huff_tables || using_std_huff_tables(cinfo))) - cinfo->optimize_coding = TRUE; /* assume default tables no good for 12-bit - data precision */ /* Initialize my private state */ if (transcode_only) { diff --git a/src/3rdparty/libjpeg/src/jcomapi.c b/src/3rdparty/libjpeg/src/jcomapi.c index efbb8357b0c..84f37e172ec 100644 --- a/src/3rdparty/libjpeg/src/jcomapi.c +++ b/src/3rdparty/libjpeg/src/jcomapi.c @@ -3,8 +3,8 @@ * * This file was part of the Independent JPEG Group's software: * Copyright (C) 1994-1997, Thomas G. Lane. - * It was modified by The libjpeg-turbo Project to include only code relevant - * to libjpeg-turbo. + * libjpeg-turbo Modifications: + * Copyright (C) 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -51,6 +51,7 @@ jpeg_abort(j_common_ptr cinfo) * A bit kludgy to do it here, but this is the most central place. */ ((j_decompress_ptr)cinfo)->marker_list = NULL; + ((j_decompress_ptr)cinfo)->master->marker_list_end = NULL; } else { cinfo->global_state = CSTATE_START; } diff --git a/src/3rdparty/libjpeg/src/jcparam.c b/src/3rdparty/libjpeg/src/jcparam.c index d1dee4da3df..1d6e2254809 100644 --- a/src/3rdparty/libjpeg/src/jcparam.c +++ b/src/3rdparty/libjpeg/src/jcparam.c @@ -233,7 +233,7 @@ jpeg_set_defaults(j_compress_ptr cinfo) * tables will be computed. This test can be removed if default tables * are supplied that are valid for the desired precision. */ - if (cinfo->data_precision == 12 && !cinfo->arith_code) + if (cinfo->data_precision == 12) cinfo->optimize_coding = TRUE; /* By default, use the simpler non-cosited sampling alignment */ diff --git a/src/3rdparty/libjpeg/src/jcphuff.c b/src/3rdparty/libjpeg/src/jcphuff.c index 484e2d857f0..58287328d2d 100644 --- a/src/3rdparty/libjpeg/src/jcphuff.c +++ b/src/3rdparty/libjpeg/src/jcphuff.c @@ -650,6 +650,11 @@ encode_mcu_AC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data) size_t bits[8 / SIZEOF_SIZE_T]; int max_coef_bits = cinfo->data_precision + 2; +#ifdef ZERO_BUFFERS + memset(values_unaligned, 0, sizeof(values_unaligned)); + memset(bits, 0, sizeof(bits)); +#endif + entropy->next_output_byte = cinfo->dest->next_output_byte; entropy->free_in_buffer = cinfo->dest->free_in_buffer; @@ -915,6 +920,11 @@ encode_mcu_AC_refine(j_compress_ptr cinfo, JBLOCKROW *MCU_data) size_t zerobits, signbits; size_t bits[16 / SIZEOF_SIZE_T]; +#ifdef ZERO_BUFFERS + memset(absvalues_unaligned, 0, sizeof(absvalues_unaligned)); + memset(bits, 0, sizeof(bits)); +#endif + entropy->next_output_byte = cinfo->dest->next_output_byte; entropy->free_in_buffer = cinfo->dest->free_in_buffer; diff --git a/src/3rdparty/libjpeg/src/jdapistd.c b/src/3rdparty/libjpeg/src/jdapistd.c index 1f449272368..38da36b7050 100644 --- a/src/3rdparty/libjpeg/src/jdapistd.c +++ b/src/3rdparty/libjpeg/src/jdapistd.c @@ -4,7 +4,7 @@ * This file was part of the Independent JPEG Group's software: * Copyright (C) 1994-1996, Thomas G. Lane. * libjpeg-turbo Modifications: - * Copyright (C) 2010, 2015-2020, 2022-2023, D. R. Commander. + * Copyright (C) 2010, 2015-2020, 2022-2024, D. R. Commander. * Copyright (C) 2015, Google, Inc. * For conditions of distribution and use, see the accompanying README.ijg * file. @@ -200,7 +200,8 @@ _jpeg_crop_scanline(j_decompress_ptr cinfo, JDIMENSION *xoffset, ERREXIT(cinfo, JERR_BAD_CROP_SPEC); /* xoffset and width must fall within the output image dimensions. */ - if (*width == 0 || *xoffset + *width > cinfo->output_width) + if (*width == 0 || + (unsigned long long)(*xoffset) + *width > cinfo->output_width) ERREXIT(cinfo, JERR_WIDTH_OVERFLOW); /* No need to do anything if the caller wants the entire width. */ @@ -482,7 +483,8 @@ _jpeg_skip_scanlines(j_decompress_ptr cinfo, JDIMENSION num_lines) ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state); /* Do not skip past the bottom of the image. */ - if (cinfo->output_scanline + num_lines >= cinfo->output_height) { + if ((unsigned long long)cinfo->output_scanline + num_lines >= + cinfo->output_height) { num_lines = cinfo->output_height - cinfo->output_scanline; cinfo->output_scanline = cinfo->output_height; (*cinfo->inputctl->finish_input_pass) (cinfo); diff --git a/src/3rdparty/libjpeg/src/jdmarker.c b/src/3rdparty/libjpeg/src/jdmarker.c index acd28ce62c5..f918ee4db52 100644 --- a/src/3rdparty/libjpeg/src/jdmarker.c +++ b/src/3rdparty/libjpeg/src/jdmarker.c @@ -6,7 +6,7 @@ * Lossless JPEG Modifications: * Copyright (C) 1999, Ken Murchison. * libjpeg-turbo Modifications: - * Copyright (C) 2012, 2015, 2022, D. R. Commander. + * Copyright (C) 2012, 2015, 2022, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -248,6 +248,9 @@ get_sof(j_decompress_ptr cinfo, boolean is_prog, boolean is_lossless, jpeg_component_info *compptr; INPUT_VARS(cinfo); + if (cinfo->marker->saw_SOF) + ERREXIT(cinfo, JERR_SOF_DUPLICATE); + cinfo->progressive_mode = is_prog; cinfo->master->lossless = is_lossless; cinfo->arith_code = is_arith; @@ -265,9 +268,6 @@ get_sof(j_decompress_ptr cinfo, boolean is_prog, boolean is_lossless, (int)cinfo->image_width, (int)cinfo->image_height, cinfo->num_components); - if (cinfo->marker->saw_SOF) - ERREXIT(cinfo, JERR_SOF_DUPLICATE); - /* We don't support files in which the image height is initially specified */ /* as 0 and is later redefined by DNL. As long as we have to check that, */ /* might as well have a general sanity check. */ @@ -819,13 +819,11 @@ save_marker(j_decompress_ptr cinfo) /* Done reading what we want to read */ if (cur_marker != NULL) { /* will be NULL if bogus length word */ /* Add new marker to end of list */ - if (cinfo->marker_list == NULL) { - cinfo->marker_list = cur_marker; + if (cinfo->marker_list == NULL || cinfo->master->marker_list_end == NULL) { + cinfo->marker_list = cinfo->master->marker_list_end = cur_marker; } else { - jpeg_saved_marker_ptr prev = cinfo->marker_list; - while (prev->next != NULL) - prev = prev->next; - prev->next = cur_marker; + cinfo->master->marker_list_end->next = cur_marker; + cinfo->master->marker_list_end = cur_marker; } /* Reset pointer & calc remaining data length */ data = cur_marker->data; diff --git a/src/3rdparty/libjpeg/src/jerror.c b/src/3rdparty/libjpeg/src/jerror.c index 3a75fec02c1..2133244f8ae 100644 --- a/src/3rdparty/libjpeg/src/jerror.c +++ b/src/3rdparty/libjpeg/src/jerror.c @@ -40,8 +40,6 @@ * Create the message string table. * We do this from the master message list in jerror.h by re-reading * jerror.h with a suitable definition for macro JMESSAGE. - * The message table is made an external symbol just in case any applications - * want to refer to it directly. */ #define JMESSAGE(code, string) string, diff --git a/src/3rdparty/libjpeg/src/jmemnobs.c b/src/3rdparty/libjpeg/src/jmemnobs.c index cd6571ba1c4..692775f5a85 100644 --- a/src/3rdparty/libjpeg/src/jmemnobs.c +++ b/src/3rdparty/libjpeg/src/jmemnobs.c @@ -4,7 +4,7 @@ * This file was part of the Independent JPEG Group's software: * Copyright (C) 1992-1996, Thomas G. Lane. * libjpeg-turbo Modifications: - * Copyright (C) 2017-2018, D. R. Commander. + * Copyright (C) 2017-2018, 2024, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * @@ -31,7 +31,7 @@ GLOBAL(void *) jpeg_get_small(j_common_ptr cinfo, size_t sizeofobject) { - return (void *)malloc(sizeofobject); + return (void *)MALLOC(sizeofobject); } GLOBAL(void) @@ -48,7 +48,7 @@ jpeg_free_small(j_common_ptr cinfo, void *object, size_t sizeofobject) GLOBAL(void *) jpeg_get_large(j_common_ptr cinfo, size_t sizeofobject) { - return (void *)malloc(sizeofobject); + return (void *)MALLOC(sizeofobject); } GLOBAL(void) diff --git a/src/3rdparty/libjpeg/src/jpegint.h b/src/3rdparty/libjpeg/src/jpegint.h index 65414201434..a90493f9e08 100644 --- a/src/3rdparty/libjpeg/src/jpegint.h +++ b/src/3rdparty/libjpeg/src/jpegint.h @@ -7,7 +7,7 @@ * Lossless JPEG Modifications: * Copyright (C) 1999, Ken Murchison. * libjpeg-turbo Modifications: - * Copyright (C) 2015-2017, 2019, 2021-2022, D. R. Commander. + * Copyright (C) 2015-2017, 2019, 2021-2022, 2024, D. R. Commander. * Copyright (C) 2015, Google, Inc. * Copyright (C) 2021, Alex Richardson. * For conditions of distribution and use, see the accompanying README.ijg @@ -249,6 +249,9 @@ struct jpeg_decomp_master { /* Last iMCU row that was successfully decoded */ JDIMENSION last_good_iMCU_row; + + /* Tail of list of saved markers */ + jpeg_saved_marker_ptr marker_list_end; }; /* Input control module */ @@ -443,6 +446,12 @@ struct jpeg_color_quantizer { #undef MIN #define MIN(a, b) ((a) < (b) ? (a) : (b)) +#ifdef ZERO_BUFFERS +#define MALLOC(size) calloc(1, size) +#else +#define MALLOC(size) malloc(size) +#endif + /* We assume that right shift corresponds to signed division by 2 with * rounding towards minus infinity. This is correct for typical "arithmetic diff --git a/src/3rdparty/libjpeg/src/jpeglib.h b/src/3rdparty/libjpeg/src/jpeglib.h index a59e98c25e5..17e78333fd8 100644 --- a/src/3rdparty/libjpeg/src/jpeglib.h +++ b/src/3rdparty/libjpeg/src/jpeglib.h @@ -7,7 +7,7 @@ * Lossless JPEG Modifications: * Copyright (C) 1999, Ken Murchison. * libjpeg-turbo Modifications: - * Copyright (C) 2009-2011, 2013-2014, 2016-2017, 2020, 2022-2023, + * Copyright (C) 2009-2011, 2013-2014, 2016-2017, 2020, 2022-2024, D. R. Commander. * Copyright (C) 2015, Google, Inc. * For conditions of distribution and use, see the accompanying README.ijg @@ -18,6 +18,16 @@ * and perhaps jerror.h if they want to know the exact error codes. */ +/* NOTE: This header file does not include stdio.h, despite the fact that it + * uses FILE and size_t. That is by design, since the libjpeg API predates the + * widespread adoption of ANSI/ISO C. Referring to libjpeg.txt, it is a + * documented requirement that calling programs "include system headers that + * define at least the typedefs FILE and size_t" before including jpeglib.h. + * Technically speaking, changing that requirement by including stdio.h here + * would break backward API compatibility. Please do not file bug reports, + * feature requests, or pull requests regarding this. + */ + #ifndef JPEGLIB_H #define JPEGLIB_H @@ -575,11 +585,10 @@ struct jpeg_decompress_struct { */ int actual_number_of_colors; /* number of entries in use */ JSAMPARRAY colormap; /* The color map as a 2-D pixel array - If data_precision is 12 or 16, then this is - actually a J12SAMPARRAY or a J16SAMPARRAY, - so callers must type-cast it in order to - read/write 12-bit or 16-bit samples from/to - the array. */ + If data_precision is 12, then this is + actually a J12SAMPARRAY, so callers must + type-cast it in order to read/write 12-bit + samples from/to the array. */ /* State variables: these variables indicate the progress of decompression. * The application may examine these but must not modify them. diff --git a/src/3rdparty/libjpeg/src/jquant1.c b/src/3rdparty/libjpeg/src/jquant1.c index 2e914b919c6..bd68dcb8c6a 100644 --- a/src/3rdparty/libjpeg/src/jquant1.c +++ b/src/3rdparty/libjpeg/src/jquant1.c @@ -86,22 +86,22 @@ static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = { * Stephen Hawley's article "Ordered Dithering" in Graphics Gems I. * The values in this array must range from 0 to ODITHER_CELLS-1. */ - { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 }, - { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 }, - { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 }, - { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 }, - { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 }, - { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 }, - { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 }, - { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 }, - { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 }, - { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 }, - { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 }, - { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 }, - { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 }, - { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 }, - { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 }, - { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 } + { 0, 192, 48, 240, 12, 204, 60, 252, 3, 195, 51, 243, 15, 207, 63, 255 }, + { 128, 64, 176, 112, 140, 76, 188, 124, 131, 67, 179, 115, 143, 79, 191, 127 }, + { 32, 224, 16, 208, 44, 236, 28, 220, 35, 227, 19, 211, 47, 239, 31, 223 }, + { 160, 96, 144, 80, 172, 108, 156, 92, 163, 99, 147, 83, 175, 111, 159, 95 }, + { 8, 200, 56, 248, 4, 196, 52, 244, 11, 203, 59, 251, 7, 199, 55, 247 }, + { 136, 72, 184, 120, 132, 68, 180, 116, 139, 75, 187, 123, 135, 71, 183, 119 }, + { 40, 232, 24, 216, 36, 228, 20, 212, 43, 235, 27, 219, 39, 231, 23, 215 }, + { 168, 104, 152, 88, 164, 100, 148, 84, 171, 107, 155, 91, 167, 103, 151, 87 }, + { 2, 194, 50, 242, 14, 206, 62, 254, 1, 193, 49, 241, 13, 205, 61, 253 }, + { 130, 66, 178, 114, 142, 78, 190, 126, 129, 65, 177, 113, 141, 77, 189, 125 }, + { 34, 226, 18, 210, 46, 238, 30, 222, 33, 225, 17, 209, 45, 237, 29, 221 }, + { 162, 98, 146, 82, 174, 110, 158, 94, 161, 97, 145, 81, 173, 109, 157, 93 }, + { 10, 202, 58, 250, 6, 198, 54, 246, 9, 201, 57, 249, 5, 197, 53, 245 }, + { 138, 74, 186, 122, 134, 70, 182, 118, 137, 73, 185, 121, 133, 69, 181, 117 }, + { 42, 234, 26, 218, 38, 230, 22, 214, 41, 233, 25, 217, 37, 229, 21, 213 }, + { 170, 106, 154, 90, 166, 102, 150, 86, 169, 105, 153, 89, 165, 101, 149, 85 } };