harbor-scanner-clair icon indicating copy to clipboard operation
harbor-scanner-clair copied to clipboard

Panic: runtime error occurred when the number of image layers is 0

Open qinshaoxuan opened this issue 5 years ago • 3 comments

The progress crashed when server receiving a scan request that the number of image layers is 0

Trace

panic: runtime error: index out of range [-1]

goroutine 167 [running]:
github.com/goharbor/harbor-scanner-clair/pkg/scanner.(*adapter).Scan(0xc00026d4a0, 0xc0003a7f50, 0x2f, 0xc000425400, 0x4a2, 0xc00022aa00, 0x12, 0xc0003d02d0, 0x47, 0xc0000eed80, ...)
	/home/travis/gopath/src/github.com/goharbor/harbor-scanner-clair/pkg/scanner/adapter.go:51 +0x782
github.com/goharbor/harbor-scanner-clair/pkg/scanner.(*worker).scan(0xc000562600, 0xc000000005, 0x961a62)
	/home/travis/gopath/src/github.com/goharbor/harbor-scanner-clair/pkg/scanner/worker.go:36 +0xe3
github.com/goharbor/harbor-scanner-clair/pkg/scanner.(*worker).Task(0xc000562600)
	/home/travis/gopath/src/github.com/goharbor/harbor-scanner-clair/pkg/scanner/worker.go:20 +0xd4
github.com/goharbor/harbor-scanner-clair/pkg/work.(*Pool).Start.func1.1(0x9fb980, 0xc000562600)
	/home/travis/gopath/src/github.com/goharbor/harbor-scanner-clair/pkg/work/work.go:34 +0x89
created by github.com/goharbor/harbor-scanner-clair/pkg/work.(*Pool).Start.func1
	/home/travis/gopath/src/github.com/goharbor/harbor-scanner-clair/pkg/work/work.go:32 +0xb1

Cause by https://github.com/goharbor/harbor-scanner-clair/blob/9b8ec347fa7cd8154d90069a56bded96051db084/pkg/scanner/adapter.go#L51

qinshaoxuan avatar Feb 25 '20 13:02 qinshaoxuan

Good catch @qinshaoxuan . Does that mean that you pushed a scratch image to your registry and tried scanning it with Clair scanner? If not would you mind sharing the Dockerfile to reproduce it?

danielpacak avatar Feb 26 '20 09:02 danielpacak

@danielpacak Yes. It's a scratch image with some labels. Dockerfile:

FROM scratch

LABEL ENV=a

qinshaoxuan avatar Feb 26 '20 10:02 qinshaoxuan

@danielpacak @qinshaoxuan Any updates on this? We are facing this issue still with our clair scanners.

We should be failing gracefully here IMO

tariq1890 avatar Oct 06 '21 01:10 tariq1890