Out-of-bounds ReadWeakness · CWE-125

CVE-2025-54070

MEDIUM · 6.9 CVSS v4.0 Published 2025-07-17
Mitigation only
No fix yet — a mitigation exists. There is no fixed release. A documented workaround reduces exposure in the meantime.
See remediation →
78/100
Remediation priority · High
Remotely reachable No privileges Zero-click

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 · unedited
OpenZeppelin 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 confidence

OpenZeppelin 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.

MitigationUpgrade 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.

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 checks

Work through these to decide whether this CVE applies to you.

  1. Identify OpenZeppelin Contracts version in use
    Inspect 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)
  2. Locate Bytes.sol in the dependency tree
    Search 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
  3. Identify usage of lastIndexOf function
    Search 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
  4. Check for empty buffer scenarios with position parameter
    Review 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)
  5. Verify caller expects type(uint256).max for empty buffers
    Review 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.

Check your environment

Paste your version and any relevant configuration and it will be compared against the affected criteria above. Do not include secrets or credentials.

AI-assisted, checked against the advisory. Informational, not a guarantee.

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 · scoped
Mitigation available No clean upgrade yet — mitigate in the meantime
Mitigation

Upgrade 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.

Recommended fix High confidence

5.4.0

  1. Identify all instances where OpenZeppelin Contracts library versions 5.2.0 through 5.3.x are used in your project dependencies
  2. Update the OpenZeppelin Contracts dependency to version 5.4.0 or later
  3. 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)
  4. Rebuild and test your project to ensure the upgrade does not introduce regressions
  5. 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.

Have this fixed Scoped from the published advisory
  • Consultation2.0 h
  • Implementation4.0 h
  • Testing4.0 h
  • Review / QA2.0 h
12.0 hours of engineering $2,080
Get help mitigating

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 locally
dbcve dependency scanner

Check 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 sources

Practitioner notes

Contributed

Peer-ranked notes from engineers who’ve handled CVE-2025-54070 in production — separate from our analysis above.

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.

What this is

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.

What belongs here
  • 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