Skip to content

Commit 7ad3374

Browse files
committed
TruncatedCharErrorUTF16SSE pass
1 parent 398645f commit 7ad3374

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/Base64SSEUTF16.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,22 @@ private unsafe static OperationStatus InnerDecodeFromBase64SSERegular(ReadOnlySp
189189
int lastBlockSrcCount = 0;
190190
while ((bufferPtr - startOfBuffer) % 64 != 0 && src < srcEnd)
191191
{
192+
if (!IsValidBase64Index(*src))
193+
{
194+
bytesConsumed = Math.Max(0, (int)(src - srcInit) - lastBlockSrcCount - (int)bufferBytesConsumed);
195+
bytesWritten = Math.Max(0, (int)(dst - dstInit) - (int)bufferBytesWritten);
196+
197+
int remainderBytesConsumed = 0;
198+
int remainderBytesWritten = 0;
199+
200+
OperationStatus result =
201+
Base64WithWhiteSpaceToBinaryScalar(source.Slice(Math.Max(0, bytesConsumed)), dest.Slice(Math.Max(0, bytesWritten)), out remainderBytesConsumed, out remainderBytesWritten, isUrl);
202+
203+
bytesConsumed += remainderBytesConsumed;
204+
bytesWritten += remainderBytesWritten;
205+
return result;
206+
}
207+
192208
byte val = toBase64[(int)*src];
193209
*bufferPtr = val;
194210
if (val > 64)
@@ -260,6 +276,15 @@ private unsafe static OperationStatus InnerDecodeFromBase64SSERegular(ReadOnlySp
260276

261277
while (leftover < 4 && src < srcEnd)
262278
{
279+
280+
if (!IsValidBase64Index(*src))
281+
{
282+
bytesConsumed = (int)(src - srcInit);
283+
bytesWritten = (int)(dst - dstInit);
284+
return OperationStatus.InvalidData;
285+
}
286+
287+
263288
byte val = toBase64[(byte)*src];
264289
if (val > 64)
265290
{

0 commit comments

Comments
 (0)