diff --git a/graphics/libjxl/Makefile b/graphics/libjxl/Makefile --- a/graphics/libjxl/Makefile +++ b/graphics/libjxl/Makefile @@ -4,9 +4,6 @@ PORTREVISION= 1 CATEGORIES= graphics -PATCH_SITES= https://github.com/${GH_ACCOUNT}/${GH_PROJECT}/commit/ -PATCHFILES+= d2411cebb0c3.patch:-p1 # https://github.com/libjxl/libjxl/pull/4007 - MAINTAINER= jbeich@FreeBSD.org COMMENT= JPEG XL reference encoder/decoder WWW= https://jpeg.org/jpegxl/ @@ -21,16 +18,17 @@ USES= cmake:testing compiler:c++11-lib cpe localbase:ldflags pkgconfig shared-mime-info CPE_VENDOR= ${PORTNAME}_project USE_GITHUB= yes -USE_LDCONFIG= yes GH_TUPLE= libjxl:testdata:ff8d743:testdata/testdata \ webmproject:sjpeg:e5ab130:sjpeg/third_party/sjpeg \ ${NULL} +USE_LDCONFIG= yes CMAKE_ON= JPEGXL_ENABLE_PLUGINS CMAKE_ON+= ${AVX512 AVX512_SPR AVX512_ZEN4:L:S/^/JPEGXL_ENABLE_/} CMAKE_OFF= ${BENCHMARK FUZZERS TCMALLOC:L:S/^/JPEGXL_ENABLE_/} CMAKE_OFF+= ${OpenGL GLUT:L:S/^/CMAKE_DISABLE_FIND_PACKAGE_/} # sjpeg CMAKE_OFF+= ${CMAKE_TESTING_ON} LDFLAGS+= -Wl,--as-needed # brotlicommon, OPENEXR/PNG deps +EXTRA_PATCHES= ${FILESDIR}/extra-patch-openexr:-p1 PLIST_SUB= VERSION=${PORTVERSION} OPTIONS_DEFINE= GIF JPEG LCMS2 LTO MANPAGES OPENEXR PIXBUF PNG diff --git a/graphics/libjxl/distinfo b/graphics/libjxl/distinfo --- a/graphics/libjxl/distinfo +++ b/graphics/libjxl/distinfo @@ -7,5 +7,3 @@ SIZE (webmproject-sjpeg-e5ab130_GH0.tar.gz) = 2481141 SHA256 (jbeich-skcms-42030a7_GH0.tar.gz) = b7537267dd0fda80a98939cc4e4d15614d2d6f433cc8421b797e0f47078c2979 SIZE (jbeich-skcms-42030a7_GH0.tar.gz) = 10050433 -SHA256 (d2411cebb0c3.patch) = a14e59cc6cdf1f0b220c013570e4807500a8e7e2af2a66996456b2540b57d7f6 -SIZE (d2411cebb0c3.patch) = 3857 diff --git a/graphics/libjxl/files/extra-patch-openexr b/graphics/libjxl/files/extra-patch-openexr new file mode 100644 --- /dev/null +++ b/graphics/libjxl/files/extra-patch-openexr @@ -0,0 +1,103 @@ +From d2411cebb0c34927189417dfc536867fa8902b22 Mon Sep 17 00:00:00 2001 +From: Eugene Kliuchnikov +Date: Wed, 11 Dec 2024 18:48:12 +0100 +Subject: [PATCH] Fix for newer versions of OpenEXR (#4007) + +Newer versions of OpenEXR are doing "scratch" reads that can span befind end of file +(and thus misuse exceptions) + +This PR adjusts our InMemoryIStream to fit OpenEXR expectations. +--- + lib/extras/codec_test.cc | 14 +++++++++----- + lib/extras/dec/exr.cc | 28 +++++++++++++++++++++------- + 2 files changed, 30 insertions(+), 12 deletions(-) + +diff --git a/lib/extras/codec_test.cc b/lib/extras/codec_test.cc +index 6cbed220975e..c2b656bd6c2e 100644 +--- a/lib/extras/codec_test.cc ++++ b/lib/extras/codec_test.cc +@@ -267,15 +267,19 @@ void TestRoundTrip(const TestImageParams& params, ThreadPool* pool) { + params.codec, params.is_gray, params.add_alpha, params.bits_per_sample); + printf("Codec %s %s\n", extension.c_str(), params.DebugString().c_str()); + +- PackedPixelFile ppf_in; +- CreateTestImage(params, &ppf_in); +- +- EncodedImage encoded; ++ if (!CanDecode(params.codec)) { ++ fprintf(stderr, "Skipping test because of missing decoding support.\n"); ++ return; ++ } + auto encoder = Encoder::FromExtension(extension); + if (!encoder) { +- fprintf(stderr, "Skipping test because of missing codec support.\n"); ++ fprintf(stderr, "Skipping test because of missing encoding support.\n"); + return; + } ++ ++ PackedPixelFile ppf_in; ++ CreateTestImage(params, &ppf_in); ++ EncodedImage encoded; + ASSERT_TRUE(encoder->Encode(ppf_in, &encoded, pool)); + ASSERT_EQ(encoded.bitstreams.size(), 1); + +diff --git a/lib/extras/dec/exr.cc b/lib/extras/dec/exr.cc +index 59edd63eb863..4213d8ec5773 100644 +--- a/lib/extras/dec/exr.cc ++++ b/lib/extras/dec/exr.cc +@@ -41,10 +41,9 @@ Status DecodeImageEXR(Span bytes, const ColorHints& color_hints, + #include + + #ifdef __EXCEPTIONS +-#include +-#define JXL_EXR_THROW_LENGTH_ERROR() throw std::length_error(""); ++#define JXL_EXR_THROW_LENGTH_ERROR(M) throw Iex::InputExc(M); + #else // __EXCEPTIONS +-#define JXL_EXR_THROW_LENGTH_ERROR() JXL_CRASH() ++#define JXL_EXR_THROW_LENGTH_ERROR(M) JXL_CRASH() + #endif // __EXCEPTIONS + + namespace jxl { +@@ -71,8 +70,11 @@ class InMemoryIStream : public OpenEXR::IStream { + + bool isMemoryMapped() const override { return true; } + char* readMemoryMapped(const int n) override { +- if (pos_ + n < pos_ || pos_ + n > bytes_.size()) { +- JXL_EXR_THROW_LENGTH_ERROR(); ++ if (pos_ + n < pos_) { ++ JXL_EXR_THROW_LENGTH_ERROR("Overflow"); ++ } ++ if (pos_ + n > bytes_.size()) { ++ JXL_EXR_THROW_LENGTH_ERROR("Read past end of file"); + } + char* const result = + const_cast(reinterpret_cast(bytes_.data() + pos_)); +@@ -80,14 +82,26 @@ class InMemoryIStream : public OpenEXR::IStream { + return result; + } + bool read(char c[], const int n) override { +- std::copy_n(readMemoryMapped(n), n, c); ++ // That is not stated in documentation, but the OpenEXR code expects that ++ // when requested amount is not accessible and exception is thrown, all ++ // the accessible data is read. ++ if (pos_ + n < pos_) { ++ JXL_EXR_THROW_LENGTH_ERROR("Overflow"); ++ } ++ if (pos_ + n > bytes_.size()) { ++ int can_read = static_cast(bytes_.size() - pos_); ++ std::copy_n(readMemoryMapped(can_read), can_read, c); ++ JXL_EXR_THROW_LENGTH_ERROR("Read past end of file"); ++ } else { ++ std::copy_n(readMemoryMapped(n), n, c); ++ } + return pos_ < bytes_.size(); + } + + ExrInt64 tellg() override { return pos_; } + void seekg(const ExrInt64 pos) override { + if (pos >= bytes_.size()) { +- JXL_EXR_THROW_LENGTH_ERROR(); ++ JXL_EXR_THROW_LENGTH_ERROR("Seeks past end of file"); + } + pos_ = pos; + }