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

Serialization data corruption with Duration and serde_human_readable for negative subsecond durations #691

Closed
vriesk opened this issue Jul 7, 2024 · 1 comment
Labels
A-third-party Area: implementations of traits from other crates C-bug Category: bug in current code

Comments

@vriesk
Copy link
Contributor

vriesk commented Jul 7, 2024

The issue is here:

self.whole_seconds(),

When feature serde_human_readable is enabled, the serializing code incorrectly assumes that for a sub-second negative duration, the self.whole_seconds() will provide the sign during printing. Similar issue exists with deserialization code.

The bug will result with subsecond negative Durations being serialized into positive ones, and negative elsewhere-serialized Durations to be deserialized into positive ones.

Also the comment here:

/// Number of nanoseconds within the second. The sign always matches the `seconds` field.
is incorrect - the nanoseconds sign will NOT match the seconds sign when seconds is 0 and nanoseconds is negative.

@vriesk
Copy link
Contributor Author

vriesk commented Jul 7, 2024

Suggested fix here: #692

@jhpratt jhpratt added C-bug Category: bug in current code A-third-party Area: implementations of traits from other crates labels Oct 8, 2024
@jhpratt jhpratt closed this as completed Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-third-party Area: implementations of traits from other crates C-bug Category: bug in current code
Projects
None yet
Development

No branches or pull requests

2 participants