Skip to content

Fix invalid catch block in StringUtilities #49082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 29, 2023
Merged

Conversation

GrabYourPitchforks
Copy link
Member

The method Encoding.GetByteCount will never throw DecoderFallbackException. Instead, the two exceptions it can throw which are relevant here are:

  • ArgumentOutOfRangeException, when the input is so large that it the UTF-8 byte count can't be represented in a 32-bit integer; and
  • EncoderFallbackException, when the input is not valid UTF-16.

This PR corrects the catch block to detect these two exceptional cases.

@ghost ghost added the area-runtime label Jun 28, 2023
@GrabYourPitchforks
Copy link
Member Author

Erk, that commit contains a syntax error and wasn't supposed to go through as-is. Let me fix it.

@adityamandaleeka adityamandaleeka merged commit bbd739c into main Jun 29, 2023
@adityamandaleeka adityamandaleeka deleted the levib/fallback branch June 29, 2023 18:04
@ghost ghost added this to the 8.0-preview7 milestone Jun 29, 2023
@@ -683,9 +683,13 @@ private static bool IsValidHeaderString(string value)
new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true).GetByteCount(value);
return !value.Contains('\0');
}
catch (DecoderFallbackException)
catch (ArgumentOutOfRangeException)
Copy link
Member

Choose a reason for hiding this comment

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

method itself should probably be [Conditional("DEBUG")]

@amcasey amcasey added area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions and removed area-runtime labels Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants