Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Commit 0d11a89

Browse files
committed
Subtract don't add, avoid overflow
1 parent 50c5afa commit 0d11a89

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/Microsoft.AspNetCore.Server.Kestrel/Internal/Http/FrameHeaders.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public static unsafe void ValidateHeaderCharacters(string headerCharacters)
249249
{
250250
ThrowInvalidHeaderCharacter(pHeader + offset, Vector<byte>.Count);
251251
}
252-
} while (offset + Vector<byte>.Count <= length);
252+
} while (offset <= length - Vector<byte>.Count);
253253
}
254254

255255
// Non-vector testing:
@@ -258,7 +258,7 @@ public static unsafe void ValidateHeaderCharacters(string headerCharacters)
258258
// Flag > 0x007f => All but highest bit picked up by 0x7f flagging, highest bit picked up by < 0x20 flagging
259259
// Bitwise | or the above three together
260260
// Bitwise & and each char with 0xff80; result should be 0 if all tests pass
261-
if (offset + sizeof(ulong) <= length)
261+
if (offset <= length - sizeof(ulong))
262262
{
263263
do
264264
{
@@ -268,9 +268,9 @@ public static unsafe void ValidateHeaderCharacters(string headerCharacters)
268268
{
269269
ThrowInvalidHeaderCharacter(pHeader + offset, sizeof(ulong));
270270
}
271-
} while (offset + sizeof(ulong) <= length);
271+
} while (offset <= length - sizeof(ulong));
272272
}
273-
if (offset + sizeof(uint) <= length)
273+
if (offset <= length - sizeof(uint))
274274
{
275275
var stringUint = (uint*)(pHeader + offset);
276276
offset += sizeof(uint);
@@ -279,7 +279,7 @@ public static unsafe void ValidateHeaderCharacters(string headerCharacters)
279279
ThrowInvalidHeaderCharacter(pHeader + offset, sizeof(uint));
280280
}
281281
}
282-
if (offset + sizeof(ushort) <= length)
282+
if (offset <= length - sizeof(ushort))
283283
{
284284
var stringUshort = (ushort*)(pHeader + offset);
285285
offset += sizeof(ushort);

0 commit comments

Comments
 (0)