Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 1 addition & 56 deletions checks/binary_artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@
package checks

import (
"fmt"
"path/filepath"
"strings"

"github.com/h2non/filetype"
"github.com/h2non/filetype/types"

"github.com/ossf/scorecard/v3/checker"
sce "github.com/ossf/scorecard/v3/errors"
Expand Down Expand Up @@ -52,61 +47,11 @@ func BinaryArtifacts(c *checker.CheckRequest) checker.CheckResult {
func checkBinaryFileContent(path string, content []byte,
dl checker.DetailLogger, data FileCbData) (bool, error) {
pfound := FileGetCbDataAsBoolPointer(data)
binaryFileTypes := map[string]bool{
"crx": true,
"deb": true,
"dex": true,
"dey": true,
"elf": true,
"bin": true,
"o": true,
"so": true,
"iso": true,
"class": true,
"jar": true,
"bundle": true,
"dylib": true,
"lib": true,
"msi": true,
"acm": true,
"ax": true,
"cpl": true,
"dll": true,
"drv": true,
"efi": true,
"exe": true,
"mui": true,
"ocx": true,
"scr": true,
"sys": true,
"tsp": true,
"pyc": true,
"pyo": true,
"par": true,
"rpm": true,
"swf": true,
"torrent": true,
"cab": true,
"whl": true,
}
var t types.Type
var err error
if len(content) == 0 {
return true, nil
}
if t, err = filetype.Get(content); err != nil {
return false, sce.WithMessage(sce.ErrScorecardInternal, fmt.Sprintf("filetype.Get:%v", err))
}

if _, ok := binaryFileTypes[t.Extension]; ok {
dl.Warn3(&checker.LogMessage{
Path: path, Type: checker.FileTypeBinary,
Text: "binary detected",
})
*pfound = true
return true, nil
} else if _, ok := binaryFileTypes[strings.ReplaceAll(filepath.Ext(path), ".", "")]; ok {
// Falling back to file based extension.
if filetype.IsArchive(content) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If the check shouldn't flag pdf files for example I think it would make sense to replace this part with something like

kind, _ := filetype.Archive(content)
if !stopList[kind.Extension] {
...
}

where stopList contains pdf

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

To get this to work more or less reliably I think some kind of h2non/filetype#73 should be implemented first. I guess I'm back where I started :-)

dl.Warn3(&checker.LogMessage{
Path: path, Type: checker.FileTypeBinary,
Text: "binary detected",
Expand Down