CVE-2022-24859
JSON

6.2medium

Manipulated inline images can cause Infinite Loop in PyPDF2

Severity
6.2medium CVSS:3.1 by GitHub_M
Exploit likelihood
1.33% (higher than 71% of CVEs; EPSS, by FIRST)
Published
Last changed
Assigned by
GitHub_M
Also known as
GHSA-xcjx-m2pj-8g79PYSEC-2022-194

Description

PyPDF2 is an open source python PDF library capable of splitting, merging, cropping, and transforming the pages of PDF files. In versions prior to 1.27.5 an attacker who uses this vulnerability can craft a PDF which leads to an infinite loop if the PyPDF2 if the code attempts to get the content stream. The reason is that the last while-loop in `ContentStream._readInlineImage` only terminates when it finds the `EI` token, but never actually checks if the stream has already ended. This issue has been resolved in version `1.27.5`. Users unable to upgrade should validate and PDFs prior to iterating over their content stream.

Affected

Product or packageVersionsReported by
py-pdf PyPDF2< 1.27.5CVE List
pypdf2 (PyPI)before 1.27.5GitHub Advisory Database, PyPA Advisory Database
pypdf2_project pypdf2before 1.27.5NVD
debian debian_linux9.0NVD

All scores

GitHub_M6.2medium CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
GitHub6.2medium CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H
GitHubmedium CVSS:4.0CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:A/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N
NVD5.5medium CVSS:3.1CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H
NVD4.3medium CVSS:2.0AV:N/AC:M/Au:N/C:N/I:N/A:P

Classification

CWE-835

SSVC (CISA-ADP): exploitation poc, automatable no, technical impact partial.

What each source says

CVE List

PyPDF2 is an open source python PDF library capable of splitting, merging, cropping, and transforming the pages of PDF files. In versions prior to 1.27.5 an attacker who uses this vulnerability can craft a PDF which leads to an infinite loop if the PyPDF2 if the code attempts to get the content stream. The reason is that the last while-loop in `ContentStream._readInlineImage` only terminates when it finds the `EI` token, but never actually checks if the stream has already ended. This issue has been resolved in version `1.27.5`. Users unable to upgrade should validate and PDFs prior to iterating over their content stream.

GitHub Advisory Database
Impact

An attacker who uses this vulnerability can craft a PDF which leads to an infinite loop if the PyPDF2 user wrote the following code:

from PyPDF2 import PdfFileReader, PdfFileWriter
from PyPDF2.pdf import ContentStream

reader = PdfFileReader("malicious.pdf", strict=False)
for page in reader.pages:
    ContentStream(page.getContents(), reader)
Patches

PyPDF2==1.27.5 and later are patched.

Credits to Sebastian Krause for finding (issue) and fixing (PR) it.

NVD (es)

PyPDF2 es una librería PDF de código abierto capaz de dividir, fusionar, recortar y transformar las páginas de los archivos PDF. En versiones anteriores a 1.27.5 un atacante que use esta vulnerabilidad puede diseñar un PDF que conlleva a un bucle infinito si el código de PyPDF2 intenta conseguir el flujo de contenido. La razón es que el último bucle while en "ContentStream._readInlineImage" sólo termina cuando encuentra el token "EI", pero nunca comprueba si el flujo ya ha terminado. Este problema ha sido resuelto en versión "1.27.5". Los usuarios que no puedan actualizarse deberán comprobar y PDFs antes de iterar sobre su flujo de contenido

References

Sources

SourceRecordLicence
CVE ListCVE-2022-24859 changed 2025-04-22CVE Terms of Use
GitHub Advisory DatabaseGHSA-xcjx-m2pj-8g79 changed 2024-10-14CC-BY-4.0
NVDCVE-2022-24859 changed 2026-06-17Public domain
PyPA Advisory DatabasePYSEC-2022-194 changed 2023-11-08CC-BY-4.0