Skip to content
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

ViaHeaderValue throws on TryParse #72677

Closed
MihaZupan opened this issue Jul 22, 2022 · 2 comments · Fixed by #72741
Closed

ViaHeaderValue throws on TryParse #72677

MihaZupan opened this issue Jul 22, 2022 · 2 comments · Fixed by #72741

Comments

@MihaZupan
Copy link
Member

var headers = new HttpResponseMessage().Headers;
headers.TryAddWithoutValidation("Via", "1.1 foo.bar, foo");

foreach (var h in headers) { } // Throws
System.ArgumentException: The value cannot be null or empty. (Parameter 'protocolVersion')
   at System.Net.Http.Headers.HeaderUtilities.CheckValidToken(String value, String parameterName)
   at System.Net.Http.Headers.ViaHeaderValue..ctor(String protocolVersion, String receivedBy, String protocolName, String comment)
   at System.Net.Http.Headers.ViaHeaderValue.GetViaLength(String input, Int32 startIndex, Object& parsedValue)
   at System.Net.Http.Headers.GenericHeaderParser.GetParsedValueLength(String value, Int32 startIndex, Object storeValue, Object& parsedValue)
   at System.Net.Http.Headers.BaseHeaderParser.TryParseValue(String value, Object storeValue, Int32& index, Object& parsedValue)
   at System.Net.Http.Headers.HttpHeaders.TryParseAndAddRawHeaderValue(HeaderDescriptor descriptor, HeaderStoreItemInfo info, String value, Boolean addWhenInvalid)
   at System.Net.Http.Headers.HttpHeaders.ParseSingleRawHeaderValue(HeaderDescriptor descriptor, HeaderStoreItemInfo info)
   at System.Net.Http.Headers.HttpHeaders.ParseRawHeaderValues(HeaderDescriptor descriptor, HeaderStoreItemInfo info, Boolean removeEmptyHeader)
   at System.Net.Http.Headers.HttpHeaders.GetEnumeratorCore()+MoveNext()

TryParse should never throw. In this case, it throws from the ViaHeaderValue ctor as the protocolVersion was not parsed. I assume this debug assert would trigger here as well.

This would silently succeed without throwing (but still storing a null value) before 5.0 (#47205).

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jul 22, 2022
@ghost
Copy link

ghost commented Jul 22, 2022

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

Issue Details
var headers = new HttpResponseMessage().Headers;
headers.TryAddWithoutValidation("Via", "1.1 foo.bar, foo");

foreach (var h in headers) { } // Throws
System.ArgumentException: The value cannot be null or empty. (Parameter 'protocolVersion')
   at System.Net.Http.Headers.HeaderUtilities.CheckValidToken(String value, String parameterName)
   at System.Net.Http.Headers.ViaHeaderValue..ctor(String protocolVersion, String receivedBy, String protocolName, String comment)
   at System.Net.Http.Headers.ViaHeaderValue.GetViaLength(String input, Int32 startIndex, Object& parsedValue)
   at System.Net.Http.Headers.GenericHeaderParser.GetParsedValueLength(String value, Int32 startIndex, Object storeValue, Object& parsedValue)
   at System.Net.Http.Headers.BaseHeaderParser.TryParseValue(String value, Object storeValue, Int32& index, Object& parsedValue)
   at System.Net.Http.Headers.HttpHeaders.TryParseAndAddRawHeaderValue(HeaderDescriptor descriptor, HeaderStoreItemInfo info, String value, Boolean addWhenInvalid)
   at System.Net.Http.Headers.HttpHeaders.ParseSingleRawHeaderValue(HeaderDescriptor descriptor, HeaderStoreItemInfo info)
   at System.Net.Http.Headers.HttpHeaders.ParseRawHeaderValues(HeaderDescriptor descriptor, HeaderStoreItemInfo info, Boolean removeEmptyHeader)
   at System.Net.Http.Headers.HttpHeaders.GetEnumeratorCore()+MoveNext()

TryParse should never throw. In this case, it throws from the ViaHeaderValue ctor as the protocolVersion was not parsed. I assume this debug assert would trigger here as well.

This would silently succeed without throwing (but still storing a null value) before 5.0 (#47205).

Author: MihaZupan
Assignees: -
Labels:

bug, area-System.Net.Http

Milestone: -

@karelz
Copy link
Member

karelz commented Jul 22, 2022

Triage: Regression against 5.0 -- throwing is much worse (from TryParse than invalid output).
It was reported by 1 customer.
Unless it is costly, we should fix it in 7.0.

@karelz karelz added this to the 7.0.0 milestone Jul 22, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jul 22, 2022
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 24, 2022
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jul 25, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Aug 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants