Skip to content

core/runtime/v2: Preserve protobuf shim response bytes - #13801

Merged
fuweid merged 1 commit into
containerd:mainfrom
vvoland:work-shim2
Jul 16, 2026
Merged

fuweid merged 1 commit into
containerd:mainfrom
vvoland:work-shim2

Conversation

@vvoland

@vvoland vvoland commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Shim start output was trimmed before protobuf decoding. Because arbitrary protobuf fields may legitimately end with whitespace bytes, including \n, trimming could corrupt metadata or capabilities and cause decoding to fail.

Pass the raw command output to parseStartResponse and attempt protobuf decoding before modifying the response.
Whitespace trimming now applies only to legacy JSON and plain-address responses.

Shim start output was trimmed before protobuf decoding.
Because arbitrary protobuf fields may legitimately end with whitespace
bytes, including `\n`, trimming could corrupt metadata or capabilities
and cause decoding to fail.

Pass the raw command output to `parseStartResponse` and attempt protobuf
decoding before modifying the response.
Whitespace trimming now applies only to legacy JSON and plain-address
responses.

Signed-off-by: Paweł Gronowski <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes shim start response parsing in core/runtime/v2 to avoid corrupting protobuf-encoded BootstrapResult data by trimming whitespace before protobuf decoding. It ensures protobuf decoding is attempted on the raw shim stdout output, while whitespace trimming is retained only for legacy (plain-string / JSON) responses.

Changes:

  • Pass raw shim start stdout bytes into parseStartResponse (stop trimming at the call site).
  • Apply bytes.TrimSpace only in the legacy fallback path after protobuf unmarshal fails.
  • Extend tests to cover protobuf responses whose serialized bytes legitimately end with whitespace (e.g., \n).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
core/runtime/v2/shim.go Moves whitespace trimming to the legacy fallback path so protobuf unmarshalling sees unmodified bytes.
core/runtime/v2/binary.go Stops trimming shim stdout before parsing, preserving raw response bytes for protobuf decoding.
core/runtime/v2/shim_test.go Adds coverage for protobuf responses ending with whitespace and adapts test inputs to raw []byte responses.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@vvoland
vvoland marked this pull request as ready for review July 16, 2026 19:04
@mxpv mxpv added the cherry-pick/2.3.x Change to be cherry picked to release/2.3 label Jul 16, 2026
@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Jul 16, 2026
@fuweid
fuweid added this pull request to the merge queue Jul 16, 2026
Comment thread core/runtime/v2/binary.go
if err != nil {
return nil, fmt.Errorf("%s: %w", out, err)
}
response := bytes.TrimSpace(out)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks indeed that this was added when it was just plain text output, and kept in dba6f9d

Comment thread core/runtime/v2/binary.go
log.G(ctx).WithError(err).Error("copy shim log")
}
}()
out, err := cmd.CombinedOutput()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should also look at this; now that the output is more strict (less forgiving than plain text), we should consider only parsing StdOut, and capture StdErr separately for the error case (probably)

Merged via the queue into containerd:main with commit 94aa7cd Jul 16, 2026
51 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Jul 16, 2026
@mxpv

mxpv commented Jul 17, 2026

Copy link
Copy Markdown
Member

/cherry-pick release/2.3

@k8s-infra-cherrypick-robot

Copy link
Copy Markdown

@mxpv: new pull request created: #13803

Details

In response to this:

/cherry-pick release/2.3

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@fuweid fuweid added cherry-picked/2.3.x PR commits are cherry picked into release/2.3 branch and removed cherry-pick/2.3.x Change to be cherry picked to release/2.3 labels Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-picked/2.3.x PR commits are cherry picked into release/2.3 branch size/M

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

6 participants