Skip to content

Commit 16dba17

Browse files
authored
Merge pull request #24 from simdutf/some_fixes
fixing a bug in base64url decoding
2 parents efa3bb8 + 262266a commit 16dba17

File tree

2 files changed

+116
-98
lines changed

2 files changed

+116
-98
lines changed

src/Base64SSE.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ private static ushort ToBase64Mask(bool base64Url, ref Vector128<byte> src, ref
8181
: Vector128.Create(0x00, 0x00, 0x00, 0x13, 0x04, 0xBF, 0xBF, 0xB9, 0xB9, 0x00, 0x10, 0xC3, 0xBF, 0xBF, 0xB9, 0xB9);
8282

8383
Vector128<sbyte> checkAsso = base64Url
84-
? Vector128.Create(0xD, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x3, 0x7, 0xB, 0x6, 0xB, 0x12)
84+
? Vector128.Create(0xD, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x3, 0x7, 0xB, 0xE, 0xB, 0x6)
8585
: Vector128.Create(0xD, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x3, 0x7, 0xB, 0xB, 0xB, 0xF);
8686

8787
Vector128<byte> checkValues = base64Url
88-
? Vector128.Create(0x00, 0x80, 0x80, 0x80, 0xCF, 0xBF, 0xD3, 0xA6, 0xB5, 0x86, 0xD0, 0x80, 0xB0, 0x80, 0x00, 0x00)
88+
? Vector128.Create(0x80, 0x80, 0x80, 0x80, 0xCF, 0xBF, 0xB6, 0xA6, 0xB5, 0xA1, 0x0, 0x80, 0x0, 0x80, 0x0, 0x80)
8989
: Vector128.Create(0x80, 0x80, 0x80, 0x80, 0xCF, 0xBF, 0xD5, 0xA6, 0xB5, 0x86, 0xD1, 0x80, 0xB1, 0x80, 0x91, 0x80);
9090

9191
Vector128<Int32> shifted = Sse2.ShiftRightLogical(src.AsInt32(), 3);
@@ -334,14 +334,14 @@ public unsafe static OperationStatus DecodeFromBase64SSE(ReadOnlySpan<byte> sour
334334
src -= bufferBytesConsumed;
335335
dst -= bufferBytesWritten;
336336

337-
bytesConsumed = Math.Max(0,(int)(src - srcInit));
338-
bytesWritten = Math.Max(0,(int)(dst - dstInit));
337+
bytesConsumed = Math.Max(0, (int)(src - srcInit));
338+
bytesWritten = Math.Max(0, (int)(dst - dstInit));
339339

340340
int remainderBytesConsumed = 0;
341341
int remainderBytesWritten = 0;
342342

343343
OperationStatus result =
344-
Base64WithWhiteSpaceToBinaryScalar(source.Slice(Math.Max(0,bytesConsumed)), dest.Slice(Math.Max(0,bytesWritten)), out remainderBytesConsumed, out remainderBytesWritten, isUrl);
344+
Base64WithWhiteSpaceToBinaryScalar(source.Slice(Math.Max(0, bytesConsumed)), dest.Slice(Math.Max(0, bytesWritten)), out remainderBytesConsumed, out remainderBytesWritten, isUrl);
345345

346346
bytesConsumed += remainderBytesConsumed;
347347
bytesWritten += remainderBytesWritten;
@@ -420,14 +420,14 @@ public unsafe static OperationStatus DecodeFromBase64SSE(ReadOnlySpan<byte> sour
420420
*bufferPtr = val;
421421
if (val > 64)
422422
{
423-
bytesConsumed = Math.Max(0,(int)(src - srcInit) - lastBlockSrcCount - (int)bufferBytesConsumed);
424-
bytesWritten = Math.Max(0,(int)(dst - dstInit) - (int)bufferBytesWritten);
423+
bytesConsumed = Math.Max(0, (int)(src - srcInit) - lastBlockSrcCount - (int)bufferBytesConsumed);
424+
bytesWritten = Math.Max(0, (int)(dst - dstInit) - (int)bufferBytesWritten);
425425

426426
int remainderBytesConsumed = 0;
427427
int remainderBytesWritten = 0;
428428

429429
OperationStatus result =
430-
Base64WithWhiteSpaceToBinaryScalar(source.Slice(Math.Max(0,bytesConsumed)), dest.Slice(Math.Max(0,bytesWritten)), out remainderBytesConsumed, out remainderBytesWritten, isUrl);
430+
Base64WithWhiteSpaceToBinaryScalar(source.Slice(Math.Max(0, bytesConsumed)), dest.Slice(Math.Max(0, bytesWritten)), out remainderBytesConsumed, out remainderBytesWritten, isUrl);
431431

432432
bytesConsumed += remainderBytesConsumed;
433433
bytesWritten += remainderBytesWritten;

0 commit comments

Comments
 (0)