fix(planstate): leave the plan unchanged when an appended layer fails validation - #937
Open
lenamonj wants to merge 1 commit into
Open
fix(planstate): leave the plan unchanged when an appended layer fails validation#937lenamonj wants to merge 1 commit into
lenamonj wants to merge 1 commit into
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
A
pebble add --innerwhose layer parses but fails plan validation leaves the daemon's live layer list changed.appendLayerinserted withslices.Insert(m.plan.Layers, ...). When the slice has spare capacity,slices.Insertshifts the existing elements in place, so the new layer was spliced intom.plan.LayersbeforeupdatePlanLayersvalidated the result; when validation failed, that mutation stayed.CombineLayeralready copies before mutating.Insert into
slices.Clone(m.plan.Layers)instead. The success path is unchanged: same index, sameOrder, 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,staticcheckpass.