← Back to Pull requests

Ignore out-of-range color table indices in OSC 4 and OSC 104 #20991

Closed
unknown closed this pull request without merging on Nov 28, 2026 16:58 UTC
View on GitHub
unknown unknown commented on Nov 28, 2026 12:43 UTC
Author

Summary of the Pull Request

This PR prevents OSC 4 (set/query color table entry) and OSC 104 (reset color table entry) from addressing indices outside the 256-entry xterm color table, and fixes integer overflow wraparound in Utils::StringToUint by clamping overflowing values to UINT_MAX.

References and Relevant Issues

N/A

Detailed Description of the Pull Request / Additional comments

Currently, OutputStateMachineEngine does not bound-check the color table index parsed in _GetOscSetColorTable (OSC 4) or ActionOscDispatch (OSC 104):

1. Out-of-bounds indices (>= 256):
- Indices in the range 256..266 address internal entries at the end of RenderSettings::_colorTable (such as default foreground/background, cursor color, selection background, etc.) which are meant to be managed via their respective sequences/aliases rather than indexed xterm palette sequences.
- Indices >= 267 (TextColor::TABLE_SIZE) cause _colorTable.at(tableIndex) in RenderSettings to throw std::out_of_range. When an OSC 4 or OSC 104 sequence specifies multiple color indices and one of them is out of range (e.g. OSC 4;300;rgb:1/1/1;255;rgb:2/2/2 ST or OSC 104;1;300;255 ST), the exception aborts the dispatch loop and prevents any subsequent valid entries in the same sequence from being applied.

2. 32-bit unsigned integer wraparound in Utils::StringToUint:
- Utils::StringToUint accumulates decimal digits into an unsigned int without checking for overflow. As a result, a large index such as 4294967297 ($2^{32} + 1$) silently wraps around to 1 and modifies or queries color table entry 1.
- Clamping overflowing values to UINT_MAX in Utils::StringToUint (matching how CSI parameter accumulation saturates in StateMachine::_AccumulateTo) ensures that huge numbers remain out of range rather than wrapping around to small valid values.

Validation Steps Performed

  • Added unit tests in OutputEngineTest (TestOscSetColorTable, TestOscGetColorTableEntry, and TestOscColorTableReset) covering out-of-range indices (256, 261, 267, 300, 4294967297) as well as sequences mixing out-of-range and valid indices.

  • Added unit tests in UtilsTests::TestStringToUint verifying that values exceeding UINT_MAX saturate to UINT_MAX.
  • PR Checklist


  • Closes #xxx

  • Tests added/passed

  • Documentation updated

  • - If checked, please file a pull request on our docs repo and link it here: #xxx
  • Schema updated (if necessary)
  • Diff: 322 lines (+241 / -81) across 4 files Reviewer: DHowett Review duration: 254m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.47) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 322 lines diff across 4 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.346
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #20991"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 46.9% (MEDIUM) · Higher = larger blast radius
    46.9%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 18.6% · Safe to merge
    18.6%