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

sstable/block: fix Buffer growth bug #4249

Merged
merged 1 commit into from
Jan 10, 2025

Conversation

jbowens
Copy link
Collaborator

@jbowens jbowens commented Jan 10, 2025

Fix a bug whereby Buffer.AppendValue would fail to sufficiently grow the capacity of its backing byte slice. Previously, AppendValue used cap(buf) when calculating the argument to slices.Grow, but slices.Grow expects its argument to be in terms of the slice's current length, not capacity.

Add a focused randomized test that catches the bug. Also, add invariant assertions around a BufHandle's existence in or out of a pool.

Fix #4247.

@jbowens jbowens requested a review from a team as a code owner January 10, 2025 20:29
@jbowens jbowens requested a review from sumeerbhola January 10, 2025 20:29
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@jbowens jbowens requested a review from RaduBerinde January 10, 2025 20:43
Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

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

:lgtm:

Reviewable status: 0 of 2 files reviewed, 1 unresolved discussion (waiting on @jbowens and @sumeerbhola)


sstable/block/compression.go line 453 at r1 (raw file):

// buffer.
func (p *bufferSyncPool) Put(bh *BufHandle) {
	if bh.pool == nil {

[nit] should we check that bh.pool == p.pool?

Fix a bug whereby Buffer.AppendValue would fail to sufficiently grow the
capacity of its backing byte slice. Previously, AppendValue used cap(buf) when
calculating the argument to slices.Grow, but slices.Grow expects its argument
to be in terms of the slice's current length, not capacity.

Add a focused randomized test that catches the bug. Also, add invariant
assertions around a BufHandle's existence in or out of a pool.

Fix cockroachdb#4247.
Copy link
Collaborator Author

@jbowens jbowens left a comment

Choose a reason for hiding this comment

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

TFTR!

Reviewable status: 0 of 2 files reviewed, all discussions resolved (waiting on @sumeerbhola)


sstable/block/compression.go line 453 at r1 (raw file):

Previously, RaduBerinde wrote…

[nit] should we check that bh.pool == p.pool?

Done

@jbowens jbowens merged commit ce9b648 into cockroachdb:master Jan 10, 2025
23 checks passed
@jbowens jbowens deleted the blockbuffer-bug branch January 10, 2025 22:39
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.

valblk: out-of-bounds in Writer.AddValue
3 participants