Skip to content

Port TlsFrameHelper bounds-check fixes from dotnet/runtime#3028

Merged
MihaZupan merged 1 commit into
mainfrom
copilot/update-tls-frame-helper-version
May 14, 2026
Merged

Port TlsFrameHelper bounds-check fixes from dotnet/runtime#3028
MihaZupan merged 1 commit into
mainfrom
copilot/update-tls-frame-helper-version

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 14, 2026

TlsFrameHelper.cs is a fork of the runtime's implementation. The only behavior-changing upstream commit since the YARP copy is dotnet/runtime#126352, which fixes 4 out-of-bounds reads found by SslStreamClientHelloFuzzer against crafted/truncated TLS frames. This PR ports those fixes.

Bounds checks added

  • TryParseClientHello / TryParseServerHello — guard p.Length < sizeof(ushort) before ReadUInt16BigEndian(p) for the extension list length. Truncated input with 1 byte remaining after compression methods previously threw ArgumentOutOfRangeException.
  • GetSniFromHostNameStruct — guard hostNameStruct.Length < HostNameOffset before reading the host name length.
  • TryGetSupportedVersionsFromExtension — guard extensionData.IsEmpty before indexing extensionData[VersionListLengthOffset].

Not ported

  • Upstream's helloLength < ProtocolVersionSize check in TryParseHelloFrame is already subsumed by YARP's stricter helloLength < MinimalHandshakeLength (44 > 2).
  • Pure-style changes (== false!, using reordering) and fixes already present in YARP (typos InsufficientSecurity/MaximumFragmentLength, TLS 1.0/1.1 obsoletion pragmas, unified SSL2 framing, ParsingStatus, cipher suite parsing).

Example

// TryParseClientHello, after skipping compression methods:
if (p.IsEmpty) { return true; }

if (p.Length < sizeof(ushort))   // <-- added; was reading past end
{
    return false;
}

int extensionListLength = BinaryPrimitives.ReadUInt16BigEndian(p);

@MihaZupan MihaZupan added this to the YARP 3.0 milestone May 14, 2026
@MihaZupan MihaZupan marked this pull request as ready for review May 14, 2026 18:12
@MihaZupan MihaZupan self-requested a review as a code owner May 14, 2026 18:12
@MihaZupan MihaZupan enabled auto-merge (squash) May 14, 2026 18:17
@MihaZupan MihaZupan requested a review from rzikm May 14, 2026 18:17
@MihaZupan MihaZupan merged commit 2bdfe18 into main May 14, 2026
7 checks passed
@MihaZupan MihaZupan deleted the copilot/update-tls-frame-helper-version branch May 14, 2026 19:42
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