Skip to content

Commit

Permalink
revert strings
Browse files Browse the repository at this point in the history
  • Loading branch information
turbocrime committed Dec 11, 2024
1 parent 8cd68aa commit ef487b6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
12 changes: 6 additions & 6 deletions lcov.info
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,13 @@ BRDA:90,0,1,512
DA:91,512
BRDA:91,1,0,2
BRDA:91,1,1,510
DA:93,510
BRDA:93,2,0,-
BRDA:93,2,1,510
DA:103,258
FN:103,ReadCidSha256.NullableCid
DA:92,510
BRDA:92,2,0,-
BRDA:92,2,1,510
DA:102,258
FN:102,ReadCidSha256.NullableCid
FNDA:258,ReadCidSha256.NullableCid
DA:104,258
DA:103,258
FNF:3
FNH:3
LF:14
Expand Down
16 changes: 8 additions & 8 deletions src/ReadCbor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ library ReadCbor {
n := add(i, len)
}

require(n <= cbor.length, "index out of range");
require(n <= cbor.length);
}

/// @notice Reads a string item into a bytes32 and advances the index
Expand All @@ -369,15 +369,15 @@ library ReadCbor {
{
assert(maxLen <= 32);
(i, len) = header8(cbor, i, MajorText);
require(len <= maxLen, "string length out of range");
require(len <= maxLen);

assembly ("memory-safe") {
ret := mload(add(cbor, add(0x20, i)))
ret := and(ret, not(shr(mul(len, 8), not(0))))
n := add(i, len)
}

require(n <= cbor.length, "index out of range");
require(n <= cbor.length);
}

/// @notice Reads a single-byte string item and advances the index
Expand Down Expand Up @@ -405,7 +405,7 @@ library ReadCbor {
uint32 len;
(i, len) = header32(cbor, i, MajorText);
n = i + len;
require(n <= cbor.length, "index out of range");
require(n <= cbor.length);
}

/// @notice Checks if the next item is a byte string
Expand Down Expand Up @@ -434,7 +434,7 @@ library ReadCbor {
n := add(i, len)
}

require(n <= cbor.length, "index out of range");
require(n <= cbor.length);
}

/// @notice Reads a byte string item into a bytes32 and advances the index
Expand All @@ -458,15 +458,15 @@ library ReadCbor {
{
assert(maxLen <= 32);
(i, len) = header8(cbor, i, MajorBytes);
require(len <= maxLen, "bytes length out of range");
require(len <= maxLen);

assembly ("memory-safe") {
ret := mload(add(cbor, add(0x20, i)))
ret := and(ret, not(shr(mul(len, 8), not(0))))
n := add(i, len)
}

require(n <= cbor.length, "index out of range");
require(n <= cbor.length);
}

/// @notice Skips a byte string item and advances the index
Expand All @@ -477,7 +477,7 @@ library ReadCbor {
uint32 len;
(i, len) = header32(cbor, i, MajorBytes);
n = i + len;
require(n <= cbor.length, "index out of range");
require(n <= cbor.length);
}

/// @notice Checks if the next item is a tag
Expand Down
8 changes: 4 additions & 4 deletions src/tags/ReadBignum.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ library ReadBignum {
)
n := add(i, len)
}
require(n <= cbor.length, "index out of range");
require(n <= cbor.length);
}

function NInt256(bytes memory cbor, uint32 i) internal pure returns (uint32 n, int256 nbn) {
Expand All @@ -46,17 +46,17 @@ library ReadBignum {
n := add(i, len)
}

require(bn < uint256(type(int256).min), "two's complement int256 will overflow");
require(bn < uint256(type(int256).min), "int256 will overflow");
nbn = -1 - int256(bn);
require(n <= cbor.length, "index out of range");
require(n <= cbor.length);
}

function Int256(bytes memory cbor, uint32 i) internal pure returns (uint32 n, int256 ibn) {
(, uint64 tag) = cbor.Tag(i);
if (tag == TagUnsignedBignum) {
uint256 ubn;
(n, ubn) = UInt256(cbor, i);
require(ubn <= uint256(type(int256).max), "two's complement int256 will overflow");
require(ubn <= uint256(type(int256).max), "int256 will overflow");
ibn = int256(ubn);
} else if (tag == TagNegativeBignum) {
return NInt256(cbor, i);
Expand Down
7 changes: 3 additions & 4 deletions src/tags/ReadCidSha256.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,9 @@ library ReadCidSha256 {
n := add(i, 41) // 4 bytes cbor header + 5 bytes multibase header + 32 bytes hash
}

require(expect == cborHeader, "Expected CBOR tag 42 and 37-byte CIDv1");
require(!cidSha256.isNull(), "Expected non-zero CID value");

require(n <= cbor.length, "index out of range");
require(expect == cborHeader, "expected CBOR tag 42 and 37-byte CIDv1");
require(!cidSha256.isNull(), "expected non-zero CID");
require(n <= cbor.length);
}

/**
Expand Down

0 comments on commit ef487b6

Please sign in to comment.