Skip to content

Commit f5251e0

Browse files
authored
fix: resume array headers across stream chunks
1 parent 6d4b666 commit f5251e0

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

‎src/Decoder.ts‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,13 +430,13 @@ export class Decoder<ContextType = undefined> {
430430

431431
this.appendBuffer(buffer);
432432

433-
if (isArrayHeaderRequired) {
434-
arrayItemsLeft = this.readArraySize();
435-
isArrayHeaderRequired = false;
436-
this.complete();
437-
}
438-
439433
try {
434+
if (isArrayHeaderRequired) {
435+
arrayItemsLeft = this.readArraySize();
436+
isArrayHeaderRequired = false;
437+
this.complete();
438+
}
439+
440440
while (true) {
441441
yield this.doDecodeSync();
442442
if (--arrayItemsLeft === 0) {
@@ -451,6 +451,10 @@ export class Decoder<ContextType = undefined> {
451451
}
452452
this.totalPos += this.pos;
453453
}
454+
455+
if (isArrayHeaderRequired) {
456+
throw new RangeError("Insufficient data in parsing array header");
457+
}
454458
} finally {
455459
this.entered = false;
456460
}

0 commit comments

Comments
 (0)