CVE-2023-36810
PyPDF quadratic runtime vulnerability
- CVSS 6.5
- CWE-407 Inefficient Algorithmic Complexity
- Resource Management
- Remote
pypdf is a pure-python PDF library capable of splitting, merging, cropping, and transforming the pages of PDF files. An attacker who uses this vulnerability can craft a PDF which leads to unexpected long runtime. This quadratic runtime blocks the current process and can utilize a single core of the CPU by 100%. It does not affect memory usage. This issue has been addressed in PR 808 and versions from 1.27.9 include this fix. Users are advised to upgrade. There are no known workarounds for this vulnerability.
- CVSS base score
- 6.5
- Published
- 2023-06-30
- OWASP
- A06 Vulnerable and Outdated Components
- Orthogonal defect classification
- Timing/Serialization
- Code defect classification
- Timing Issues
- Category
- Resource Management
- Subcategory
- Resource Exhaustion
- Accessibility scope
- Remote
- Impact
- Denial of Service (DoS)
- Fixed by upgrading
- Yes
Solution
Update pypdf to version 1.27.9 or higher.
Vulnerable code sample
import pypdf
def pdf_processing(pdf_path):
with open(pdf_path, "rb") as file:
reader = pypdf.PdfReader(file)
for i in range(len(reader.pages)):
for j in range(len(reader.pages)):
page = reader.pages[i]
text = page.extract_text()
print(text)
pdf_processing("example.pdf")Patched code sample
import pypdf
def pdf_processing(pdf_path):
try:
with open(pdf_path, "rb") as file:
reader = pypdf.PdfReader(file)
for i, page in enumerate(reader.pages):
try:
text = page.extract_text()
if text:
print(f"Page {i + 1}:\n{text}")
else:
print(f"Page {i + 1}: No text found.")
except Exception as e:
print(f"Error extracting text from page {i + 1}: {e}")
except (FileNotFoundError, IOError) as file_error:
print(f"File error: {file_error}")
except Exception as e:
print(f"Failed to process PDF: {e}")Cite this entry
@misc{vaitp:cve202336810,
title = {{PyPDF quadratic runtime vulnerability}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2023},
note = {VAITP Python Vulnerability Dataset, entry CVE-2023-36810},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2023-36810/}}
}
Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.
The supreme art of war is to subdue the enemy without fighting.
Sun Tzu – “The Art of War”
:: Shaping the future through research and ingenuity ::
