Skip to content

fix(planstate): leave the plan unchanged when an appended layer fails validation - #937

Open
lenamonj wants to merge 1 commit into
canonical:masterfrom
lenamonj:planstate-append-rollback
Open

fix(planstate): leave the plan unchanged when an appended layer fails validation#937
lenamonj wants to merge 1 commit into
canonical:masterfrom
lenamonj:planstate-append-rollback

Conversation

@lenamonj

@lenamonj lenamonj commented Sep 7, 2026

Copy link
Copy Markdown

A pebble add --inner whose layer parses but fails plan validation leaves the daemon's live layer list changed.

appendLayer inserted with slices.Insert(m.plan.Layers, ...). When the slice has spare capacity, slices.Insert shifts the existing elements in place, so the new layer was spliced into m.plan.Layers before updatePlanLayers validated the result; when validation failed, that mutation stayed. CombineLayer already copies before mutating.

Insert into slices.Clone(m.plan.Layers) instead. The success path is unchanged: same index, same Order, same returned plan.

The regression test appends five layers with the sub-directory layer first, so the insert index is not the end and the slice has spare capacity, then appends a layer that fails validation. On master it fails with the layer list read as [foo/one foo/two bbb ccc ddd].

go test -race ./..., go build ./cmd/pebble, gofmt, staticcheck pass.

… validation

appendLayer inserted with slices.Insert on m.plan.Layers itself. When the slice has spare capacity the insert shifts elements in place, so a layer that then failed plan validation was already spliced into the live layer list and stayed there. Insert into a clone; the success path is unchanged.
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.

1 participant