goharbor / harbor-scanner-clair

Use Clair as a plug-in vulnerability scanner in the Harbor registry
https://goharbor.io/
Apache License 2.0
35 stars 26 forks source link

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

Open qinshaoxuan opened 4 years ago

qinshaoxuan commented 4 years ago

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

danielpacak commented 4 years ago

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?

qinshaoxuan commented 4 years ago

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

FROM scratch

LABEL ENV=a
tariq1890 commented 3 years ago

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

We should be failing gracefully here IMO