Buffer Overflow in Python 3.x through 3.9.1

python3 Updated 02 Oct 2025

Summary

19/01/2021
N/A
Yes i
Critical
9.8

CVE-2021-3177: Python 3.x through 3.9.1 has a buffer overflow in PyCArg_repr in _ctypes/callproc.c, which may lead to remote code execution in certain Python applications that accept floating-point numbers as untrusted input, as demons... Affects python3 across 5 version ranges.

>= 1bf9cc509326bc42cd8cb1650eb9bf64550d817e, <= 13c94747c74437e594b7fc242ff7da668e81887c < 3.7.7-r2 >= 5c4568a05a0a62b5947c55f68f9f2ecfb90a4f12, <= c0a9afe2ac1820409e6173bd1893ebee2cf50270 >= 9cf6752276e6fcfd0c23fdb064ad27f448aaaf75, <= 1e5d33e9b9b8631b36f061103a30208b206fd03a >= fa919fdf2583bdfead1df00e842f24f30b2a34bf, <= 6503f05dd59e26a9986bdea097b3da9b3546f45b

Fixed in 3.7.7-r2. 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 Devnack Your last release was probably never penetration tested Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

Python is a popular programming language known for its simplicity and versatility. It is widely used for various applications, including web development, data analysis, and artificial intelligence. Python 3.x is the latest major version of Python, with version 3.9.1 being the most recent release. However, this version is vulnerable to a buffer overflow in the PyCArg_repr function in the _ctypes/callproc.c file. This vulnerability can be exploited by providing a large floating-point number as input to certain Python applications, potentially leading to remote code execution. The vulnerability arises due to the unsafe usage of the sprintf function.

Vulnerability Detail

The buffer overflow vulnerability, identified as CVE-2021-3177, affects Python 3.x through 3.9.1. By supplying a floating-point number, such as 1e300, as untrusted input to Python applications that accept such values, an attacker can trigger the buffer overflow. This can result in the execution of arbitrary code within the context of the affected application. The vulnerability has a CVSS score of 9.8, indicating its high severity. It is crucial to address this vulnerability promptly to prevent potential remote code execution and unauthorized access to systems.

How To Fix

Minimum fixed version

3.7.7-r2

This is the first release that contains the fix.

sudo apk add --upgrade python3

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

Workaround

As a temporary workaround, developers can validate and sanitize user input to prevent the exploitation of this vulnerability. By implementing input validation and limiting the range of acceptable floating-point numbers, the risk of buffer overflow can be mitigated. Here is an example of how input validation can be performed in Python:

def process_input(input_value):
    try:
        float_value = float(input_value)
        if float_value > 1e100:
            raise ValueError('Input value exceeds the allowed range.')
        # Process the input
    except ValueError as e:
        print('Invalid input:', str(e))

Conclusion

The buffer overflow vulnerability in Python 3.x through 3.9.1 poses a significant risk to applications that accept floating-point numbers as untrusted input. It is crucial to update Python installations to the latest available version within the 3.x series, starting from version 3.7.7-r2, to address this vulnerability. Additionally, implementing input validation and range checks can provide temporary mitigation until the update is applied. For further assistance and support in vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for python3 →

Share this vulnerability

FAQ

The vulnerability allows an attacker to execute arbitrary code remotely, potentially leading to unauthorized access, data breaches, and system compromise.

Python 3.x through 3.9.1 are affected by this vulnerability.

Yes, the vulnerability can be fixed by updating Python to version 3.7.7-r2 or later within the 3.x series.

Yes, implementing input validation and limiting the range of acceptable floating-point numbers can help mitigate the risk until the Python installation is updated.

The CVSS score of this vulnerability is 9.8, indicating its high severity.

Related vulnerabilities

Recent vulnerabilities recorded for python3.

How To Fix

Minimum fixed version

3.7.7-r2

This is the first release that contains the fix.

sudo apk add --upgrade python3

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