Skip to content

fix(scanner): handle digest-only MainAssetName without panic - #42

Closed
henrikfrech wants to merge 3 commits into
sysdiglabs:masterfrom
henrikfrech:fix/digest-only-mainassetname-panic
Closed

fix(scanner): handle digest-only MainAssetName without panic#42
henrikfrech wants to merge 3 commits into
sysdiglabs:masterfrom
henrikfrech:fix/digest-only-mainassetname-panic

Conversation

@henrikfrech

Copy link
Copy Markdown

What

Fix panic in scanner report conversion when Sysdig returns digest-only references in mainAssetName (e.g. repo@sha256:...).

Why

ToHarborVulnerabilityReport assumed repo:tag@digest and sliced with lastColon=-1 for tagless images, causing:
panic: runtime error: slice bounds out of range [:-1].

Changes

  • Added robust parseMainAssetName helper in pkg/scanner/base_adapter.go
  • Supports:
    • tagged: repo:tag@sha256:...
    • digest-only: repo@sha256:...
    • registry-prefixed variants
  • On malformed values, logs warning and continues instead of panicking
  • Added parser-focused tests in pkg/scanner/base_adapter_test.go
  • Updated scanner test fixture expectation in pkg/scanner/backend_adapter_test.go

Validation

  • go test -count=1 ./pkg/scanner
  • go test ./pkg/scanner/...

Impact

  • Unblocks Harbor report generation for digest-only image references
  • Preserves existing tagged-image behavior

Copilot AI review requested due to automatic review settings July 10, 2026 09:38

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes a panic in BaseAdapter.ToHarborVulnerabilityReport when Sysdig returns digest-only (tagless) mainAssetName values by introducing a safer parser and using it during report conversion.

Changes:

  • Replaced brittle string slicing with a new parseMainAssetName helper to support both repo:tag@digest and repo@digest formats.
  • Added Ginkgo tests covering common mainAssetName variants (with/without tags, with/without registry prefixes).
  • Updated scanner test fixture expectations to include populated Artifact data.

Reviewed changes

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

File Description
pkg/scanner/base_adapter.go Uses parseMainAssetName to avoid panics and correctly populate Harbor artifact fields.
pkg/scanner/base_adapter_test.go Adds unit tests for parseMainAssetName across tagged/digest-only/registry cases.
pkg/scanner/backend_adapter_test.go Updates expected vulnerability report to include Artifact details.

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

Comment thread pkg/scanner/base_adapter.go
Comment thread pkg/scanner/base_adapter_test.go
Treat a tag separator with an empty tag (e.g. "repo:@sha256:...") as a
malformed reference so the caller logs and skips instead of returning an
empty tag. Add tests for registry-host-with-port, single-name official
images, and the empty-tag malformed case.

Addresses Copilot review comments on PR sysdiglabs#42.
@henrikfrech

henrikfrech commented Jul 10, 2026

Copy link
Copy Markdown
Author

Hello @airadier,
as this is my first MR ever I am looking forward to your feedback whether this PR was addressed the right way. Should you need further adjustment just let me know.
BR, Henrik

Add a doc comment describing the accepted MainAssetName reference forms and
the registry-host stripping rule, and rename the hash return value/local to
digest to match its value (algo:hex) and the harbor.Artifact.Digest field.

Addresses code-review nits from PR sysdiglabs#42 round 2.

@airadier airadier left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approving.

This fixes a real, reproducible panic (slice bounds out of range [:-1]) in ToHarborVulnerabilityReport when Sysdig returns a digest-only MainAssetName, which is hit on the active InlineAdapter path (inline_adapter.go:248). As a bonus it also fixes a latent bug where un-prefixed repo names (e.g. sysdig/agent) had their first segment stripped as if it were a registry, so Artifact was silently never populated — hence the corrected fixture in backend_adapter_test.go.

Reviewed via 3 independent review passes (Go idioms, general quality, adversarial edge cases): unanimous, 0 critical/high. The parser was exercised against 30+ reference forms with no panics, and the added tests lock in the tricky cases (digest-only, registry+port disambiguation, empty tag).

The two Copilot comments (empty-tag rejection + its test) are addressed, and I pushed two small maintainability commits (doc comment on parseMainAssetName, hashdigest rename). Remaining low-severity items are pre-existing and out of scope — tracked as a follow-up issue.

LGTM. Thanks @henrikfrech for the fix.

@airadier

Copy link
Copy Markdown
Collaborator

Follow-up items (all pre-existing, out of scope for this PR) tracked in #43.

@airadier

Copy link
Copy Markdown
Collaborator

Thanks so much for this contribution, @henrikfrech! 🙌

This is a genuinely valuable fix — you caught a real panic on the active scanning path, diagnosed the root cause precisely (the [:-1] slice on digest-only references), and even uncovered a latent bug where un-prefixed repository names weren't populating the Artifact metadata. The parser is clean, the PR description was clear and easy to follow, and the tests you included made reviewing this a pleasure.

We ran it through a thorough review and it came out great. I've pushed a couple of tiny maintainability touch-ups (a doc comment and a hashdigest rename) and filed #43 for some pre-existing items that were out of scope here — nothing on your end.

Really appreciate you taking the time to not just report the issue but send a well-tested fix. Contributions like this are exactly what makes the project better. Thank you! 🎉

@airadier

Copy link
Copy Markdown
Collaborator

Hi @henrikfrech — quick heads-up on how we're landing this. 🙏

Your fix is spot on, but we hit a purely mechanical hurdle: this PR comes from a fork, and for security GitHub doesn't share our repository secrets with workflows triggered by fork PRs. Our pkg/secure test suite talks to the live Sysdig API using SECURE_API_TOKEN, so that check can never turn green from a fork — through no fault of your code. On top of that, our org's branch-protection rules require a passing review + all checks, with no admin-bypass path.

So to get everything green and merge cleanly, we've re-applied your exact commits (with your authorship preserved) onto an internal branch and opened #44, where the pipeline has access to the secrets and runs the full suite. We also folded in a golang.org/x/net bump there to clear an unrelated CVE that the security scan started flagging.

Nothing needed from you — we'll merge via #44 and this PR will be closed as part of that. Huge thanks again for the well-tested contribution; it's shipping exactly as you wrote it. 🎉

@airadier airadier closed this Jul 10, 2026
airadier added a commit that referenced this pull request Jul 10, 2026
…des #42) (#44)

* fix: handle digest-only image references in report parsing

* fix(scanner): reject empty tag in parseMainAssetName

Treat a tag separator with an empty tag (e.g. "repo:@sha256:...") as a
malformed reference so the caller logs and skips instead of returning an
empty tag. Add tests for registry-host-with-port, single-name official
images, and the empty-tag malformed case.

Addresses Copilot review comments on PR #42.

* docs(scanner): document parseMainAssetName and rename hash to digest

Add a doc comment describing the accepted MainAssetName reference forms and
the registry-host stripping rule, and rename the hash return value/local to
digest to match its value (algo:hex) and the harbor.Artifact.Digest field.

Addresses code-review nits from PR #42 round 2.

* chore(deps): bump golang.org/x/net to v0.57.0 to fix CVEs

Trivy flagged 8 vulnerabilities (4 HIGH) in golang.org/x/net v0.51.0
(CVE-2026-25681, CVE-2026-33814, CVE-2026-39821, and others). Bump the
golang.org/x/* modules and refresh the nix vendorHash accordingly.

---------

Co-authored-by: Henrik Frech <henrik.frech@sva.de>
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.

3 participants