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

Deserializer::deserialize_struct is incorrect #114

Open
Mingun opened this issue Oct 28, 2023 · 1 comment
Open

Deserializer::deserialize_struct is incorrect #114

Mingun opened this issue Oct 28, 2023 · 1 comment

Comments

@Mingun
Copy link

Mingun commented Oct 28, 2023

During investigation of correct serde deserializers behavior I found, that postcard implements struct deserialization incorrectly:

  • first of all, it deserializes structs using Visitor::visit_seq:
    fn deserialize_struct<V>(
    self,
    _name: &'static str,
    fields: &'static [&'static str],
    visitor: V,
    ) -> Result<V::Value>
    where
    V: Visitor<'de>,
    {
    self.deserialize_tuple(fields.len(), visitor)
    }

    That method is intended only to provide data for sequential types. To provide data for map types you should call visit_map which would use a special deserializer to deserialize keys
  • it uses fields.len() as expected tuple size, which is not correct if some fields has aliases. You are never known the count of fields in a struct.
@jamesmunns
Copy link
Owner

This is potentially correct, though postcard generally doesn't support many of the serde attributes such as alias, external tagging, etc.

If there is a better way to handle this if we'd like to disregard these attributes, I'm defintiely interested!

Thanks for the report.

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

2 participants