Skip to content

Limit length and improve exception message when processing long SSE line#128558

Open
mrek-msft wants to merge 2 commits into
dotnet:mainfrom
mrek-msft:dev/mrek/snsse-long-lines
Open

Limit length and improve exception message when processing long SSE line#128558
mrek-msft wants to merge 2 commits into
dotnet:mainfrom
mrek-msft:dev/mrek/snsse-long-lines

Conversation

@mrek-msft
Copy link
Copy Markdown
Member

No description provided.

Copilot AI review requested due to automatic review settings May 25, 2026 14:18
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@MihaZupan
Copy link
Copy Markdown
Member

Please add a test case

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 adds an upper bound to SSE line buffering to prevent unbounded growth when the parser encounters an extremely long line without a newline, and introduces a dedicated InvalidDataException message for that condition.

Changes:

  • Introduces a 64 MiB maximum line length and throws InvalidDataException when line buffer growth would exceed it.
  • Adds a new localized resource string for the new exception message.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/libraries/System.Net.ServerSentEvents/src/System/Net/ServerSentEvents/SseParser_1.cs Adds MaxLineLength and enforces it during line-buffer growth by throwing InvalidDataException.
src/libraries/System.Net.ServerSentEvents/src/Resources/Strings.resx Adds InvalidDataException_LineExceededMaxLength resource used by the new exception path.

Comment on lines +308 to +313
int newLength = _lineBuffer.Length * 2;
if (newLength > MaxLineLength)
{
throw new InvalidDataException(SR.InvalidDataException_LineExceededMaxLength);
}
GrowBuffer(ref _lineBuffer, newLength);
<value>The argument cannot be a negative value.</value>
</data>
<data name="InvalidDataException_LineExceededMaxLength" xml:space="preserve">
<value>SSE line exceeds maximum allowed length.</value>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants