CVE-2021-40839: rencode Package Infinite Loop Denial of Service

rencode Updated 02 Oct 2025

Summary

10/09/2021
Yes i
High
7.5

CVE-2021-40839: The rencode package through 1.0.6 for Python allows an infinite loop in typecode decoding (such as via ;\x2f\x7f), enabling a remote attack that consumes CPU and memory. Affects rencode versions < 572ff74586d9b1daab904c6f7f7009ce0143bb75. Fixed in 572ff74586d9b1daab904c6f7f7009ce0143bb75. How to fix ↓

Also tracked for

The same CVE-2021-40839 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.

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

Sponsored Devnack Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

The rencode package is a Python library that provides encoding and decoding functions for the Rencode serialization format. It is commonly used for data serialization and deserialization in various Python applications. The package allows users to encode Python objects into a compact binary format and decode them back into their original form. However, versions of rencode up to 1.0.6 are vulnerable to an infinite loop denial of service (DoS) attack when decoding certain typecodes. This vulnerability can be exploited remotely, leading to excessive CPU and memory consumption, potentially impacting the availability and performance of the affected application.

Vulnerability Detail

The vulnerability in the rencode package arises from a flaw in the typecode decoding process. An attacker can craft a malicious input, such as the sequence ';\x2f\x7f', which triggers an infinite loop during the decoding process. This results in the consumption of excessive CPU and memory resources, leading to a denial of service condition. The impact of this vulnerability can range from degraded performance to complete unavailability of the affected application. It is important to note that this vulnerability can be exploited remotely without requiring any authentication.

How To Fix

Minimum fixed version

572ff74586d9b1daab904c6f7f7009ce0143bb75

This is the first release that contains the fix.

pip install --upgrade "rencode==572ff74586d9b1daab904c6f7f7009ce0143bb75"

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

Workaround

As a temporary workaround, users can consider implementing input validation and sanitization mechanisms to filter out potentially malicious input. This can help mitigate the risk of exploitation until the package is updated to a fixed version. Here is an example of input validation using regular expressions in Python:

import re

def validate_input(input):
pattern = re.compile(r'^[a-zA-Z0-9]+$')
if pattern.match(input):
        return True
else:
        return False

Conclusion

The rencode package up to version 1.0.6 is vulnerable to an infinite loop denial of service attack. This can be exploited remotely, causing excessive CPU and memory consumption. To mitigate this vulnerability, it is crucial to update the rencode package to version 1.0.7 or later. Additionally, implementing input validation and sanitization mechanisms can provide temporary protection. For further assistance and support in vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for rencode →

Share this vulnerability

FAQ

The rencode package is a Python library used for encoding and decoding data in the Rencode serialization format. It provides a compact binary representation of Python objects.

The vulnerability allows an attacker to trigger an infinite loop in the typecode decoding process, leading to excessive CPU and memory consumption. This can result in a denial of service condition, impacting the availability and performance of the affected application.

Yes, this vulnerability can be exploited remotely without requiring any authentication.

Yes, a fix has been released in rencode version 1.0.7. Users are advised to update their dependencies to the latest version to mitigate the risk.

As a temporary workaround, users can implement input validation and sanitization mechanisms to filter out potentially malicious input. However, updating to the fixed version is the recommended solution.

How To Fix

Minimum fixed version

572ff74586d9b1daab904c6f7f7009ce0143bb75

This is the first release that contains the fix.

pip install --upgrade "rencode==572ff74586d9b1daab904c6f7f7009ce0143bb75"

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

Follow Vulert in Google

Get more Vulert vulnerability and dependency-security updates in Google Search and AI results.