@@ -12,6 +12,8 @@ contract TestBytesLib2 {
12
12
bytes storageCheckBytes = hex "aabbccddeeff " ;
13
13
bytes storageCheckBytesZeroLength = hex "" ;
14
14
15
+ uint256 constant MAX_UINT = uint256 (- 1 );
16
+
15
17
/**
16
18
* Sanity Checks
17
19
*/
@@ -98,6 +100,27 @@ contract TestBytesLib2 {
98
100
(r, ) = address (this ).call (abi.encodePacked (this .sliceIndexThrow.selector ));
99
101
Assert.isFalse (r, "Slicing with wrong index should throw " );
100
102
103
+ (r, ) = address (this ).call (abi.encodePacked (this .sliceOverflowLength0Throw.selector ));
104
+ Assert.isFalse (r, "Slicing with overflow in length and _start 0 should throw " );
105
+
106
+ (r, ) = address (this ).call (abi.encodePacked (this .sliceOverflowLength1Throw.selector ));
107
+ Assert.isFalse (r, "Slicing with overflow in length and _start 1 should throw " );
108
+
109
+ (r, ) = address (this ).call (abi.encodePacked (this .sliceOverflowLength33Throw.selector ));
110
+ Assert.isFalse (r, "Slicing with overflow in length and _start 33 should throw " );
111
+
112
+ (r, ) = address (this ).call (abi.encodePacked (this .sliceOverflowLengthMinus32Throw.selector ));
113
+ Assert.isFalse (r, "Slicing with overflow in length minus 32 and _start 1 should throw " );
114
+
115
+ (r, ) = address (this ).call (abi.encodePacked (this .sliceOverflowStart0Throw.selector ));
116
+ Assert.isFalse (r, "Slicing with overflow in _start and length 0 should throw " );
117
+
118
+ (r, ) = address (this ).call (abi.encodePacked (this .sliceOverflowStart1Throw.selector ));
119
+ Assert.isFalse (r, "Slicing with overflow in _start and length 1 should throw " );
120
+
121
+ (r, ) = address (this ).call (abi.encodePacked (this .sliceOverflowStart33Throw.selector ));
122
+ Assert.isFalse (r, "Slicing with overflow in _start and length 33 should throw " );
123
+
101
124
(r, ) = address (this ).call (abi.encodePacked (this .sliceLengthThrow.selector ));
102
125
Assert.isFalse (r, "Slicing with wrong length should throw " );
103
126
}
@@ -124,6 +147,83 @@ contract TestBytesLib2 {
124
147
// This should throw;
125
148
}
126
149
150
+ function sliceOverflowLength0Throw () public pure {
151
+ bytes memory memBytes33 = hex "f00d0000000000000000000000000000000000000000000000000000000000feed " ;
152
+
153
+ bytes memory testBytes;
154
+ bytes memory resultBytes;
155
+
156
+ testBytes = hex "f00d " ;
157
+ resultBytes = memBytes33.slice (0 , MAX_UINT);
158
+ // This should throw;
159
+ }
160
+
161
+ function sliceOverflowLength1Throw () public pure {
162
+ bytes memory memBytes33 = hex "f00d0000000000000000000000000000000000000000000000000000000000feed " ;
163
+
164
+ bytes memory testBytes;
165
+ bytes memory resultBytes;
166
+
167
+ testBytes = hex "f00d " ;
168
+ resultBytes = memBytes33.slice (1 , MAX_UINT);
169
+ // This should throw;
170
+ }
171
+
172
+ function sliceOverflowLength33Throw () public pure {
173
+ bytes memory memBytes33 = hex "f00d0000000000000000000000000000000000000000000000000000000000feed " ;
174
+
175
+ bytes memory testBytes;
176
+ bytes memory resultBytes;
177
+
178
+ testBytes = hex "f00d " ;
179
+ resultBytes = memBytes33.slice (33 , MAX_UINT);
180
+ // This should throw;
181
+ }
182
+
183
+ function sliceOverflowLengthMinus32Throw () public pure {
184
+ bytes memory memBytes33 = hex "f00d0000000000000000000000000000000000000000000000000000000000feed " ;
185
+
186
+ bytes memory testBytes;
187
+ bytes memory resultBytes;
188
+
189
+ testBytes = hex "f00d " ;
190
+ resultBytes = memBytes33.slice (1 , MAX_UINT - 32 );
191
+ // This should throw;
192
+ }
193
+
194
+ function sliceOverflowStart0Throw () public pure {
195
+ bytes memory memBytes33 = hex "f00d0000000000000000000000000000000000000000000000000000000000feed " ;
196
+
197
+ bytes memory testBytes;
198
+ bytes memory resultBytes;
199
+
200
+ testBytes = hex "f00d " ;
201
+ resultBytes = memBytes33.slice (MAX_UINT, 0 );
202
+ // This should throw;
203
+ }
204
+
205
+ function sliceOverflowStart1Throw () public pure {
206
+ bytes memory memBytes33 = hex "f00d0000000000000000000000000000000000000000000000000000000000feed " ;
207
+
208
+ bytes memory testBytes;
209
+ bytes memory resultBytes;
210
+
211
+ testBytes = hex "f00d " ;
212
+ resultBytes = memBytes33.slice (MAX_UINT, 1 );
213
+ // This should throw;
214
+ }
215
+
216
+ function sliceOverflowStart33Throw () public pure {
217
+ bytes memory memBytes33 = hex "f00d0000000000000000000000000000000000000000000000000000000000feed " ;
218
+
219
+ bytes memory testBytes;
220
+ bytes memory resultBytes;
221
+
222
+ testBytes = hex "f00d " ;
223
+ resultBytes = memBytes33.slice (MAX_UINT, 1 );
224
+ // This should throw;
225
+ }
226
+
127
227
function testToUint8 () public {
128
228
bytes memory memBytes = hex "f00d20feed " ;
129
229
0 commit comments