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

fix: serde::Visitors should have visit_map rather that visit_seq called when deserializing structs #2905

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

jeswr
Copy link

@jeswr jeswr commented Feb 28, 2025

Working towards a fix of #2871. The underlying issue of which is that in serde::Visitors should have visit_map rather that visit_seq called when deserializing structs.

Marking as ready for review as feedback is needed on this comment.

Note, the implementation of WordRead for &str is co-pilot generated and requires checking before merging.

Copy link

vercel bot commented Feb 28, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview Mar 11, 2025 3:17pm

Copy link

vercel bot commented Feb 28, 2025

@jeswr is attempting to deploy a commit to the RISC Zero Team on Vercel.

A member of the Team first needs to authorize it.

Comment on lines +460 to +463
visitor.visit_map(MapAccess {
deserializer: self,
len: fields.len(),
})
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a slight hack; to implement this properly MapAccess should be checking that only the fields defined in fields are being passed to the map visitor.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@flaub Before I proceed to:

  • add this check to MapAccess, and
  • add a test cases where there are entries in the struct

Could I please ask you to review this draft PR - to confirm:

  • The previous use of deserialize_seq here was a bug rather than the intended behavior
  • That you are comfortable with moving forward by adding an Optional fields property to MapAccess; which would add validation behavior to the keys iterated through by MapAccess.

Copy link
Author

@jeswr jeswr Feb 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that the change introduces the following test failures:

failures:

---- serde::deserializer::tests::test_struct stdout ----
thread 'serde::deserializer::tests::test_struct' panicked at risc0/zkvm/src/serde/deserializer.rs:576:49:
called `Result::unwrap()` on an `Err` value: NotSupported

---- serde::deserializer::tests::test_str stdout ----
thread 'serde::deserializer::tests::test_str' panicked at risc0/zkvm/src/serde/deserializer.rs:594:49:
called `Result::unwrap()` on an `Err` value: NotSupported
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    serde::deserializer::tests::test_str
    serde::deserializer::tests::test_struct

It is unclear to me whether this is a "bug in the tests"; in that I am unsure if they are testing for behviors which conflict with serde behavior.

The error here appears to be because deserialize_identifer is not implemented - which I am unsure how to implement.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #2906 to try and answer this question, would be good if CI can be run on that PR.

@jeswr jeswr marked this pull request as ready for review February 28, 2025 20:24
@jeswr jeswr requested a review from a team as a code owner February 28, 2025 20:24
@jeswr jeswr changed the title chore: add Visitor test fix: serde::Visitors should have visit_map rather that visit_seq called when deserializing structs Feb 28, 2025
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

Successfully merging this pull request may close these issues.

1 participant