Skip to content

fix(provenance): check error return in Digest and encodeRelease#32136

Open
SebTardif wants to merge 1 commit into
helm:mainfrom
SebTardif:fix-digest-error-swallow
Open

fix(provenance): check error return in Digest and encodeRelease#32136
SebTardif wants to merge 1 commit into
helm:mainfrom
SebTardif:fix-digest-error-swallow

Conversation

@SebTardif
Copy link
Copy Markdown
Contributor

What this PR does

Fixes two swallowed errors in the provenance and storage layers:

  1. pkg/provenance/sign.goDigest(): return "", nil instead of return "", err on io.Copy failure. This returns an empty string as a valid SHA-256 digest, which can cause chart provenance verification to silently produce wrong results.

  2. pkg/storage/driver/util.goencodeRelease(): gzip.Writer.Close() error discarded. Close flushes remaining data and writes the gzip footer; if it fails, the buffer contains a truncated stream that will be base64-encoded and stored in a Secret/ConfigMap. Also added close on the Write error path where the writer was leaked.

AI Disclosure

Developed with AI assistance (Grok by xAI) in a human-in-the-loop workflow. All code reviewed and verified by the human author.

Signed-off-by: Sebastien Tardif sebtardif@ncf.ca
Assisted-by: Grok/xAI

Return the actual error from io.Copy in Digest() instead of nil.
The previous code swallowed the error and returned an empty string
as a valid SHA-256 digest, which could silently break chart
provenance verification.

Also fix encodeRelease() in pkg/storage/driver/util.go:
- Close the gzip writer on the w.Write() error path to avoid
  leaking resources.
- Check the error return from gzip.Writer.Close(), which flushes
  remaining compressed data and can fail.

Assisted-by: Grok/xAI
Signed-off-by: Sebastien Tardif <sebtardif@ncf.ca>
Copilot AI review requested due to automatic review settings May 21, 2026 14:43
@pull-request-size pull-request-size Bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label May 21, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Improves error handling in storage encoding and provenance digesting to ensure failures are surfaced correctly and writers are properly closed.

Changes:

  • Properly handle Write/Close errors in release encoding, ensuring the writer is closed and close failures are returned.
  • Fix Digest to return the actual copy error instead of nil.

Reviewed changes

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

File Description
pkg/storage/driver/util.go Ensures writer close is handled correctly and close errors are propagated.
pkg/provenance/sign.go Fixes incorrect error return when hashing input fails.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants