Skip to content

From implementations for some WKTs break their contracts #690

Open
@panhania

Description

@panhania

From implementations for Timestamp and Duration well-known types that convert to standard library std::time::SystemTime and std::time::Duration state that they panic when given values out of the allowed range. However, this is against the contract that From imposes on implementations:

Note: This trait must not fail. The From trait is intended for perfect conversions. If the conversion can fail or is not perfect, use TryFrom.

This contract breakage is especially severe in the case of protobuf crate as Protocol Buffers messages usually contain data from "the outside" and should not be trusted. If the application relies on the fact that From conversion cannot fail (as I usually do), it means that a malformed message can easily bring it down.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions