VAITP Dataset

← Back to the dataset

CVE-2024-26149

Array index overflow in Vyper's `_abi_decode` can lead to exploits.

  • CVSS 5.3
  • CWE-119 Improper Restriction of Operations within the Bounds of a Memory Buffer
  • Input Validation and Sanitization
  • Remote

Vyper is a pythonic Smart Contract Language for the ethereum virtual machine. If an excessively large value is specified as the starting index for an array in `_abi_decode`, it can cause the read position to overflow. This results in the decoding of values outside the intended array bounds, potentially leading to exploitations in contracts that use arrays within `_abi_decode`. This vulnerability affects 0.3.10 and earlier versions.

CVSS base score
5.3
Published
2024-02-26
OWASP
A01 Broken Access Control
Orthogonal defect classification
Algorithm
Code defect classification
Incorrect Algorithm
Category
Input Validation and Sanitization
Subcategory
Integer Overflows
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
Vyper
Fixed by upgrading
Yes

Solution

Upgrade to Vyper version 0.3.11 or later to mitigate the vulnerability.

Vulnerable code sample

def abi_decode(data, start_index, length):
    return data[start_index:start_index + length]

data = [1, 2, 3, 4, 5]
start_index = 2**32
length = 3
decoded_values = abi_decode(data, start_index, length)
print(decoded_values)

Patched code sample

def abi_decode(data, start_index, length):
    if start_index < 0 or start_index + length > len(data):
        raise ValueError("Invalid start index or length for decoding.")
    return data[start_index:start_index + length]

data = [1, 2, 3, 4, 5]
start_index = 2**32
length = 3
decoded_values = abi_decode(data, start_index, length)
print(decoded_values)

Published fix

Public sources link this CVE to the changes below. The code samples above were generated to illustrate the defect; these links lead to the code the project actually changed.

  • fix[codegen]: fix `_abi_decode` buffer overflow (vyperlang/vyper)
    vyper/builtins/functions.py, vyper/builtins/functions.py · ABIDecode.build_IR, vyper/builtins/functions.py · Slice.build_IR, vyper/builtins/functions.py · _build_adhoc_slice_node, vyper/codegen/core.py, vyper/codegen/core.py · clamp_bytestring, vyper/codegen/core.py · clamp_dyn_array, vyper/codegen/core.py · make_setter, vyper/codegen/core.py · _complex_make_setter, vyper/codegen/core.py · _dynarray_make_setter, vyper/codegen/core.py · _getelemptr_abi_helper, vyper/codegen/core.py · _get_element_ptr_tuplelike and 1 more
  • fix[codegen]: zero-length dynarray `abi_decode` validation (vyperlang/vyper)
    vyper/codegen/core.py · clamp_dyn_array, vyper/codegen/core.py · _abi_payload_size
  • fix[codegen]: recursive dynarray oob check (vyperlang/vyper)
    vyper/builtins/functions.py · ABIDecode.build_IR, vyper/codegen/core.py · make_setter, vyper/codegen/core.py · _abi_payload_size, vyper/codegen/external_call.py · _unpack_returndata, vyper/codegen/function_definitions/external_function.py · _generate_kwarg_handlers
  • fix[codegen]: add back in `returndatasize` check (vyperlang/vyper)
    vyper/abi_types.py, vyper/codegen/external_call.py · _unpack_returndata

Payload

data = [1, 2, 3, 4, 5]  # Example data array
start_index = 2**32  # Excessively large index to trigger overflow
length = 10  # Length that exceeds the data array bounds

Cite this entry

@misc{vaitp:cve202426149,
  title        = {{Array index overflow in Vyper's `_abi_decode` can lead to exploits.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2024},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2024-26149},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2024-26149/}}
}

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.