CVE-2023-31146
Out-of-bounds array access in Vyper (before version 0.3.8)
- CVSS 9.1
- CWE-787
- Memory Corruption
- Remote
Vyper is a Pythonic smart contract language for the Ethereum virtual machine. Prior to version 0.3.8, during codegen, the length word of a dynarray is written before the data, which can result in out-of-bounds array access in the case where the dynarray is on both the lhs and rhs of an assignment. The issue can cause data corruption across call frames. The expected behavior is to revert due to out-of-bounds array access. Version 0.3.8 contains a patch for this issue.
- CWE
- CWE-787
- CVSS base score
- 9.1
- Published
- 2023-05-11
- OWASP
- A03 Injection
- Orthogonal defect classification
- Algorithm
- Code defect classification
- Incorrect Algorithm
- Category
- Memory Corruption
- Subcategory
- Out-of-Bound Accesses
- Accessibility scope
- Remote
- Impact
- Arbitrary Code Execution
- Fixed by upgrading
- Yes
Solution
Update to Vyper version 0.3.8 or higher
Vulnerable code sample
class DynamicArray:
def __init__(self):
self.data = []
def append(self, value):
self.data.append(value)
def get(self, index):
return self.data[index]
def set(self, index, value):
self.data[index] = value
array = DynamicArray()
array.append(1)
array.append(2)
array.set(2, 3)
print(array.get(2))Patched code sample
class DynamicArray:
def __init__(self):
self.data = []
def append(self, value):
self.data.append(value)
def get(self, index):
if index < 0 or index >= len(self.data):
raise IndexError("Array index out of bounds")
return self.data[index]
def set(self, index, value):
if index < 0 or index >= len(self.data):
raise IndexError("Array index out of bounds")
self.data[index] = value
array = DynamicArray()
array.append(1)
array.append(2)
try:
array.set(2, 3)
print(array.get(2))
except IndexError as e:
print(e)Cite this entry
@misc{vaitp:cve202331146,
title = {{Out-of-bounds array access in Vyper (before version 0.3.8) }},
author = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
year = {2023},
note = {VAITP Python Vulnerability Dataset, entry CVE-2023-31146},
howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2023-31146/}}
}
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 ::
