CVE-2026-31826: pypdf Memory Exhaustion Vulnerability Due to Manipulated Stream Lengths

pypdf Updated 13 Mar 2026

Summary

11/03/2026
Yes i
Moderate
6.8

CVE-2026-31826: pypdf: manipulated stream length values can exhaust RAM. Affects pypdf versions < 6.8.0. Fixed in 6.8.0. How to fix ↓

Free scan

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.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored MarkAI Find prospects already talking about the problem you solve AI watches the communities your customers use to find qualified prospects, then alerts you when a conversation is worth joining. See MarkAI

Background

pypdf is a Python library designed for reading and manipulating PDF files. It provides functionalities such as extracting text, merging documents, and modifying PDF content. However, it is vulnerable to a specific issue where an attacker can craft a PDF file that leads to excessive memory usage, potentially exhausting system resources.

Vulnerability Detail

The vulnerability arises from the handling of content streams in PDF files, specifically when a stream has a manipulated '/Length' value that does not correspond to the actual data length. This can lead to significant memory consumption when parsing such streams, making the application susceptible to denial-of-service attacks. Attackers can exploit this vulnerability by creating specially crafted PDF files that cause the pypdf library to allocate large amounts of memory, which can lead to application crashes or slowdowns.

How To Fix

Latest published version: 6.21.2 as of 22 Oct 2026

pip install --upgrade "pypdf==6.21.2"

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

6.8.0

This is the first release that contains the fix.

pip install --upgrade "pypdf==6.8.0"

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Workaround

If upgrading is not immediately possible, you can apply the changes from pull request #3675 on GitHub. This involves modifying the way pypdf handles content streams to mitigate the risk of memory exhaustion. Alternatively, avoid reading from buffers of unknown size, such as those returned by open('file.pdf', mode='rb'). Instead, use a file path or a BytesIO buffer to prevent triggering the vulnerability.

Conclusion

CVE-2026-31826 represents a significant vulnerability in the pypdf library, allowing for potential memory exhaustion through crafted PDF files. Users are encouraged to update to the latest version to protect their applications from this risk. For those unable to upgrade immediately, workarounds are available to mitigate the threat.

See every vulnerability recorded for pypdf →

Share this vulnerability

FAQ

CVE-2026-31826 is a vulnerability in the pypdf library that allows attackers to craft PDF files with manipulated stream lengths, leading to excessive memory usage.

You can check if your application is affected by using Vulert, which monitors and alerts for open-source vulnerabilities in real-time. You can also use the Vulert playground without signup to test your application.

Exploiting this vulnerability can lead to denial-of-service conditions, where the application consumes excessive memory, potentially crashing or slowing down the system.

Yes, the vulnerability has been patched in pypdf version 6.8.0. It is recommended to upgrade to this version to mitigate the risk.

If you cannot upgrade, consider applying the changes from pull request #3675 or avoid reading from buffers of unknown size to reduce the risk of exploitation.

Related vulnerabilities

Recent vulnerabilities recorded for pypdf.

How To Fix

Latest published version: 6.21.2 as of 22 Oct 2026

pip install --upgrade "pypdf==6.21.2"

Upgrading to it may include breaking changes; the version below is the minimum fixed release for this vulnerability.

If you need the minimum change

6.8.0

This is the first release that contains the fix.

pip install --upgrade "pypdf==6.8.0"

Tip — Not sure which version your app runs? Vulert can match this fix to it. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback