From 362ffaf9b7f063609bcd02ef30b1288e16e99cd1 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Sun, 18 Aug 2024 20:39:14 -0500 Subject: [PATCH 01/16] implement tiff exif multistrip support --- Tests/test_file_tiff.py | 3 ++- Tests/test_file_tiff_metadata.py | 22 ++++++++++++++++++++++ src/PIL/TiffImagePlugin.py | 8 +++++--- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index 190f83f40..44da25295 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -108,7 +108,8 @@ class TestFileTiff: assert_image_equal_tofile(im, "Tests/images/hopper.tif") with Image.open("Tests/images/hopper_bigtiff.tif") as im: - # multistrip support not yet implemented + # The data type of this file's StripOffsets tag is LONG8, + # which is not yet supported for offset data when saving multiple frames. del im.tag_v2[273] outfile = str(tmp_path / "temp.tif") diff --git a/Tests/test_file_tiff_metadata.py b/Tests/test_file_tiff_metadata.py index 1e0310001..00fe745cf 100644 --- a/Tests/test_file_tiff_metadata.py +++ b/Tests/test_file_tiff_metadata.py @@ -181,6 +181,28 @@ def test_change_stripbytecounts_tag_type(tmp_path: Path) -> None: assert reloaded.tag_v2.tagtype[TiffImagePlugin.STRIPBYTECOUNTS] == TiffTags.LONG +def test_save_multiple_stripoffsets() -> None: + ifd = TiffImagePlugin.ImageFileDirectory_v2() + ifd[TiffImagePlugin.STRIPOFFSETS] = (123, 456) + assert ifd.tagtype[TiffImagePlugin.STRIPOFFSETS] == TiffTags.LONG + + # all values are in little-endian + assert ifd.tobytes() == ( + # number of tags == 1 + b"\x01\x00" + # tag id (2 bytes), type (2 bytes), count (4 bytes), value (4 bytes) + # == 273, 4, 2, 18 + # == TiffImagePlugin.STRIPOFFSETS, TiffTags.LONG, 2, 18 + # the value is the index of the tag data + b"\x11\x01\x04\x00\x02\x00\x00\x00\x12\x00\x00\x00" + # end of tags marker + b"\x00\x00\x00\x00" + # tag data == (149, 482) == (123 + 26, 456 + 26) + # 26 is the number of bytes before this data + b"\x95\x00\x00\x00\xe2\x01\x00\x00" + ) + + def test_no_duplicate_50741_tag() -> None: assert TAG_IDS["MakerNoteSafety"] == 50741 assert TAG_IDS["BestQualityScale"] == 50780 diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index 14e6ea278..d4c46a797 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -991,9 +991,11 @@ class ImageFileDirectory_v2(_IFDv2Base): if stripoffsets is not None: tag, typ, count, value, data = entries[stripoffsets] if data: - msg = "multistrip support not yet implemented" - raise NotImplementedError(msg) - value = self._pack("L", self._unpack("L", value)[0] + offset) + size, handler = self._load_dispatch[typ] + values = [val + offset for val in handler(self, data, self.legacy_api)] + data = self._write_dispatch[typ](self, *values) + else: + value = self._pack("L", self._unpack("L", value)[0] + offset) entries[stripoffsets] = tag, typ, count, value, data # pass 2: write entries to file From 1392eab89b9c7e6bbc1fa5a1d3af2434bcb04e5d Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 19 Sep 2024 09:21:23 +1000 Subject: [PATCH 02/16] Updated Ghostscript to 10.4.0 --- .appveyor.yml | 4 ++-- .github/workflows/test-windows.yml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index f490561cd..de5e52742 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -34,8 +34,8 @@ install: - xcopy /S /Y c:\test-images-main\* c:\pillow\tests\images - curl -fsSL -o nasm-win64.zip https://raw.githubusercontent.com/python-pillow/pillow-depends/main/nasm-2.16.03-win64.zip - 7z x nasm-win64.zip -oc:\ -- choco install ghostscript --version=10.3.1 -- path c:\nasm-2.16.03;C:\Program Files\gs\gs10.03.1\bin;%PATH% +- choco install ghostscript --version=10.4.0 +- path c:\nasm-2.16.03;C:\Program Files\gs\gs10.04.0\bin;%PATH% - cd c:\pillow\winbuild\ - ps: | c:\python39\python.exe c:\pillow\winbuild\build_prepare.py -v --depends=C:\pillow-depends\ diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index f58e8dae3..13147d86b 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -86,8 +86,8 @@ jobs: choco install nasm --no-progress echo "C:\Program Files\NASM" >> $env:GITHUB_PATH - choco install ghostscript --version=10.3.1 --no-progress - echo "C:\Program Files\gs\gs10.03.1\bin" >> $env:GITHUB_PATH + choco install ghostscript --version=10.4.0 --no-progress + echo "C:\Program Files\gs\gs10.04.0\bin" >> $env:GITHUB_PATH # Install extra test images xcopy /S /Y Tests\test-images\* Tests\images From 0f47ecd4325268156c27fa86799d31829f31fcea Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 19 Sep 2024 15:07:06 +1000 Subject: [PATCH 03/16] Update CHANGES.rst [ci skip] --- CHANGES.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index f23ec609f..4ab9eaf2b 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,18 @@ Changelog (Pillow) 11.0.0 (unreleased) ------------------- +- Use transposed size after opening for TIFF images #8390 + [radarhere, homm] + +- Improve ImageFont error messages #8338 + [yngvem, radarhere, hugovk] + +- Mention MAX_TEXT_CHUNK limit in PNG error message #8391 + [radarhere] + +- Cast Dib handle to int #8385 + [radarhere] + - Accept float stroke widths #8369 [radarhere] From 46f2fa17be9768ec2647988b0446dd848b833a5b Mon Sep 17 00:00:00 2001 From: PavlNekrasov <95914807+PavlNekrasov@users.noreply.github.com> Date: Thu, 19 Sep 2024 22:53:45 +0300 Subject: [PATCH 04/16] fix dereference before checking for NULL in the `ImagingTransformAffine` function The `imIn` pointer is checked for `NULL`, but it seems to be dereferenced before this check. You must first make sure that the pointer is not `NULL` before using it. --- src/libImaging/Geometry.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libImaging/Geometry.c b/src/libImaging/Geometry.c index 2bfeed7b6..264c7d169 100644 --- a/src/libImaging/Geometry.c +++ b/src/libImaging/Geometry.c @@ -1035,6 +1035,10 @@ ImagingTransformAffine( double xx, yy; double xo, yo; + if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) { + return (Imaging)ImagingError_ModeError(); + } + if (filterid || imIn->type == IMAGING_TYPE_SPECIAL) { return ImagingGenericTransform( imOut, imIn, x0, y0, x1, y1, affine_transform, a, filterid, fill @@ -1046,10 +1050,6 @@ ImagingTransformAffine( return ImagingScaleAffine(imOut, imIn, x0, y0, x1, y1, a, fill); } - if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) { - return (Imaging)ImagingError_ModeError(); - } - if (x0 < 0) { x0 = 0; } From 9424b1a8920201b52086c0b06b5148db33255668 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 19 Sep 2024 19:59:08 +0000 Subject: [PATCH 05/16] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/libImaging/Geometry.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libImaging/Geometry.c b/src/libImaging/Geometry.c index 264c7d169..84aa442f0 100644 --- a/src/libImaging/Geometry.c +++ b/src/libImaging/Geometry.c @@ -1037,7 +1037,7 @@ ImagingTransformAffine( if (!imOut || !imIn || strcmp(imIn->mode, imOut->mode) != 0) { return (Imaging)ImagingError_ModeError(); - } + } if (filterid || imIn->type == IMAGING_TYPE_SPECIAL) { return ImagingGenericTransform( From 693a68b2bb7fdf01bbafb7070320c16ec57ca78d Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 20 Sep 2024 18:46:47 +1000 Subject: [PATCH 06/16] Updated link to OSS Fuzz issues --- README.md | 2 +- docs/index.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b4c6d2987..5bbebaccb 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ As of 2019, Pillow development is Code coverage - Fuzzing Status diff --git a/docs/index.rst b/docs/index.rst index 3a12953f0..18f5c3d13 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -54,7 +54,7 @@ Pillow for enterprise is available via the Tidelift Subscription. `Learn more Date: Fri, 20 Sep 2024 08:39:11 -0500 Subject: [PATCH 07/16] rewrite some comments Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com> --- Tests/test_file_tiff_metadata.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Tests/test_file_tiff_metadata.py b/Tests/test_file_tiff_metadata.py index 00fe745cf..36aabf4f8 100644 --- a/Tests/test_file_tiff_metadata.py +++ b/Tests/test_file_tiff_metadata.py @@ -191,14 +191,15 @@ def test_save_multiple_stripoffsets() -> None: # number of tags == 1 b"\x01\x00" # tag id (2 bytes), type (2 bytes), count (4 bytes), value (4 bytes) - # == 273, 4, 2, 18 - # == TiffImagePlugin.STRIPOFFSETS, TiffTags.LONG, 2, 18 - # the value is the index of the tag data + # TiffImagePlugin.STRIPOFFSETS, TiffTags.LONG, 2, 18 + # where STRIPOFFSETS is 273, LONG is 4 + # and 18 is the offset of the tag data b"\x11\x01\x04\x00\x02\x00\x00\x00\x12\x00\x00\x00" - # end of tags marker + # end of entries b"\x00\x00\x00\x00" - # tag data == (149, 482) == (123 + 26, 456 + 26) - # 26 is the number of bytes before this data + # 26 is the total number of bytes output, + # the offset for any auxiliary strip data that will then be appended + # (123 + 26, 456 + 26) == (149, 482) b"\x95\x00\x00\x00\xe2\x01\x00\x00" ) From 8fa5ba844361536135d3d6cb67e3a3f4a1a651f4 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Thu, 19 Sep 2024 11:05:52 -0500 Subject: [PATCH 08/16] add common windows ci test script --- .appveyor.yml | 5 ++--- .ci/test.cmd | 3 +++ .github/workflows/test-windows.yml | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) create mode 100644 .ci/test.cmd diff --git a/.appveyor.yml b/.appveyor.yml index f490561cd..7d45e11ee 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -53,9 +53,8 @@ test_script: - cd c:\pillow - '%PYTHON%\%EXECUTABLE% -m pip install pytest pytest-cov pytest-timeout defusedxml ipython numpy olefile pyroma' - c:\"Program Files (x86)"\"Windows Kits"\10\Debuggers\x86\gflags.exe /p /enable %PYTHON%\%EXECUTABLE% -- '%PYTHON%\%EXECUTABLE% -c "from PIL import Image"' -- '%PYTHON%\%EXECUTABLE% -m pytest -vx --cov PIL --cov Tests --cov-report term --cov-report xml Tests' -#- '%PYTHON%\%EXECUTABLE% test-installed.py -v -s %TEST_OPTIONS%' TODO TEST_OPTIONS with pytest? +- path %PYTHON%;%PATH% +- .ci\test.cmd after_test: - curl -Os https://uploader.codecov.io/latest/windows/codecov.exe diff --git a/.ci/test.cmd b/.ci/test.cmd new file mode 100644 index 000000000..aafc9290c --- /dev/null +++ b/.ci/test.cmd @@ -0,0 +1,3 @@ +python.exe -c "from PIL import Image" +IF ERRORLEVEL 1 EXIT /B +python.exe -bb -m pytest -v -x -W always --cov PIL --cov Tests --cov-report term --cov-report xml Tests diff --git a/.github/workflows/test-windows.yml b/.github/workflows/test-windows.yml index f58e8dae3..e36dc05fd 100644 --- a/.github/workflows/test-windows.yml +++ b/.github/workflows/test-windows.yml @@ -190,8 +190,8 @@ jobs: - name: Test Pillow run: | - path %GITHUB_WORKSPACE%\\winbuild\\build\\bin;%PATH% - python.exe -m pytest -vx -W always --cov PIL --cov Tests --cov-report term --cov-report xml Tests + path %GITHUB_WORKSPACE%\winbuild\build\bin;%PATH% + .ci\test.cmd shell: cmd - name: Prepare to upload errors From be3192ecd41581761a78913950ec3fb4be4dd981 Mon Sep 17 00:00:00 2001 From: Yay295 Date: Thu, 19 Sep 2024 12:08:34 -0500 Subject: [PATCH 09/16] use .ci/test.sh in test-mingw.yml --- .ci/test.sh | 2 +- .github/workflows/test-mingw.yml | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.ci/test.sh b/.ci/test.sh index 8ff7c5f64..3f0ddc350 100755 --- a/.ci/test.sh +++ b/.ci/test.sh @@ -4,4 +4,4 @@ set -e python3 -c "from PIL import Image" -python3 -bb -m pytest -v -x -W always --cov PIL --cov Tests --cov-report term Tests $REVERSE +python3 -bb -m pytest -v -x -W always --cov PIL --cov Tests --cov-report term --cov-report xml Tests $REVERSE diff --git a/.github/workflows/test-mingw.yml b/.github/workflows/test-mingw.yml index e5e1ec32e..c7a73439c 100644 --- a/.github/workflows/test-mingw.yml +++ b/.github/workflows/test-mingw.yml @@ -80,8 +80,7 @@ jobs: - name: Test Pillow run: | python3 selftest.py --installed - python3 -c "from PIL import Image" - python3 -m pytest -vx --cov PIL --cov Tests --cov-report term --cov-report xml Tests + .ci/test.sh - name: Upload coverage uses: codecov/codecov-action@v4 From 6081640aa5b68a177ed54cfd03e4ae6a748e8be8 Mon Sep 17 00:00:00 2001 From: Nulano Date: Sun, 22 Sep 2024 22:46:35 +0200 Subject: [PATCH 10/16] winbuild: Build freetype.vcxproj to fix passing in custom parameters. --- winbuild/build_prepare.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py index e2022d283..d350e2575 100644 --- a/winbuild/build_prepare.py +++ b/winbuild/build_prepare.py @@ -292,8 +292,12 @@ DEPS: dict[str, dict[str, Any]] = { }, "build": [ cmd_rmdir("objs"), - cmd_msbuild("MSBuild.sln", "Release Static", "Clean"), - cmd_msbuild("MSBuild.sln", "Release Static", "Build"), + cmd_msbuild( + r"builds\windows\vc2010\freetype.vcxproj", "Release Static", "Clean" + ), + cmd_msbuild( + r"builds\windows\vc2010\freetype.vcxproj", "Release Static", "Build" + ), cmd_xcopy("include", "{inc_dir}"), ], "libs": [r"objs\{msbuild_arch}\Release Static\freetype.lib"], From 8adf15a6ee1bab667a0e7b76d19ea0f26b29ce85 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 23 Sep 2024 09:29:16 +1000 Subject: [PATCH 11/16] Updated raqm to 0.10.2 --- depends/install_raqm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depends/install_raqm.sh b/depends/install_raqm.sh index 070ba23a1..5d862403e 100755 --- a/depends/install_raqm.sh +++ b/depends/install_raqm.sh @@ -2,7 +2,7 @@ # install raqm -archive=libraqm-0.10.1 +archive=libraqm-0.10.2 ./download-and-extract.sh $archive https://raw.githubusercontent.com/python-pillow/pillow-depends/main/$archive.tar.gz From 9fe014876ab3dbc2a765ae1175659cc0d7bc7e42 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sun, 22 Sep 2024 22:42:39 +1000 Subject: [PATCH 12/16] Shared libraries may be located within usr/lib64 --- depends/install_imagequant.sh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/depends/install_imagequant.sh b/depends/install_imagequant.sh index 867b31e4d..060d9840e 100755 --- a/depends/install_imagequant.sh +++ b/depends/install_imagequant.sh @@ -23,7 +23,12 @@ else cargo cinstall --prefix=/usr --destdir=. # Copy into place - sudo cp usr/lib/libimagequant.so* /usr/lib/ + if [ -d "usr/lib64" ]; then + lib="lib64" + else + lib="lib" + fi + sudo cp usr/$lib/libimagequant.so* /usr/lib/ sudo cp usr/include/libimagequant.h /usr/include/ if [ -n "$GITHUB_ACTIONS" ]; then From 3f8b496431c3eb2f0cedad35669e725fd3be45e0 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 24 Sep 2024 09:54:26 +1000 Subject: [PATCH 13/16] Updated harfbuzz to 10.0.0 --- .github/workflows/wheels-dependencies.sh | 2 +- winbuild/build_prepare.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wheels-dependencies.sh b/.github/workflows/wheels-dependencies.sh index 4d40f7fab..92e9ad5af 100755 --- a/.github/workflows/wheels-dependencies.sh +++ b/.github/workflows/wheels-dependencies.sh @@ -17,7 +17,7 @@ ARCHIVE_SDIR=pillow-depends-main # Package versions for fresh source builds FREETYPE_VERSION=2.13.2 if [[ "$MB_ML_VER" != 2014 ]]; then - HARFBUZZ_VERSION=9.0.0 + HARFBUZZ_VERSION=10.0.0 else HARFBUZZ_VERSION=8.5.0 fi diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py index d350e2575..db592d23c 100644 --- a/winbuild/build_prepare.py +++ b/winbuild/build_prepare.py @@ -112,7 +112,7 @@ V = { "BROTLI": "1.1.0", "FREETYPE": "2.13.3", "FRIBIDI": "1.0.15", - "HARFBUZZ": "9.0.0", + "HARFBUZZ": "10.0.0", "JPEGTURBO": "3.0.4", "LCMS2": "2.16", "LIBPNG": "1.6.44", From 61c83a882cc0a1b78f2e8f1e3ce38616f95c6f3e Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 25 Sep 2024 00:00:22 +1000 Subject: [PATCH 14/16] Updated macOS version to 10.15 for PyPy x86-64 --- .github/workflows/wheels.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/wheels.yml b/.github/workflows/wheels.yml index 11564c142..d3c2ac44c 100644 --- a/.github/workflows/wheels.yml +++ b/.github/workflows/wheels.yml @@ -105,13 +105,18 @@ jobs: - name: "macOS 10.10 x86_64" os: macos-13 cibw_arch: x86_64 - build: "pp310* cp3{9,10,11}*" + build: "cp3{9,10,11}*" macosx_deployment_target: "10.10" - name: "macOS 10.13 x86_64" os: macos-13 cibw_arch: x86_64 build: "cp3{12,13}*" macosx_deployment_target: "10.13" + - name: "macOS 10.15 x86_64" + os: macos-13 + cibw_arch: x86_64 + build: "pp310*" + macosx_deployment_target: "10.15" - name: "macOS arm64" os: macos-latest cibw_arch: arm64 From 72144ec5300d92bfffd029ccfb52e4d087a0bd95 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 25 Sep 2024 08:33:18 +1000 Subject: [PATCH 15/16] Updated harfbuzz to 10.0.1 --- .github/workflows/wheels-dependencies.sh | 2 +- winbuild/build_prepare.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/wheels-dependencies.sh b/.github/workflows/wheels-dependencies.sh index 92e9ad5af..b5fbdc421 100755 --- a/.github/workflows/wheels-dependencies.sh +++ b/.github/workflows/wheels-dependencies.sh @@ -17,7 +17,7 @@ ARCHIVE_SDIR=pillow-depends-main # Package versions for fresh source builds FREETYPE_VERSION=2.13.2 if [[ "$MB_ML_VER" != 2014 ]]; then - HARFBUZZ_VERSION=10.0.0 + HARFBUZZ_VERSION=10.0.1 else HARFBUZZ_VERSION=8.5.0 fi diff --git a/winbuild/build_prepare.py b/winbuild/build_prepare.py index db592d23c..84ad6417e 100644 --- a/winbuild/build_prepare.py +++ b/winbuild/build_prepare.py @@ -112,7 +112,7 @@ V = { "BROTLI": "1.1.0", "FREETYPE": "2.13.3", "FRIBIDI": "1.0.15", - "HARFBUZZ": "10.0.0", + "HARFBUZZ": "10.0.1", "JPEGTURBO": "3.0.4", "LCMS2": "2.16", "LIBPNG": "1.6.44", From 5d16eb73eb658daceb7b0af9f8d29cca96888a48 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 25 Sep 2024 19:07:32 +1000 Subject: [PATCH 16/16] Update CHANGES.rst [ci skip] --- CHANGES.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 4ab9eaf2b..ae7370a79 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,15 @@ Changelog (Pillow) 11.0.0 (unreleased) ------------------- +- Fixed writing multiple StripOffsets to TIFF #8317 + [Yay295, radarhere] + +- Shared imagequant libraries may be located within usr/lib64 #8407 + [radarhere] + +- Fix dereference before checking for NULL in ImagingTransformAffine #8398 + [PavlNekrasov] + - Use transposed size after opening for TIFF images #8390 [radarhere, homm]