CVE-2025-54070: OpenZeppelin Contracts lastIndexOf Function Vulnerability Leading to Out-of-Bound Memory Access

@openzeppelin/contracts Updated 02 Oct 2025

Summary

17/07/2025
Yes i
Moderate
0.0

CVE-2025-54070: Impact The lastIndexOf(bytes,byte,uint256) function of the Bytes.sol library may access uninitialized memory when the following two conditions hold: 1) the provided buffer length is empty (i.e. Affects @openzeppelin/contracts versions >= 5.2.0, < 5.4.0. Fixed in 5.4.0. 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 MarkAI Find prospects already talking about the problem you solve AI watches the communities your customers use to find qualified prospects, then alerts you when a conversation is worth joining. See MarkAI

Background

OpenZeppelin Contracts is a widely used library in the Ethereum ecosystem, providing secure and reusable smart contract components. The library includes various utilities for developing decentralized applications, ensuring that developers can implement complex functionalities without compromising security. However, a vulnerability has been identified in the 'lastIndexOf' function of the Bytes.sol library, which can lead to unintended memory access issues.

Vulnerability Detail

The vulnerability arises in the 'lastIndexOf(bytes, byte, uint256)' function when the provided buffer length is empty and the position argument is not set to the maximum uint256 value. This can cause the function to access uninitialized memory, potentially leading to gas exhaustion or returning an invalid index. If the function reads memory at an out-of-bounds location that matches the search pattern, it may return a valid-looking index outside the buffer bounds, resulting in undefined behavior for subsequent memory accesses.

How To Fix

Minimum fixed version

5.4.0

This is the first release that contains the fix.

npm install @openzeppelin/contracts@5.4.0

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

Workaround

As a temporary workaround, ensure that any calls to the 'lastIndexOf' function are made with a non-empty buffer or validate the position argument before invoking the function to prevent out-of-bounds access.

Conclusion

In summary, CVE-2025-54070 represents a significant vulnerability in the OpenZeppelin Contracts library that can lead to out-of-bounds memory access. It is crucial for developers using this library to upgrade to the patched version to mitigate potential risks. Implementing proper checks and using tools like Vulert can further enhance security by monitoring for vulnerabilities in real-time.

See every vulnerability recorded for @openzeppelin/contracts →

Share this vulnerability

FAQ

CVE-2025-54070 is a vulnerability in the OpenZeppelin Contracts library that affects the 'lastIndexOf' function, allowing for potential out-of-bounds memory access.

If your application uses the affected version of the OpenZeppelin Contracts library, it may experience unexpected behavior, including gas exhaustion or invalid memory access, which could lead to contract failures.

If an immediate upgrade is not possible, implement checks to ensure that the buffer is not empty and validate the position argument before calling the 'lastIndexOf' function.

You can use Vulert to monitor your project for open-source vulnerabilities. It analyzes your package-lock.json file to alert you in real-time. You can also check if your application is affected by this vulnerability using the Vulert playground without any signup.

The CVSS score for this vulnerability is 0.0, indicating a moderate level of risk associated with its exploitation.

Related vulnerabilities

Recent vulnerabilities recorded for @openzeppelin/contracts.

How To Fix

Minimum fixed version

5.4.0

This is the first release that contains the fix.

npm install @openzeppelin/contracts@5.4.0

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