Skip to content

Fix unvalidated TerminalProfileSize during distribution import - #41495

Merged
Ben Hillis (benhillis) merged 2 commits into
microsoft:masterfrom
benhillis:fix/terminal-profile-size-bounds
Sep 2, 2026
Merged

Fix unvalidated TerminalProfileSize during distribution import#41495
Ben Hillis (benhillis) merged 2 commits into
microsoft:masterfrom
benhillis:fix/terminal-profile-size-bounds

Conversation

@benhillis

@benhillis Ben Hillis (benhillis) commented Sep 1, 2026

Copy link
Copy Markdown
Member

Summary

LxssUserSessionImpl::_ProcessImportResultMessage builds a string_view over the terminal profile data using the message's TerminalProfileSize field directly, without validating it against the size of the received buffer. If the value is inconsistent with the actual buffer length, the resulting string_view extends past the end of the buffer.

Fix

Use the bounds-checked two-argument gsl::span::subspan(offset, count) overload instead of the single-argument form, matching the pattern already used a few lines above for ShortcutIconIndex/ShortcutIconSize. This ensures offset + count is validated against the span size before it's used to build the string_view.

Copilot AI lite review requested due to automatic review settings September 1, 2026 19:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a potential out-of-bounds read in LxssUserSessionImpl::_ProcessImportResultMessage when constructing a std::string_view for Windows Terminal profile data during distribution import, by validating TerminalProfileSize against the received buffer length via gsl::span.

Changes:

  • Switch Span.subspan(Message.TerminalProfileIndex) to Span.subspan(Message.TerminalProfileIndex, Message.TerminalProfileSize) so offset + count is validated.
  • Build the std::string_view using the resulting span’s actual size (terminalProfileSpan.size()) rather than trusting the message size field directly.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@benhillis
Ben Hillis (benhillis) marked this pull request as ready for review September 1, 2026 19:06
@benhillis
Ben Hillis (benhillis) requested a review from a team as a code owner September 1, 2026 19:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is minimal, matches the existing local pattern for other payload slices, and directly addresses the described out-of-bounds risk.

Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

Ben Hillis and others added 2 commits September 1, 2026 15:44
_ProcessImportResultMessage constructed the terminal profile string_view
using the message-supplied TerminalProfileSize without validating it
against the received buffer length. Use the bounds-checked two-argument
span::subspan() overload (matching the existing ShortcutIconSize handling
a few lines above) so an inconsistent size value throws instead of
producing a string_view that runs past the end of the buffer.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 35281c30-3d08-4f05-8c84-2ce4711023d5
Copilot AI review requested due to automatic review settings September 1, 2026 22:44
@benhillis
Ben Hillis (benhillis) force-pushed the fix/terminal-profile-size-bounds branch from 493d601 to 2af9b69 Compare September 1, 2026 22:44
@benhillis
Ben Hillis (benhillis) enabled auto-merge (squash) September 1, 2026 22:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is minimal, matches an existing validated pattern in the same function, and directly addresses the out-of-bounds string_view risk.

Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

@benhillis
Ben Hillis (benhillis) merged commit f2d87e0 into microsoft:master Sep 2, 2026
9 checks passed
@benhillis
Ben Hillis (benhillis) deleted the fix/terminal-profile-size-bounds branch September 2, 2026 18:39
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.

3 participants