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

Formatting timestamp with %#z panics #1139

Closed
domodwyer opened this issue Jun 8, 2023 · 3 comments
Closed

Formatting timestamp with %#z panics #1139

domodwyer opened this issue Jun 8, 2023 · 3 comments

Comments

@domodwyer
Copy link
Contributor

When attempting to format a timestamp with a strftime format string containing %#z it panics:

panic!("Do not try to write %#z it is undefined")

This specifier is documented as being "parsing only" here, but we accept format strings from users (limited/validated) who may put %#z in the formatting sequence.

All other invalid cases (that I can see!) result in Err(std::fmt::Error) being returned:

return Err(fmt::Error); // insufficient arguments for given format

This has the benefit of allowing the caller to handle the error when the timestamp formatter is invalid (as long as you're not using the infallible to_string()). This is one way we validate a user-provided strftime formatter - try and use it, catching any errors - but obviously this doesn't work for %#z because it immediately panics! Thsi was unexpected - we only discovered it through fuzz testing.

Is there a reason %#z panics over returning an error? I'd be happy to PR the change to return the error & test.

@djc
Copy link
Member

djc commented Jun 8, 2023

Yeah, happy to review a PR for this!

@pitdicker
Copy link
Collaborator

@domodwyer It just so happens that we are looking at this code the last couple of days. In #1127 we try to come up with a way to not panic but find a good place to report en errors.

@pitdicker
Copy link
Collaborator

If it spares some work, the last commit here has the change and a test: #1121

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants