Repository navigation
Conversation
close_submessage() returned early for submessages opened with a known size without resetting m_pos in the parent, so any further write to the parent hit the "existing submessage" assert. This affected e.g. packed_field_fixed32 with a size argument, as shown in the tutorial. m_pos now holds the expected end position for such submessages, and closing asserts that exactly that many bytes were written.
kkaefer
commented
Oct 14, 2026
| if (m_rollback_pos == size_is_known) { | ||
| const auto end_pos = m_pos; | ||
| m_pos = 0; | ||
| protozero_assert(buffer_customization<TBuffer>::size(m_data) == end_pos && "submessage with known size must have exactly that many bytes written"); |
Member
Author
There was a problem hiding this comment.
Should we throw here instead?
Member
Author
There was a problem hiding this comment.
Hmm, I guess overall in protozero, we use asserts for API misuse rather than throwing exceptions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a submessage was opened with a known size (e.g.
packed_field_fixed32 field{pw, 1, 2}, as in the tutorial), closing it never reset the parent'sm_pos. Any later write to the parent then hit the "existing submessage" assert in debug builds.Closing now resets the parent and asserts that exactly
sizebytes were written. Tests cover the correct, too-few and too-many element cases, plus a plain known-size submessage.