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 package | Versions | Reported by |
|---|---|---|
| py-pdf PyPDF2 | < 1.27.5 | CVE List |
| pypdf2 (PyPI) | before 1.27.5 | GitHub Advisory Database, PyPA Advisory Database |
| pypdf2_project pypdf2 | before 1.27.5 | NVD |
| debian debian_linux | 9.0 | NVD |
All scores
| GitHub_M | 6.2medium CVSS:3.1 | CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H |
| GitHub | 6.2medium CVSS:3.1 | CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H |
| GitHub | medium CVSS:4.0 | CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:A/VC:N/VI:N/VA:H/SC:N/SI:N/SA:N |
| NVD | 5.5medium CVSS:3.1 | CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:N/I:N/A:H |
| NVD | 4.3medium CVSS:2.0 | AV:N/AC:M/Au:N/C:N/I:N/A:P |
Classification
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
| https://github.com/py-pdf/PyPDF2/security/advisories/GHSA-xcjx-m2pj-8g79 | advisory, exploit, third-party-advisory, web | |
| https://github.com/py-pdf/PyPDF2/issues/329 | exploit, report, third-party-advisory, web | |
| https://github.com/py-pdf/PyPDF2/pull/740 | patch, third-party-advisory, web | |
| https://github.com/py-pdf/PyPDF2/releases/tag/1.27.5 | release-notes, third-party-advisory, web | |
| https://lists.debian.org/debian-lts-announce/2022/06/msg00001.html | mailing-list, third-party-advisory, web | |
| https://lists.debian.org/debian-lts-announce/2023/06/msg00013.html | mailing-list, web | |
| https://nvd.nist.gov/vuln/detail/CVE-2022-24859 | advisory | |
| https://github.com/py-pdf/PyPDF2 | package | |
| https://github.com/pypa/advisory-database/tree/main/vulns/pypdf2/PYSEC-2022-194.yaml | web | |
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2022-24859 changed 2025-04-22 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-xcjx-m2pj-8g79 changed 2024-10-14 | CC-BY-4.0 |
| NVD | CVE-2022-24859 changed 2026-06-17 | Public domain |
| PyPA Advisory Database | PYSEC-2022-194 changed 2023-11-08 | CC-BY-4.0 |