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 there are exactly 32 hasbits, we were allocating only 4 bytes for hasbits, leading to an overlap in the message layout. Hasbits were being allocated to the same offset as a regular data member. This caused data corruption.
upb's hasbits are identified by a zero-based index, so the hasbit can be calculated with
1 << index
. However we do not use hasbit index 0, as 0 indicates "no presence" (either a proto3 singular field, or a repeated/map field). Therefore 32 hasbits will be assigned to the indexes 1-32. The value1 << 32
exceeds four bytes, and therefore requires that we allocate at least five bytes to hasbits. But our math had an off-by-one error:This expression evaluated to four when
hasbit_count_
is 32. The fix is to add one, so that when we are using hasbit index 32, we allocate five bytes instead of four.Fixes: protocolbuffers/protobuf#9440 (this will require an explicit sync to Ruby & PHP).