CVE-2025-54070
Official description Straight from the sourceThe vendor's or NVD's own wording, published unedited. Authoritative, but often terse — it says what broke, rarely what to do.
NVD · uneditedOpenZeppelin Contracts is a library for secure smart contract development. Starting in version 5.2.0 and prior to version 5.4.0, 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. `buffer.length == 0`) and position is not `2**256 - 1` (i.e. `pos != type(uint256).max`). The `pos` argument could be used to access arbitrary data outside of the buffer bounds. This could lead to the operation running out of gas, or returning an invalid index (outside of the empty buffer). Processing this invalid result for accessing the `buffer` would cause a revert under normal conditions. When triggered, the function reads memory at offset `buffer + 0x20 + pos`. If memory at that location (outside the `buffer`) matches the search pattern, the function would return an out of bound index instead of the expected `type(uint256).max`. This creates unexpected behavior where callers receive a valid-looking index pointing outside buffer bounds. Subsequent memory accesses that don't check bounds and use the returned index must carefully review the potential impact depending on their setup. Code relying on this function returning `type(uint256).max` for empty buffers or using the returned index without bounds checking could exhibit undefined behavior. Users should upgrade to version 5.4.0 to receive a patch.
Technical summary Written by usOur analysis, written from the advisory, the CVSS vector and the affected-version data. It adds context the advisory leaves out, and never invents facts that are not in the source.
dbcve analysis · high confidenceOpenZeppelin Contracts library versions 5.2.0 through 5.3.x contain a vulnerability in the `lastIndexOf(bytes,byte,uint256)` function of Bytes.sol. When an empty buffer (length == 0) is passed with a position parameter not equal to type(uint256).max, the function accesses memory at offset `buffer + 0x20 + pos`, potentially reading uninitialized or arbitrary memory. If the accessed memory matches the search pattern, the function returns an out-of-bounds index instead of the expected type(uint256).max, causing callers expecting the max value for empty buffers to receive an invalid index.
Verify against the referenced sources before acting — the references below are authoritative for this CVE, this summary is not.
CVSS breakdown How the score is builtThe industry scoring standard. It rates how the flaw is reached, what it takes to exploit, and what an attacker gains — the score is derived from those, not the other way round.
From the vector- Attack vector
- Network
- Complexity
- Low
- Privileges
- None
- Authentication
- X
- User interaction
- None
- Scope
- X
CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:N/VI:L/VA:L/SC:N/SI:N/SA:N/E:X/CR:X/IR:X/AR:X/MAV:X/MAC:X/MAT:X/MPR:X/MUI:X/MVC:X/MVI:X/MVA:X/MSC:X/MSI:X/MSA:X/S:X/AU:X/R:X/V:X/RE:X/U:X
Am I affected? How to checkSteps we derive from the advisory and the affected-version data, so you can decide whether this CVE reaches your setup. They are a guide, not a scan — your own configuration is the authority.
dbcve checksWork through these to decide whether this CVE applies to you.
-
Identify OpenZeppelin Contracts version in useInspect package.json, lockfiles, or imported files for '@openzeppelin/contracts' version entry. Run 'npm list @openzeppelin/contracts' or 'pip show openzeppelin-contracts' depending on language. Check any direct Bytes.sol import.Affected if Version is 5.2.0, 5.3.0, 5.3.1, or any 5.3.x release within the range 5.2.0 to 5.3.x (excluding 5.4.0 and later)
-
Locate Bytes.sol in the dependency treeSearch for imported 'Bytes.sol' or '@openzeppelin/contracts/utils/Bytes.sol' in source code. Verify the file exists in node_modules or vendor directory.Affected if Bytes.sol from OpenZeppelin versions 5.2.0-5.3.x is present in the project dependencies
-
Identify usage of lastIndexOf functionSearch code for calls to 'lastIndexOf' with three parameters: lastIndexOf(bytes, byte, uint256). Review function call sites in Solidity source files.Affected if Code calls lastIndexOf(bytes,byte,uint256) from OpenZeppelin Bytes library
-
Check for empty buffer scenarios with position parameterReview all lastIndexOf call sites to determine if any pass empty bytes (length == 0) as the first argument. Inspect the uint256 position parameter value at runtime or in source code.Affected if The vulnerable code path passes an empty bytes array with a position parameter value NOT equal to type(uint256).max (i.e., any concrete uint256 value)
-
Verify caller expects type(uint256).max for empty buffersReview code that uses the return value from lastIndexOf. Search for comparisons or expectations that empty buffers should return type(uint256).max, such as '== type(uint256).max' or '!= type(uint256).max' checks.Affected if Caller logic relies on lastIndexOf returning type(uint256).max for empty buffers without additional bounds validation
A user is affected if their project uses OpenZeppelin Contracts version 5.2.0-5.3.x, imports Bytes.sol, calls lastIndexOf(bytes,byte,uint256) with empty bytes and a non-max position value, and the calling code expects type(uint256).max for empty buffers without bounds checking.
Generated from the published advisory. Verify against your own configuration.
Remediation Closing itWhat it takes to close this. Where a vendor fix exists we point at it; where none exists we say so plainly, and can build one. Effort estimates are scoped from the advisory, not from your codebase.
dbcve · scopedUpgrade OpenZeppelin Contracts to version 5.4.0 or later. Review any code relying on lastIndexOf returning type(uint256).max for empty buffers or using the returned index without bounds validation.
5.4.0
- Identify all instances where OpenZeppelin Contracts library versions 5.2.0 through 5.3.x are used in your project dependencies
- Update the OpenZeppelin Contracts dependency to version 5.4.0 or later
- Run your project's dependency management tool to resolve the new version (e.g., npm update, cargo update, or pip install -U depending on your language/framework)
- Rebuild and test your project to ensure the upgrade does not introduce regressions
- Review any code that calls the `lastIndexOf(bytes,byte,uint256)` function in the Bytes.sol library to ensure correct behavior with empty buffers
Generated from the published advisory — verify against the referenced sources before acting.
- Consultation2.0 h
- Implementation4.0 h
- Testing4.0 h
- Review / QA2.0 h
An estimate, not a bill — we confirm scope with you before any work starts. Need it this week? Rush from $3,328.
Scan for this in your stack
Free · runs locallyCheck whether your project pulls in CVE-2025-54070 — or any other known-vulnerable package — straight from your lock files. Free and open source; it runs locally and uploads nothing.
References Go to the primary sourcePrimary sources — vendor advisories, patches and trackers. Where our summary and a reference disagree, the reference wins.
Primary sourcesPractitioner notes
ContributedPeer-ranked notes from engineers who’ve handled CVE-2025-54070 in production — separate from our analysis above.
The advisory tells you what broke. It rarely tells you what actually worked. If you’ve dealt with this one, that detail is what the next engineer is searching for.
- The version that genuinely resolved it — not the one the vendor claimed
- A config change or rule that shut the vector down
- A gotcha in the upgrade path that cost you an afternoon
No notes yet
Be the first to add a field note for this CVE — a mitigation you’ve verified, a version caveat, or a link to a working fix. Sign in above to contribute.
A place for practitioners to share what actually worked: a mitigation you’ve tested, a configuration change, a version- or environment-specific caveat, or a link to a verified patch. The most useful notes rise to the top as peers upvote them, so the signal stays high.
- Verified mitigations, workarounds, and config changes
- Version or environment caveats, and links to real fixes
- No weaponised exploit code, or anything meant to cause harm
- No spam, self-promotion, credentials, or personal data