Skip to content

Cherry pick #133530 to 26.3: Fix handling of groups and named unions in CapnProto format - #133754

Merged
robot-ch-test-poll merged 9 commits into
backport/26.3/133530from
cherrypick/26.3/133530
Nov 23, 2026
Merged

robot-ch-test-poll merged 9 commits into
backport/26.3/133530from
cherrypick/26.3/133530

Conversation

@robot-ch-test-poll3

Copy link
Copy Markdown
Contributor

Original pull-request #133530

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

nikitamikhaylov and others added 8 commits November 22, 2026 14:50
A Cap'n Proto group (`g :group { ... }`, and a named union
`u :union { ... }` as well) is stored inline in the struct that contains
it. The serializer treated such a field as a pointer field of the parent
struct, so the data was written to and read from the wrong place, and
for a parent struct without pointers the access was out of bounds of the
struct.

Access the group through the storage of its parent struct, both when
writing and when reading, and do not read the slot offset from the proto
of a field that is not a slot.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…n `CapnProto`

Address review: `CapnProtoNullableSerializer` took the slot offset of the
value from the first member of the union, assuming both members have the
same offset. This holds for a standalone struct with a union, but not for
a named union declared inline in a struct: the `Void` member always has
offset 0, while the value can be in any slot of the enclosing struct. For
a union with the `Void` member first, the value was written over (and read
from) the slot 0 of the parent, corrupting a sibling field.

Now the offset is taken from the non-`Void` member.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
…in `CapnProto`

Address review: for a column with a flattened name such as `g.h` and the
type `Tuple`, `CapnProtoStructureSerializer` for `g` is an adapter with a
single field serializer (for `h`), but `writeRowImpl` and `readRowImpl`
decided what to do by the type of the column: for `ColumnTuple` they
iterated over the tuple elements and accessed `fields_serializers` and
`fields_offsets` out of bounds.

Now the serializer remembers whether it maps a struct to a `Tuple`, and
otherwise passes the whole column to its single field. This affected both
groups and standalone structs.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Extend `05843_capnproto_group_fields` with:
- named unions with the `Void` member first, declared after other data and
  pointer fields, so the value is not in the slot 0; the written data is
  also read through a struct with the same layout and plain fields to check
  that the sibling fields and the discriminants are in the right places;
- a `Tuple` column under a flattened name (`g.h`), for a group and for a
  standalone struct.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Columns with flattened names (like `l.x` and `l.y`) are written to the
same list and share its cached builder, which is created with the size
of the first array. An array of another size was then written through
that builder: a longer one accessed its element builders out of bounds,
a shorter one silently left the remaining elements unset.

Throw `SIZES_OF_ARRAYS_DONT_MATCH` in `CapnProtoArraySerializer` instead.
It applies to lists inside groups and inside standalone structs.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Fix handling of groups and named unions in CapnProto format
@robot-ch-test-poll3 robot-ch-test-poll3 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-critical-bugfix labels Nov 23, 2026
…ypick/26.3/133530

Resolve the conflict in `CapnProtoSerializer.cpp`: keep the 26.3 member declarations and add `is_tuple`.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@robot-ch-test-poll
robot-ch-test-poll merged commit cd33386 into backport/26.3/133530 Nov 23, 2026
2 checks passed
@robot-ch-test-poll
robot-ch-test-poll deleted the cherrypick/26.3/133530 branch November 23, 2026 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! pr-critical-bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants