Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow failure to unzip invalid zip-files #164

Merged
merged 2 commits into from
Dec 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
21 changes: 12 additions & 9 deletions internal/fingerprint/fingerprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,29 +162,32 @@ func (f *Fingerprinter) FingerprintFiles(rootPath string, exclusions []string) (
}

func computeMD5ForFileAndZip(fileInfo os.FileInfo, path string, exclusions []string) ([]FileFingerprint, error) {
fingerprints := []FileFingerprint{}

if !shouldProcessFile(fileInfo, exclusions, path) {
return fingerprints, nil
return nil, nil
}

// Scan the contents of compressed files
// such as .jar and .nupkg
var fingerprints []FileFingerprint

// If the file should be unzipped, try to unzip and fingerprint it
if shouldUnzip(path) {
fingerprintsZip, err := inMemFingerprintingCompressedContent(path, exclusions)
if err != nil {
return nil, err
if strings.Contains(err.Error(), "not a valid zip file") {
sweoggy marked this conversation as resolved.
Show resolved Hide resolved
fmt.Printf("WARNING: Could not unpack and fingerprint contents of compressed file [%s]. Error: %v\n", path, err)
} else {
return nil, err
}
}
fingerprints = append(fingerprints, fingerprintsZip...)
}

// Compute the MD5 for the file
fingerprint, err := computeMD5ForFile(path)
if err != nil {
return nil, err
}

fingerprints = append(fingerprints, fingerprint)

return fingerprints, nil
return append(fingerprints, fingerprint), nil
}

func isSymlink(filename string) (bool, error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/fingerprint/fingerprint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func TestFingerprintFiles(t *testing.T) {
assert.NoError(t, err)
assert.NotNil(t, fingerprints)
assert.NotEmpty(t, fingerprints)
assert.Equal(t, 1, fingerprints.Len())
assert.Equal(t, 2, fingerprints.Len())
assert.Equal(t, "file=72214db4e1e543018d1bafe86ea3b444,21,testdata/fingerprinter/testfile.py", fingerprints.Entries[0].ToString())

// Test no file
Expand Down
1 change: 1 addition & 0 deletions internal/fingerprint/testdata/fingerprinter/wfailing.jar
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
xxx
Loading