fix(parser): validate ESC prefix byte range with correct precedence

_identifier() checked custom prefix bytes with
`res && 0x3c > res || res > 0x3f`, which parsed as
`(res && 0x3c > res) || (res > 0x3f)` because && binds tighter
than ||. A prefix of NUL (0x00) skipped both clauses and was
accepted even though only 0x3c..0x3f are valid.

Use an explicit range test: res < 0x3c || res > 0x3f. Mirror the
same fix in ApcParser and DcsParser test identifier helpers.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Daniel Imms
2026-06-01 15:28:04 +00:00
committed by Cursor Agent
co-authored by Cursor
parent 1a01e9634f
commit 4500485e79
3 changed files with 3 additions and 3 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ function identifier(id: IFunctionIdentifier): number {
throw new Error('only one byte as prefix supported');
}
res = id.prefix.charCodeAt(0);
if (res && 0x3c > res || res > 0x3f) {
if (res < 0x3c || res > 0x3f) {
throw new Error('prefix must be in range 0x3c .. 0x3f');
}
}
+1 -1
View File
@@ -22,7 +22,7 @@ function identifier(id: IFunctionIdentifier): number {
throw new Error('only one byte as prefix supported');
}
res = id.prefix.charCodeAt(0);
if (res && 0x3c > res || res > 0x3f) {
if (res < 0x3c || res > 0x3f) {
throw new Error('prefix must be in range 0x3c .. 0x3f');
}
}
+1 -1
View File
@@ -342,7 +342,7 @@ export class EscapeSequenceParser extends Disposable implements IEscapeSequenceP
throw new Error('only one byte as prefix supported');
}
res = id.prefix.charCodeAt(0);
if (res && 0x3c > res || res > 0x3f) {
if (res < 0x3c || res > 0x3f) {
throw new Error('prefix must be in range 0x3c .. 0x3f');
}
}