From ccb0cf7727fd6764854ac45cb775c152e3121339 Mon Sep 17 00:00:00 2001 From: maradini77 <140460067+maradini77@users.noreply.github.com> Date: Tue, 7 Oct 2025 20:33:36 +0200 Subject: [PATCH] Update StdStorage.sol --- src/StdStorage.sol | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/StdStorage.sol b/src/StdStorage.sol index 1627af75..1d32704e 100644 --- a/src/StdStorage.sol +++ b/src/StdStorage.sol @@ -282,7 +282,11 @@ library stdStorageSafe { function bytesToBytes32(bytes memory b, uint256 offset) private pure returns (bytes32) { bytes32 out; - uint256 max = b.length > 32 ? 32 : b.length; + // Cap read length by remaining bytes from `offset`, and at most 32 bytes to avoid out-of-bounds + uint256 max = b.length > offset ? b.length - offset : 0; + if (max > 32) { + max = 32; + } for (uint256 i = 0; i < max; i++) { out |= bytes32(b[offset + i] & 0xFF) >> (i * 8); }