Skip to content

Commit db7d148

Browse files
committed
Throw underflow in readSingleBuffer if no bytes are available
1 parent 51f0560 commit db7d148

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/stream.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,22 @@ export default class Stream {
312312
}
313313

314314
readSingleBuffer(length) {
315-
let result = this.list.first.subarray(this.localOffset, length);
315+
if (!this.available(1)) {
316+
throw new UnderflowError;
317+
}
318+
319+
let result = this.list.first.subarray(this.localOffset, this.localOffset + length);
316320
this.advance(result.length);
317321
return result;
318322
}
319323

320324
peekSingleBuffer(offset, length) {
321-
let result = this.list.first.subarray(this.localOffset + offset, length);
325+
if (!this.available(offset + 1)) {
326+
throw new UnderflowError;
327+
}
328+
329+
offset += this.localOffset;
330+
let result = this.list.first.subarray(offset, offset + length);
322331
return result;
323332
}
324333

0 commit comments

Comments
 (0)