DeFiHardhatFoundry
250,000 USDC
View results
Submission Details
Severity: medium
Invalid

`verifyCopyByteIndex` and `verifyPasteByteIndex` isn't enough for verifying data copy and paste

Summary

verifyCopyByteIndex and verifyPasteByteIndex isn't enough for verifying data copy and paste

Vulnerability Details

function verifyCopyByteIndex(uint256 copyByteIndex, bytes memory copyFromData) internal pure {
require(C.SLOT_SIZE <= copyByteIndex, "LibBytes: copyByteIndex too small");
require(copyByteIndex <= copyFromData.length, "LibBytes: copyByteIndex too large");
}
function verifyPasteByteIndex(uint256 pasteByteIndex, bytes memory pasteToData) internal pure {
require(C.SLOT_SIZE <= pasteByteIndex, "LibBytes: pasteByteIndex too small");
require(pasteByteIndex <= pasteToData.length, "LibBytes: pasteByteIndex too large");
}

bytes memory variables in Solidity have an additional 32 bytes of overhead for storing the array length. So we need to verify data.length >= index + 32.

Impact

Even though the verify of verifyCopyByteIndex and verifyPasteByteIndex passes, the paste32Bytes function maybe still revert.

Tools Used

manual

Recommendations

function verifyCopyByteIndex(uint256 copyByteIndex, bytes memory copyFromData) internal pure {
require(C.SLOT_SIZE <= copyByteIndex, "LibBytes: copyByteIndex too small");
- require(copyByteIndex <= copyFromData.length, "LibBytes: copyByteIndex too large");
+ require(copyByteIndex + 32 <= copyFromData.length, "LibBytes: copyByteIndex too large");
}
function verifyPasteByteIndex(uint256 pasteByteIndex, bytes memory pasteToData) internal pure {
require(C.SLOT_SIZE <= pasteByteIndex, "LibBytes: pasteByteIndex too small");
- require(pasteByteIndex <= pasteToData.length, "LibBytes: pasteByteIndex too large");
+ require(pasteByteIndex + 32 <= pasteToData.length, "LibBytes: pasteByteIndex too large");
}
Updates

Lead Judging Commences

inallhonesty Lead Judge 11 months ago
Submission Judgement Published
Invalidated
Reason: Incorrect statement

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.