{"id":"CVE-2025-54070","published":"2025-07-17T18:25:02Z","modified":"2025-07-17T20:28:13Z","title":"OpenZeppelin Contracts's Bytes's lastIndexOf function with position argument performs out-of-bound memory access on…","vendor":"OpenZeppelin","product":"openzeppelin-contracts","tier":"tail","description":{"text":"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.","provenance":"source","from":"CVE.org"},"cvss":{"score":6.9,"severity":"MEDIUM","version":"4.0","vector":"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","provenance":"source","from":"CVE.org CNA"},"epss":{"score":0.00399,"percentile":0.35032,"provenance":"source"},"cwes":[{"id":"CWE-125","name":"Out-of-bounds Read"}],"references":[{"url":"https://github.com/OpenZeppelin/openzeppelin-contracts/security/advisories/GHSA-9rcw-c2f9-2j55","tags":["x_refsource_CONFIRM"]},{"url":"https://github.com/OpenZeppelin/openzeppelin-contracts/releases/tag/v5.4.0","tags":["x_refsource_MISC"]}],"priority":{"score":11.8,"factors":[{"name":"EPSS percentile","points":7.01},{"name":"CVSS severity","points":4.83}]},"vendorSlug":"openzeppelin","affectedVersions":[{"vendor":"OpenZeppelin","product":"openzeppelin-contracts","versions":[">= 5.2.0, < 5.4.0"]}],"ssvc":{"exploitation":"none","automatable":"no","technicalImpact":"partial","timestamp":"2025-07-17T20:27:49.503221Z","from":"CISA ADP","provenance":"source"},"affected":[{"ecosystem":"npm","package":"@openzeppelin/contracts","vulnerableRanges":[">=5.2.0, <5.4.0"],"patched":["5.4.0"],"from":["GHSA-9rcw-c2f9-2j55"],"provenance":"source"},{"ecosystem":"npm","package":"@openzeppelin/contracts-upgradeable","vulnerableRanges":[">=5.2.0, <5.4.0"],"patched":["5.4.0"],"from":["GHSA-9rcw-c2f9-2j55"],"provenance":"source"}],"summary":{"text":"The OpenZeppelin Contracts library's lastIndexOf(bytes,byte,uint256) function in its Bytes.sol library, in versions from 5.2.0 before 5.4.0, performs an out-of-bounds memory read when the buffer is empty and the position argument is not the maximum uint256 value. An attacker who can control the position argument and the data in memory can cause the function to return an index pointing outside the buffer, or to run out of gas, with callers that do not bounds-check the result at risk of unexpected behavior.","provenance":"ai","model":"claude-haiku-5-5","generatedAt":"2026-11-20T21:52:55Z"},"euvd":{"id":"EUVD-2025-21789","exploited":false,"provenance":"source"}}