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: incorrect read_slice impl for ReadAdapter #309

Merged
merged 2 commits into from
Sep 7, 2024

Conversation

bitwalker
Copy link
Contributor

@bitwalker bitwalker commented Sep 6, 2024

This commit fixes a bug that is present in the implementation of ByteReader::read_slice for ReadAdapter. Specifically, it does not consume any input, so calling read_slice and then attempting to read the next value in the input, will read the same bytes again. The documented behavior of this function is that any of the read_* methods consume the corresponding amount of input.

To catch this, and to prevent future regressions, a new test was added that serializes some data to a file using one approach, and deserializes it using the ReadAdapter. This ensures that we don't accidentally make choices in the writer that aren't matched by the reader, and vice versa.

Closes #308

@bitwalker
Copy link
Contributor Author

@irakliyk This fixes #308, and also addresses the issue in Miden when deserializing Library or Program from files.

Copy link
Collaborator

@irakliyk irakliyk left a comment

Choose a reason for hiding this comment

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

Looks good! Thank you for fixing this!

Since this is a non-breaking change, could you change the base to main? This way, I could make a patch release which would fix things immediately downstream.

@bitwalker bitwalker changed the base branch from next to main September 6, 2024 23:38
This commit fixes a bug that is present in the implementation of
ByteReader for ReadAdapter. Specifically, it does not consume any input,
so calling `read_slice` and then attempting to read the next value in
the input, will read the same bytes again. The documented behavior of
this function is that any of the `read_*` methods consume the
corresponding amount of input.

To catch this, and to prevent future regressions, a new test was added
that serializes some data to a file using one approach, and deserializes
it using the ReadAdapter. This ensures that we don't accidentally make
choices in the writer that aren't matched by the reader, and vice versa.

Closes facebook#308
@bitwalker
Copy link
Contributor Author

@irakliyk Done!

@irakliyk irakliyk merged commit c9834a3 into facebook:main Sep 7, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ReadAdapter is broken
3 participants