Skip to content

Commit cbd5795

Browse files
authored
fix: add bounds check for lexer position while parsing array and dictionary (#327)
* fix: add bounds check for lexer position while parsing array and dictionary * refactor: better position for checks is inside the while loop * fix(lexer): prevent buffer overread in getString by adding bounds check * refactor
1 parent 765c276 commit cbd5795

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

lib/parser/lexer.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ class Lexer {
2020
}
2121

2222
getString(len) {
23+
if (this.pos + len > this.buf.length) {
24+
throw new Error(
25+
`Lexer buffer overread: trying to read ${len} bytes from position ${this.pos}, but buffer length is ${this.buf.length}`
26+
);
27+
}
2328
return String.fromCharCode.apply(
2429
null,
2530
this.buf.subarray(this.pos, this.pos + len),

0 commit comments

Comments
 (0)