CVE-2016-5636
Integer Overflow in zipimport.c in CPython
- CVSS 9.8
- CWE-190: Integer Overflow or Wraparound
- Numeric Errors
- Remote
Integer overflow in the get_data function in zipimport.c in CPython (aka Python) before 2.7.12, 3.x before 3.4.5, and 3.5.x before 3.5.2 allows remote attackers to have unspecified impact via a negative data size value, which triggers a heap-based buffer overflow.
- CVSS base score
- 9.8
- Published
- 2016-09-02
- OWASP
- A08 Software and Data Integrity Failures
- Orthogonal defect classification
- Algorithm
- Code defect classification
- Incorrect Algorithm
- Category
- Numeric Errors
- Subcategory
- Integer Overflows
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Fixed by upgrading
- Yes
Solution
Update Python to version 2.7.12, 3.4.5, or 3.5.2 or later.
Vulnerable code sample
import zipfile
class ZipFile:
def __init__(self, file):
self.zip_file = zipfile.ZipFile(file)
def get_data(self, name):
info = self.zip_file.getinfo(name)
return self.zip_file.read(name)
if __name__ == "__main__":
zip = ZipFile('example.zip')
data = zip.get_data('somefile.txt')
print(data)Patched code sample
import zipfile
class ZipFile:
def __init__(self, file):
self.zip_file = zipfile.ZipFile(file)
def get_data(self, name):
info = self.zip_file.getinfo(name)
if info.file_size < 0:
raise ValueError("Invalid file size detected, potential integer overflow.")
return self.zip_file.read(name)
if __name__ == "__main__":
try:
zip = ZipFile('example.zip')
data = zip.get_data('somefile.txt')
print(data)
except ValueError as e:
print("Error:", e)Cite this entry
@misc{vaitp:cve20165636,
title = {{Integer Overflow in zipimport.c in CPython}},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2016},
note = {VAITP Python Vulnerability Dataset, entry CVE-2016-5636},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2016-5636/}}
}
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 ::
