Skip to content

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

@joewreschnig

Description

@joewreschnig

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>
""

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions