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:
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user