VAITP Dataset

← Back to the dataset

CVE-2007-1657

Buffer overflow in Python 2.5 minigzip allows arbitrary code execution via long file argument

  • CVSS 7.5
  • CWE-119: Improper Restriction of Operations within the Bounds of a Memory Buffer
  • Memory Corruption
  • Remote

Stack-based buffer overflow in the file_compress function in minigzip (Modules/zlib) in Python 2.5 allows context-dependent attackers to execute arbitrary code via a long file argument.

CVSS base score
7.5
Published
2007-03-24
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Function
Code defect classification
Incorrect Functionality
Category
Memory Corruption
Subcategory
Buffer Overflows
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
Python 2.5
Fixed by upgrading
Yes

Solution

Update Python to version 2.5.6 or higher.

Vulnerable code sample

import zlib

def vulnerable_file_compress(file_path):
    with open(file_path, 'rb') as f:
        data = f.read()  # No size limit, potential for buffer overflow
        compressed_data = zlib.compress(data)
    return compressed_data

# Example usage
compressed = vulnerable_file_compress('path/to/input/file')

Patched code sample

import zlib

def safe_file_compress(file_path):
    # Limit the maximum size of the input to prevent buffer overflow
    max_size = 2**20  # 1 MB for example
    with open(file_path, 'rb') as f:
        data = f.read(max_size)
        if len(data) >= max_size:
            raise ValueError("Input file is too large.")
        compressed_data = zlib.compress(data)
    return compressed_data

# Example usage
try:
    compressed = safe_file_compress('path/to/input/file')
except ValueError as e:
    print(e)

Cite this entry

@misc{vaitp:cve20071657,
  title        = {{Buffer overflow in Python 2.5 minigzip allows arbitrary code execution via long file argument}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2007},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2007-1657},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2007-1657/}}
}

Download this entry as JSON Download the whole dataset

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 ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.