From 4500485e7993d0956423356770fb777b9bf3ee2b Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sun, 31 May 2026 21:52:33 -0700 Subject: [PATCH] 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 --- src/common/parser/ApcParser.test.ts | 2 +- src/common/parser/DcsParser.test.ts | 2 +- src/common/parser/EscapeSequenceParser.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common/parser/ApcParser.test.ts b/src/common/parser/ApcParser.test.ts index b27b40039..563ddbeab 100644 --- a/src/common/parser/ApcParser.test.ts +++ b/src/common/parser/ApcParser.test.ts @@ -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'); } } diff --git a/src/common/parser/DcsParser.test.ts b/src/common/parser/DcsParser.test.ts index 459bc8961..5fa7b9416 100644 --- a/src/common/parser/DcsParser.test.ts +++ b/src/common/parser/DcsParser.test.ts @@ -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'); } } diff --git a/src/common/parser/EscapeSequenceParser.ts b/src/common/parser/EscapeSequenceParser.ts index a0c97b610..c12ca3446 100644 --- a/src/common/parser/EscapeSequenceParser.ts +++ b/src/common/parser/EscapeSequenceParser.ts @@ -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'); } }