Skip to content

Fix CSI sequence parsing, Windows NO_COLOR compliance, readSecret abort, and mode token safety - #54

Merged
prateekbhujel merged 1 commit into
mainfrom
fix/csi-parsing-mode-token-safety
Aug 28, 2026
Merged

Fix CSI sequence parsing, Windows NO_COLOR compliance, readSecret abort, and mode token safety#54
prateekbhujel merged 1 commit into
mainfrom
fix/csi-parsing-mode-token-safety

Conversation

@prateekbhujel

Copy link
Copy Markdown
Owner

Fixes #53

Summary of Changes

  1. CSI sequence parsing: Recognize all standard ECMA-48 final bytes in the range 0x40..0x7E (@ through ~, including lowercase a-z) in terminal_is_csi_final_byte(). Prevents stalls on SGR (\e[0m), device attributes (\e[?1;2c), and other valid ANSI sequences.
  2. Windows NO_COLOR compliance: Treat empty NO_COLOR= as active on Windows to conform to the no-color specification and maintain parity with POSIX.
  3. POSIX readSecret Escape abort: Emit \n to stdout on Escape abort before restoring terminal attributes, matching Windows and Ctrl+C/Ctrl+D behavior.
  4. RAII ModeToken auto-restore: Automatically restore terminal cooked mode in terminal_mode_token_free_obj() if the token is garbage-collected or dropped before restoreMode() is called.
  5. CSI numeric parameter overflow protection: Guard multi-digit number parsing in CSI sequences against unsigned int overflow.
  6. NAN validation: Reject NAN values in readKey() timeout parameters with a ValueError.

Test Coverage

Added 4 new PHPT test cases:

  • tests/027_csi_lowercase_final_byte.phpt
  • tests/028_read_secret_escape_abort.phpt
  • tests/029_mode_token_auto_restore.phpt
  • tests/030_read_key_nan_validation.phpt

… safety

- recognize all ECMA-48 final bytes (0x40..0x7E) in CSI sequence parsing
- treat empty NO_COLOR as set on Windows per no-color spec
- emit newline on Escape abort in POSIX readSecret
- auto-restore terminal mode on ModeToken destruction
- guard CSI numeric parameter parsing against integer overflow
- reject NAN in readKey timeout parameters
- add PHPT tests for all fixes

Fixes #53
@prateekbhujel
prateekbhujel merged commit 5d5c001 into main Aug 28, 2026
15 checks passed
@prateekbhujel
prateekbhujel deleted the fix/csi-parsing-mode-token-safety branch August 28, 2026 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Harden CSI parsing, Windows NO_COLOR compliance, readSecret abort, and mode token safety

1 participant