Skip to content

Fix address-instability in MultiSegmentArena by storing *Segment and validating via (id, arena storage)#607

Merged
lthibault merged 1 commit intocapnproto:mainfrom
saikocat:issue-606
Oct 24, 2025
Merged

Fix address-instability in MultiSegmentArena by storing *Segment and validating via (id, arena storage)#607
lthibault merged 1 commit intocapnproto:mainfrom
saikocat:issue-606

Conversation

@saikocat
Copy link
Copy Markdown
Contributor

This attempts to fix #606 - MultiSegmentArena: preferred segment is not part of the arena

  • Replace []Segment with []*Segment in MultiSegmentArena to avoid address-instability on append.
  • Make Segment(id) return the stable pointer from msa.segs (no &msa.segs[id]).
  • In Allocate, validate the preferred segment in O(1) by checking seg.id is in-range and msa.segs[seg.id] == seg; remove the linear pointer scan.
  • Keep msa.segs length in sync with the byte-storage (msa.segs[i].data).
  • Ensure Release() zeroises and returns buffers, then clears pointers safely.

Copy link
Copy Markdown
Collaborator

@lthibault lthibault left a comment

Choose a reason for hiding this comment

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

LGTM. Approving once it clears CI.

@lthibault lthibault merged commit e26d1c6 into capnproto:main Oct 24, 2025
4 checks passed
@lthibault
Copy link
Copy Markdown
Collaborator

Do I need to cut a release?

@saikocat
Copy link
Copy Markdown
Contributor Author

Yes, I think so. This is due to previous version is buggy with MultiSegment.

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.

MultiSegmentArena: preferred segment is not part of the arena

2 participants