Limit length and improve exception message when processing long SSE line#128558
Open
mrek-msft wants to merge 2 commits into
Open
Limit length and improve exception message when processing long SSE line#128558mrek-msft wants to merge 2 commits into
mrek-msft wants to merge 2 commits into
Conversation
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/ncl |
Member
|
Please add a test case |
Contributor
There was a problem hiding this comment.
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
InvalidDataExceptionwhen 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.