console: a bare ESC[m is a reset, and OSC sequences are consumed
Two ANSI bugs, both found by running fastfetch rather than by reading the parser, and both invisible to anything that spells its escapes out in full. ESC[m with no parameters means ESC[0m. ECMA-48 is explicit that an omitted parameter takes its default and SGR's default is 0, and sgr() iterated its parameter list -- which is empty in exactly that case, so the loop body never ran and the reset was silently dropped. Programs emit the bare form constantly. fastfetch writes "\x1b[32m1%\x1b[m", so everything after the first coloured character stayed green forever. With a background colour it is much worse: its palette swatch sets a white background and resets, the reset did nothing, and the console went white-on-white and stayed there -- filling the screen with white rectangles as it scrolled, which looks like a corrupted framebuffer rather than one missing branch. OSC sequences were not a state at all, so ESC ] fell through and the payload printed as text: a hyperlinked path arrived as "Disk (]8;;file:///\]8;;\)". Nothing here acts on an operating-system command -- there is no window title and no hyperlink to follow -- but *discarding* one is not optional, because the alternative is printing somebody's URL into the middle of their output. ESC \ ends it, and an ESC followed by anything else is handed back to the escape state rather than eaten, so a malformed OSC does not swallow the sequence after it. Verified by screendumping the framebuffer after two consecutive fastfetch runs: identical output both times, near-white coverage down from most of the screen to 2% (the palette swatch's own white cell), and the disk line reading "Disk (/)". Also installs docs/branding/Ascii/ascii_50.txt as /usr/share/schos/logo.txt -- Shift as characters, at the width that leaves room for an info block on an 80-column console. Installed from the branding directory rather than copied into sysroot by hand, so there is one source. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VQ7Qx8E1q1M1bbCq8QLHS2
This commit is contained in:
parent
f395c39704
commit
1754cbf1aa
8 changed files with 292 additions and 4 deletions
|
|
@ -217,7 +217,11 @@ static uint32 cons_bg = CONS_DEFAULT_BG;
|
|||
static int cons_bold = 0;
|
||||
|
||||
// Escape parser state.
|
||||
enum { E_NORMAL, E_ESC, E_CSI };
|
||||
// E_OSC and E_OSC_ESC exist for hyperlinks. A terminal that does not follow
|
||||
// them must still *consume* them, or the URL is printed as text -- which is
|
||||
// what "Disk (]8;;file:///\]8;;\): 4.6 MiB" was: fastfetch wrapping a path in
|
||||
// OSC 8, and this console spelling it out.
|
||||
enum { E_NORMAL, E_ESC, E_CSI, E_OSC, E_OSC_ESC };
|
||||
static int esc_state = E_NORMAL;
|
||||
static int esc_parm[8];
|
||||
static int esc_nparm;
|
||||
|
|
@ -302,7 +306,19 @@ glyph_for(uint32 cp)
|
|||
static void
|
||||
sgr(void)
|
||||
{
|
||||
for (int i = 0; i < esc_nparm; i++) {
|
||||
// "ESC[m" with no parameters means ESC[0m -- reset -- and ECMA-48 says so for
|
||||
// every CSI: an omitted parameter takes its default, and SGR's default is 0.
|
||||
//
|
||||
// This loop used to start at a count of zero and therefore do nothing, so a
|
||||
// bare reset was silently dropped. Programs emit it constantly: fastfetch
|
||||
// writes "\x1b[32m1%\x1b[m", and with the reset ignored everything after the
|
||||
// first coloured character stayed green forever. Worse with background
|
||||
// colours -- its palette swatch sets a white background and resets, so the
|
||||
// whole console went white-on-white and stayed there, which looks like a
|
||||
// corrupted framebuffer rather than a missing branch.
|
||||
int nparm = esc_nparm ? esc_nparm : 1; // esc_parm[0] is already 0
|
||||
|
||||
for (int i = 0; i < nparm; i++) {
|
||||
int p = esc_parm[i];
|
||||
|
||||
if (p == 0) {
|
||||
|
|
@ -392,6 +408,10 @@ gfx_feed(int c)
|
|||
for (int i = 0; i < 8; i++) esc_parm[i] = 0;
|
||||
return;
|
||||
}
|
||||
if (c == ']') { // OSC: swallow it, see below
|
||||
esc_state = E_OSC;
|
||||
return;
|
||||
}
|
||||
esc_state = E_NORMAL;
|
||||
if (c == 'c') { // RIS -- full reset
|
||||
cons_fg = CONS_DEFAULT_FG;
|
||||
|
|
@ -400,6 +420,24 @@ gfx_feed(int c)
|
|||
}
|
||||
return; // other two-byte escapes: ignored
|
||||
|
||||
// An operating-system command runs until BEL or until ST (ESC \). Nothing
|
||||
// here acts on one -- there is no window title to set and no hyperlink to
|
||||
// follow -- but discarding the payload is not optional: the alternative is
|
||||
// printing somebody's URL into the middle of their output.
|
||||
case E_OSC:
|
||||
if (c == '\a') { esc_state = E_NORMAL; return; }
|
||||
if (c == '\x1b') { esc_state = E_OSC_ESC; return; }
|
||||
return;
|
||||
|
||||
case E_OSC_ESC:
|
||||
// ESC \ ends it; ESC anything-else means the OSC was malformed and a new
|
||||
// escape has started, so hand the byte to the ESC state rather than eating
|
||||
// it. Dropping it would lose the sequence that follows.
|
||||
if (c == '\\') { esc_state = E_NORMAL; return; }
|
||||
esc_state = E_ESC;
|
||||
gfx_feed(c);
|
||||
return;
|
||||
|
||||
case E_CSI:
|
||||
if (c == '?') { esc_private = 1; return; }
|
||||
if (c >= '0' && c <= '9') {
|
||||
|
|
|
|||
Loading…
Reference in a new issue