Skip to content

Commit 60c3536

Browse files
🥅 Handle stack overflow for JSON decode
1 parent 2b4e2b4 commit 60c3536

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

Lite3DotNet.SystemTextJson/Lite3JsonDecoder.cs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -303,14 +303,12 @@ private static Lite3Core.Status DecodeDocument(
303303
if ((status = Lite3Core.InitializeObject(buffer, out position)) < 0)
304304
return status;
305305

306-
frames.Push(Frame.ForObject(offset: 0));
307-
return 0;
306+
return frames.Push(Frame.ForObject(offset: 0));
308307
case JsonTokenType.StartArray:
309308
if ((status = Lite3Core.InitializeArray(buffer, out position)) < 0)
310309
return status;
311310

312-
frames.Push(Frame.ForArray(offset: 0));
313-
return 0;
311+
return frames.Push(Frame.ForArray(offset: 0));
314312
default:
315313
return Lite3Core.Status.ExpectedJsonArrayOrObject;
316314
}
@@ -341,8 +339,7 @@ private static Lite3Core.Status DecodeObject(
341339
if (reader.TokenType != JsonTokenType.PropertyName)
342340
return Lite3Core.Status.ExpectedJsonProperty;
343341

344-
frames.Push(Frame.ForObjectSwitch(offset, GetKeyRef(arrayPool, ref reader)));
345-
return 0;
342+
return frames.Push(Frame.ForObjectSwitch(offset, GetKeyRef(arrayPool, ref reader)));
346343
}
347344

348345
return reader.IsFinalBlock ? Lite3Core.Status.InsufficientBuffer : Lite3Core.Status.NeedsMoreData;
@@ -400,7 +397,7 @@ private static Lite3Core.Status DecodeObjectSwitch(
400397
if ((status = Lite3Core.SetObject(buffer, ref position, offset, key, keyData, out var objectOffset)) >= 0)
401398
{
402399
frames.Pop(arrayPool);
403-
frames.Push(Frame.ForObject(objectOffset));
400+
return frames.Push(Frame.ForObject(objectOffset));
404401
}
405402

406403
return status;
@@ -410,7 +407,7 @@ private static Lite3Core.Status DecodeObjectSwitch(
410407
if ((status = Lite3Core.SetArray(buffer, ref position, offset, key, keyData, out var arrayOffset)) >= 0)
411408
{
412409
frames.Pop(arrayPool);
413-
frames.Push(Frame.ForArray(arrayOffset));
410+
return frames.Push(Frame.ForArray(arrayOffset));
414411
}
415412

416413
return status;
@@ -450,8 +447,7 @@ private static Lite3Core.Status DecodeArray(
450447
return 0;
451448
}
452449

453-
frames.Push(Frame.ForArraySwitch(offset));
454-
return 0;
450+
return frames.Push(Frame.ForArraySwitch(offset));
455451
}
456452

457453
return reader.IsFinalBlock ? Lite3Core.Status.InsufficientBuffer : Lite3Core.Status.NeedsMoreData;
@@ -502,7 +498,7 @@ private static Lite3Core.Status DecodeArraySwitch(
502498
if ((status = Lite3Core.ArrayAppendObject(buffer, ref position, offset, out var objectOffset)) >= 0)
503499
{
504500
frames.Pop(arrayPool);
505-
frames.Push(Frame.ForObject(objectOffset));
501+
return frames.Push(Frame.ForObject(objectOffset));
506502
}
507503

508504
return status;
@@ -512,7 +508,7 @@ private static Lite3Core.Status DecodeArraySwitch(
512508
if ((status = Lite3Core.ArrayAppendArray(buffer, ref position, offset, out var arrayOffset)) >= 0)
513509
{
514510
frames.Pop(arrayPool);
515-
frames.Push(Frame.ForArray(arrayOffset));
511+
return frames.Push(Frame.ForArray(arrayOffset));
516512
}
517513

518514
return status;

0 commit comments

Comments
 (0)