Skip to content

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

@vriesk

Description

@vriesk

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-third-partyArea: implementations of traits from other cratesC-bugCategory: bug in current code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions