We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
bytesToBytes32
1 parent a906201 commit e3ffae7Copy full SHA for e3ffae7
src/StdStorage.sol
@@ -282,7 +282,11 @@ library stdStorageSafe {
282
function bytesToBytes32(bytes memory b, uint256 offset) private pure returns (bytes32) {
283
bytes32 out;
284
285
- 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
286
+ uint256 max = b.length > offset ? b.length - offset : 0;
287
+ if (max > 32) {
288
+ max = 32;
289
+ }
290
for (uint256 i = 0; i < max; i++) {
291
out |= bytes32(b[offset + i] & 0xFF) >> (i * 8);
292
}
0 commit comments