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

mime: ParseMediaType can parse something FormatMediaType can't reformat #56614

Open
joewreschnig opened this issue Nov 6, 2022 · 1 comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@joewreschnig
Copy link

joewreschnig commented Nov 6, 2022

During fuzzing some custom HTTP request handling of my own I discovered a Content-Type #;*0="" which mime.ParseMediaType is happy to parse more or less as I would expect without error, but for which mime.FormatMediaType returns an empty string indicating some part of it is invalid.

I'm not familiar enough with the details of the relevant standards to say which of the two is correct - I seriously doubt anyone needs it to be valid - but these two functions should probably agree on whether it's valid or not.

It seems possibly related to, but the impact is distinct from, #43128.

What version of Go are you using (go version)?

$ go version
go version go1.19.3 linux/amd64

But also reproducible on go.dev.

What did you do?

https://go.dev/play/p/oeqtYtq72MY

	t, param, err := mime.ParseMediaType(`#;*0=""`)
	fmt.Printf("%q, %+v, %+v\n", t, param, err)
	fmt.Printf("%q", mime.FormatMediaType(t, param))

What did you expect to see?

An error during parsing, or some non-empty equivalent media type when reformatted:

"#", map[:], <nil>
"#;*0=\"\""

What did you see instead?

"#", map[:], <nil>
""
@mknyszek
Copy link
Contributor

mknyszek commented Nov 7, 2022

CC @neild

@mknyszek mknyszek added this to the Backlog milestone Nov 7, 2022
@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

2 participants