Repository navigation
Description
Summary
Parser._dispatch_osc() in src/libvt/parser.py (#2) parses OSC command numbers with int(head) if head.isdigit() else -1, which raises ValueError (Exceeds the limit (4300 digits) for integer string conversion) on untrusted OSC headers over 4,300 ASCII digits while accepting non-ASCII isdigit() bytes in downstream str.isdigit() checks (terminal.py, tmux.py) and unbounded int() strings in graphics.py. Meanwhile, _event_byte_cost() in src/libvt/terminal.py charges a flat 64 bytes for TitleChanged, WorkingDirectoryChanged, WindowRenamed, ProgramStatusChanged, and UnhandledSequence, letting max_events (4,096) retain hundreds of megabytes of string payloads despite Limits.max_event_bytes.
Reproduction
- Feed an OSC sequence with a
4,301-digit command prefix intoTerminal.feed():
uv run python -c 'from libvt import Terminal; vt = Terminal(rows=2, cols=10); vt.feed(b"\x1b]" + b"9" * 4301 + b";x\x07")'
Expected
Terminal.feed()andParser.feed()never raiseValueErroror other implementation exceptions on arbitrary untrusted byte streams (matchinglibghostty-vtterminal.hat11ed660d9untrusted-input semantics whenPolicy.strict=False).- Integer fields parse strictly ASCII digits
0x30..0x39with bounded accumulators: OSC command codes clamp/reject above65535(matching xtermdo_osc), KittyAPC Gi=andI=accept full unsigned32-bit IDs up to4,294,967,295(10ASCII digits), andOSC 133;Dexit codes parse bounded signed ASCII integers. _event_byte_cost()accounts for UTF-8 byte lengths of variable-size strings and dictionaries across everyEventvariant so unread_eventsmemory stays bounded byLimits.max_event_bytes.
Actual
ValueError: Exceeds the limit (4300 digits) for integer string conversion crashes Terminal.feed().
Environment
Versions
libvt:#2(0.1.0a0)- Python:
3.15.1 - OS: Linux
x86_64
Proposal
Invariants
The invariants below are load-bearing; everything under Intent is open.
- With
Policy.strict=False(default),Parser.feed(),Parser.feed_to(), andTerminal.feed()never raiseValueError,OverflowError,IndexError, orKeyErrorfor anybytesinput. - Only ASCII digits
0x30..0x39(plus leading-where signed values are defined by spec) are accepted as protocol numeric digits; Unicode superscripts and non-ASCII decimal characters never match. - Cumulative UTF-8 payload bytes across buffered
Terminalevents never exceedLimits.max_event_bytes.
Intent (non-binding)
- Add small ASCII byte/string integer helpers with explicit ceilings (
parse_ascii_uint(raw, max_value=...)andparse_ascii_int(...)) shared byparser.py,terminal.py,graphics.py, andtmux.py. - Measure UTF-8 string/control byte footprints across
TitleChanged,WindowRenamed,WorkingDirectoryChanged,ClipboardWrite,ProgramStatusChanged,KittyGraphic(control+payload),SixelGraphic,Passthrough, andUnhandledSequencein_event_byte_cost().
Not doing
- Raising
sys.set_int_max_str_digits()process-wide.
Activity
parser(fix[limits]): Bound ints and event bytes (#23)