CVE-2022-24859: PyPDF2 - Infinite Loop Vulnerability
Summary
CVE-2022-24859: Manipulated inline images can cause Infinite Loop in PyPDF2. Affects pypdf2 versions < 1.27.5. Fixed in 1.27.5. How to fix ↓
Also tracked for
- pypdf2 · Debian:11
The same CVE-2022-24859 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
PyPDF2 is a Python library for working with PDF files. It provides functionality to read, write, and manipulate PDF documents. The library is widely used for tasks such as extracting text, merging multiple PDFs, and adding annotations. PyPDF2 is vulnerable to an infinite loop issue that can be triggered by manipulating inline images in a PDF file.
Vulnerability Detail
The vulnerability in PyPDF2 allows an attacker to craft a malicious PDF file that can cause an infinite loop when processed by the library. If a PyPDF2 user attempts to extract the contents of the PDF using the PdfFileReader class and iterates over the pages, an infinite loop can occur if the page contains manipulated inline images. This can lead to resource exhaustion and denial of service. The vulnerability has a CVSS score of 6.2 (Moderate).
How To Fix
Latest published version: 3.0.1 as of 23 Oct 2026
pip install --upgrade "pypdf2==3.0.1"
Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.
If you need the minimum change
1.27.5
This is the first release that contains the fix.
pip install --upgrade "pypdf2==1.27.5"
Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →
Workaround
If updating PyPDF2 is not immediately possible, a workaround is to avoid processing PDF files with manipulated inline images. This can be achieved by checking the contents of each page before processing it. Here is an example of how to implement this workaround in Python:
from PyPDF2 import PdfFileReader, ContentStream
def process_pdf(file_path):
reader = PdfFileReader(file_path, strict=False)
for page in reader.pages:
contents = page.getContents()
if not contains_manipulated_images(contents):
ContentStream(contents, reader)
def contains_manipulated_images(contents):
# Check if the contents contain manipulated inline images
# Return True if manipulated images are found, False otherwise
pass
In this example, the contains_manipulated_images function should be implemented to analyze the contents of a page and determine if it contains manipulated inline images. If no manipulated images are found, the page can be processed safely.
Conclusion
The PyPDF2 library is vulnerable to an infinite loop issue that can be triggered by manipulated inline images in a PDF file. To mitigate this vulnerability, it is recommended to update PyPDF2 to version 1.27.5 or later. If immediate updating is not possible, a workaround is available by checking the contents of each page for manipulated images. For further assistance and support on vulnerability remediation, please contact DevNack.com.
See every vulnerability recorded for pypdf2 →
FAQ
PyPDF2 is a Python library for working with PDF files. It provides functionality to read, write, and manipulate PDF documents.
An attacker can craft a malicious PDF file that triggers an infinite loop in PyPDF2, leading to resource exhaustion and denial of service.
Update PyPDF2 to version 1.27.5 or later. This version includes a patch for the infinite loop issue.
If updating PyPDF2 is not immediately possible, you can implement a workaround by checking the contents of each page for manipulated inline images before processing them.
The vulnerability was discovered by Sebastian Krause and reported in the PyPDF2 GitHub repository. It was fixed in PyPDF2 version 1.27.5.
References
Related vulnerabilities
Recent vulnerabilities recorded for pypdf2.