Skip to content

Release 6.2.2.post11: restore four TIFF CVE fixes, complete CVE-2022-22817 (Python 2.7 line) - #42

Merged
icanhasmath merged 16 commits into
6.2.xfrom
6.2.2-security
Oct 22, 2026
Merged

icanhasmath merged 16 commits into
6.2.xfrom
6.2.2-security

Conversation

@ezequielp-activestate

@ezequielp-activestate ezequielp-activestate commented Oct 22, 2026 •

Copy link
Copy Markdown

Security release for the Python 2.7 Pillow 6.2.2 line. It restores four TIFF fixes that 6.2.2.7 removed by accident, completes the CVE-2022-22817 backport, and makes PIL.ImageMath importable on Python 2.7 again.

CVE Advisory Level Status
CVE-2020-35654 GHSA-vqcj-wrf2-7v73 High Patched again: upstream eb8c1206d
CVE-2021-25289 GHSA-57h3-9rgr-c24m Critical Patched again: upstream cbfdde7b1
CVE-2021-25290 GHSA-8xjq-8fcg-g5hw High Patched again: upstream e25be1e33
CVE-2021-25291 GHSA-mvg9-xffr-p774 High Patched again: upstream 8b8076bdc
CVE-2022-22817 GHSA-8vj2-vxx3-667w Critical Patched completely: upstream c930be075

Why the TIFF fixes were missing

6.2.2.4 to 6.2.2.6 shipped the four TIFF fixes. In 6.2.2.7, commit 6b86b9417 ("CVE-2020-10379 hard copy src/libImaging/TiffDecode.c from tag 7.1.0") replaced the whole file with Pillow 7.1.0's copy. That copy is older than the four fixes, so they disappeared. CHANGES.rst still listed them as fixed. 6.2.2.7 to 6.2.2.10 are affected.

Commits

  • TIFF decoder (9 commits): the upstream TiffDecode.c commits between 7.1.0 and 8.1.2, cherry-picked in order with -x. Besides the four CVE fixes, they include 45a62e91b (the ReadTile rework the CVE-2021-25289 fix builds on), a39d7c4fc (an out-of-bounds read fix), and two small warning and type fixes. From 3cabcf242 (MSYS2) only the TiffDecode.c part is taken; its macro only changes anything on Windows builds that define USE_WIN32_FILEIO. After these commits, TiffDecode.c is byte-identical to Pillow 8.1.2's, and the CVE-2020-10379 checks are still there. The crash images and test entries were already in the fork, so the test changes were dropped during the cherry-picks.
  • Restore Python 2.7 import of PIL.ImageMath: the CVE-2023-50447 backport (cb9af2f7c) added an f-string, so import PIL.ImageMath was a SyntaxError on 2.7. Its new test_prevent_builtins used exec(...), which is a statement on Python 2, so it now passes open instead.
  • CVE-2022-22817: the 6.2.2.x backport (1184cbf91) only had the Pillow 9.0.0 part, which checks the top-level co_names. Names inside a lambda sit in a nested code object, so (lambda: __import__('os').getcwd())() got through. This ports the 9.0.1 part, which also scans nested code objects. The upstream tests use exec; these use names that are valid on Python 2.
  • Test that every PIL module compiles (Tests/test_source_syntax.py): compiles each src/PIL/*.py with the running interpreter. On Python 2.7 it fails on Python 3-only syntax, so a backport like the 6.2.2.8 f-string can't ship unnoticed again. On 6.2.2.10 it fails on ImageMath.py only; on this branch all 92 modules pass.
  • Release 6.2.2.post11: version bump and CHANGES.rst entry. This is the first release on this line to use .postN versioning. 6.2.2.post11 sorts after 6.2.2+security.10.

Base branch

The 6.2.2.10 tag sits on security/cve-2024-28219 and was never merged into 6.2.x. This branch starts from that tag, so the PR also brings its three commits (the two 6.2.2.10 assessments and the release commit) into 6.2.x.

Validation

On ActiveState Python 2.7.18.14 (ActiveStateEnterpriseTesting/Core-Python-2.7), built against libtiff 4.5:

  • On this branch, import PIL.ImageMath works and ImageMath.eval("(lambda: __import__('os').getcwd())()") raises ValueError: '__import__' not allowed. On 6.2.2.10, the import is a SyntaxError.
  • test_tiff_crashes, test_file_tiff, test_file_libtiff, test_file_tiff_metadata and test_imagemath give 151 passed, 2 failed on this branch. On 6.2.2.10 (with only the f-string patched out so the tests can import) they give 150 passed, 3 failed. The two shared failures, test_string_dimension and test_custom_metadata, already fail on 6.2.2.10; the third is the exec test fixed here.
  • The new test_source_syntax passes for all 92 modules here, and fails on 6.2.2.10 for ImageMath.py only. That is the only module in 6.2.2.10 that doesn't compile on Python 2.7: import PIL, Image and the image plugins are unaffected.
  • With an AddressSanitizer build, none of the TIFF crash images (also tried zero-padded to get past the truncation checks) shows a memory error on either version. libtiff 4.5 or the fork's own checks reject them first. So the TIFF fixes rest on the code being identical to upstream's fixed file, not on a reproduced crash.

Tag 6.2.2.post11 and the GitHub release will follow the merge.

🤖 Generated with Claude Code

martinPavesio and others added 16 commits May 29, 2026 12:06
Version string: 6.2.2+security.10 (PEP 440 local identifier)
Git tag: 6.2.2.10

Security assessment entries for 2 CVEs:
- CVE-2026-42308: not applicable (function not in 6.2.2)
- GHSA-jgpv-4h4c-xhw3: already fixed in 6.2.x branch
(cherry picked from commit 21533e4)
(cherry picked from commit 3cabcf2, TiffDecode.c only; the MSYS2 setup.py and CI changes are not taken)
==3330==    at 0xBD4110C: _TIFFSetupFields (tif_dirinfo.c:327)

Passing in a stack allocated array is going to fail, as a reference
is retained to the name and used later when flushing the Tiff to
the file.

(cherry picked from commit a39d7c4)
* In some circumstances with some versions of libtiff (4.1.0+), there
  could be a 4 byte out of bound write when decoding a YCbCr tiff.
* The Pillow code dates to 6.0.0
* Found and reported through Tidelift

(cherry picked from commit eb8c120)
* Don't malloc for the swap line, just shuffle backwards
* Ensure that im->pixelsize is sanity checked
* Ensure that we're using the right size for the buffer from TiffReadRGBATile

(cherry picked from commit 45a62e9)
* since Pillow 8.1.0
* CVE-2021-25289

(cherry picked from commit cbfdde7)
* Caught by oss-fuzz runs
* CVE-2021-25290

(cherry picked from commit e25be1e)
* Invalid tile boundaries lead to OOB Read in TiffDecode.c, in TiffReadRGBATile
* Check the tile validity before attempting to read.

(cherry picked from commit 8b8076b)
The CVE-2023-50447 backport (cb9af2f) added an f-string to eval(), so
importing PIL.ImageMath raised SyntaxError on Python 2.7.
The 6.2.2.x backport of CVE-2022-22817 (1184cbf) carried only the
Pillow 9.0.0 part (8531b01), which checks the top-level co_names.
Names used inside a lambda live in a nested code object, so
"(lambda: __import__('os').getcwd())()" passed the check. Port
the 9.0.1 part (c930be0), which
scans nested code objects too. The tests use names valid on Python 2,
where exec is a statement.
On Python 2.7 this fails on Python 3-only syntax. It would have caught
the f-string that broke PIL.ImageMath from 6.2.2.8 to 6.2.2.10.

@icanhasmath icanhasmath left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review:

Requesting changes for one reason: the new version string. 6.2.2.post11 sorts below versions this line has already shipped, so anyone on an affected release won't be upgraded to it. Otherwise this is solid work. I checked the TIFF restore and the CVE-2022-22817 completion against upstream, and the ImageMath changes pass on Python 2.7.

Scope: I found no ticket for this release in Linear, and the PR links none. I judged scope against the advisories in the table. Question [importance 1 / effort 1]: is there a DE Release story for it? The table, the commits and the changelog all match. Nothing unrelated is folded in, apart from the three 6.2.2.10 commits, which the body explains. Two steps can only happen after the merge, and both must happen before this is closed: the tag and GitHub release, and the CVE-scanner override rows.

Impact:

  • 🔴 [importance 3 / effort 1] Version ordering (inline on src/PIL/_version.py:2 and CHANGES.rst:31). The __version__ strings this line has actually shipped are 6.2.2.1 (tags 6.2.2.4 and 6.2.2.5), 6.2.2.6 (tags 6.2.2.6 and 6.2.2.7), 6.2.2.8, then 6.2.2+security.9 and 6.2.2+security.10. Under PEP 440, 6.2.2.post11 < 6.2.2.1 … 6.2.2.8, because a fourth release segment outranks a post-release. I checked this with packaging.version. So someone on 6.2.2.8, which this PR lists as affected, gets nothing from pip install -U, and a resolver that can see both picks 6.2.2.8. The changelog's "sorts after 6.2.2+security.10" is true, but it covers only the last two releases. Suggestion: release as 6.2.2.11. It is valid PEP 440, sorts above all seven earlier strings, matches the tag series, and is what the scanner-override table's 4-component mapping would record anyway.
  • Checked and clean:
    • src/libImaging/TiffDecode.c at 3b701380 is byte-identical to upstream 8.1.2 (git diff 8.1.2 3b701380 is empty).
    • On Python 2.7.18.13, every one of the 92 src/PIL/*.py modules compiles at the head. At 6.2.2.10, only ImageMath.py:264 fails.
    • Tests/test_imagemath.py + Tests/test_source_syntax.py: 117 passed on 2.7, with the head's .py files over a prebuilt 6.2.2.8 _imaging.
    • Mutation check: with the co_consts recursion removed from ImageMath.py:275-282, test_prevent_exec fails, so the new lambda cases guard the fix.
    • Trial merge with #41 (setup.py only) is clean.
  • Not checked: the TIFF tests (test_tiff_crashes, test_file_tiff, test_file_libtiff, test_file_tiff_metadata). I had no libtiff headers to build the C extension, so for the TIFF fixes I rely on the byte-identity above and your results. Also not checked: a Windows build, or an ASan run.
  • ⚪ [importance 1 / effort 1] The body says the crash images "were already in the fork". Tests/images/crash-2020-10-test.tif wasn't. Tests/test_tiff_crashes.py:26 on 6.2.x refers to it, but the file is missing there. The cherry-pick of eb8c1206d (a4229c0c) adds it back, so that test case now has its image again. The code is fine; only the body's wording is off.

Security: The fix is right, and the regression test proves it. scan() recurses into nested code objects, as upstream 9.0.1 does. On 2.7, (lambda: __import__('os').getcwd())() gets through the old top-level-only check and is blocked by the new one. ⚪ [importance 1 / effort 1] FYI only: ImageMath.py:286 still passes {"__builtins": …} (missing the trailing __) as globals, so builtins are not stripped at eval time and the name scan is the only gate. Upstream 9.0.1 and 10.2.0 have the same line, so this PR is at parity with upstream. No change needed here.

Duplication: None. test_source_syntax.py is new, and nothing else in Tests/ compiles every module.

Infrastructure: None touched.

Comment thread src/PIL/_version.py Resolved
Comment thread CHANGES.rst Resolved

@icanhasmath icanhasmath left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review: (re-review at 3b70138. This supersedes my review 5619401861, CHANGES_REQUESTED at 3b70138.)

Approving. I'm withdrawing the 6.2.2.post11 version-ordering finding from my earlier review: it's not a concern for this line. Please disregard its two inline comments on src/PIL/_version.py:2 and CHANGES.rst:31-32. That leaves no blockers. Since that review, I've also tested the TIFF fixes against a real libtiff. They fix a crash that 6.2.2.10 has.

Scope: Unchanged from my earlier review. The commits match the advisory table, and nothing unrelated is folded in. The tag, the GitHub release and the CVE-scanner override rows come after the merge, and must happen before this is closed.

Impact, TIFF. I built both the head and 6.2.2.10 against libtiff 4.7.2 (as-builds/production/shared/tiff/4.7.2/8) on Python 2.7.18.13, once normally and once with AddressSanitizer:

  • CVE-2021-25290 reproduced on 6.2.2.10 and fixed here. Six of the fork's own crash images (crash-0c7e0e8e…, crash-1185209c…, crash-338516db…, crash-4f085cc1…, crash-86214e58…, crash-f46f5b2f…) are the trigger. Opened from io.BytesIO, 6.2.2.10 hits AddressSanitizer: negative-size-param (size=-780) in _tiffReadProc (TiffDecode.c:42). Without ASan, it segfaulted in 17 of 30 runs. At this head, all six are rejected cleanly with IOError -2, with 0 crashes in 30 runs. The fix is the loc > eof guard from 48837f5d. libtiff 4.7.2's _TIFFmemcpy calls memcpy without checking the length, so libtiff doesn't stop this itself.
  • Why "no memory error" showed up in the PR's validation: opened by path, Pillow 6.2.2 hands libtiff the file descriptor, and _tiffReadProc never runs. By path, none of the images shows an error on either version. ⚪ [importance 1 / effort 1] Worth correcting the Validation section of the PR body.
  • TIFF suites (test_tiff_crashes, test_file_tiff, test_file_libtiff, test_file_tiff_metadata): 127 passed, 1 failed, 2 skipped at this head. 6.2.2.10 (with only the f-string patched so it imports) gives 126 passed, 2 failed. The failure they share is test_string_dimension. test_custom_metadata fails on 6.2.2.10 and passes here, which fits the 4622c7e6 readcount fix.
  • Not reproduced: CVE-2020-35654, CVE-2021-25289 and CVE-2021-25291. Their upstream images (crash-2020-10-test.tif, crash_1/2.tif, crash-63b1dffe…) never reach TiffDecode.c, because 6.2.2's TiffImagePlugin rejects them with unknown data organization. I also generated 468 valid YCbCr TIFFs (subsampling 1–4, odd sizes, strips and tiles, deflate). None gave an ASan error on either version, from a path or from BytesIO. The head reads every one 6.2.2.10 reads, and 4 that 6.2.2.10 rejects with -9 (out of memory). For these three CVEs, the evidence is still that TiffDecode.c is byte-identical to upstream 8.1.2.
  • 🟡 [importance 2 / effort 1] The test suite doesn't guard the 25290 fix. Tests/test_tiff_crashes.py:40-45 opens by path and treats any IOError as a pass, so it never runs _tiffReadProc. Revert 48837f5d and the suite stays green. The same handler hid the missing crash-2020-10-test.tif on 6.2.x, where its test case passed. Follow-up: PROD-1289. It doesn't hold this PR.

Impact, Python: Unchanged from my earlier review. On 2.7, test_imagemath and test_source_syntax give 117 passed. With the nested-lambda scan removed, test_prevent_exec fails.

Security: The CVE-2022-22817 completion is right, and the CVE-2021-25290 fix is now shown against a real crash (above). ⚪ [importance 1 / effort 1] ImageMath.py:286's "__builtins" globals key is the same as upstream 9.0.1 and 10.2.0. For information only.

Duplication: None.

Infrastructure: None.

@icanhasmath
icanhasmath merged commit c2f73a9 into 6.2.x Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants