Skip to content

Commit 93fbfd5

Browse files
Checkmarx Automationcx-anurag-dalke
authored andcommitted
Fix magic number linting error and correct tar file validation logic
- Replace magic number 2 with named constant minPartsForTaggedImage - Fix tar file detection to reject invalid formats (e.g., file.tar:tag) - Update test cases to reflect correct behavior (tar files cannot have tags) - Add comprehensive test coverage for tar file detection and local resolution enforcement
1 parent 94a3ed3 commit 93fbfd5

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

internal/commands/scan.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2345,7 +2345,8 @@ func isTarFileReference(imageRef string) bool {
23452345
// A tar file cannot have a tag suffix like file.tar:tag
23462346
if strings.Contains(actualRef, ":") {
23472347
parts := strings.Split(actualRef, ":")
2348-
if len(parts) >= 2 {
2348+
const minPartsForTaggedImage = 2
2349+
if len(parts) >= minPartsForTaggedImage {
23492350
firstPart := strings.ToLower(parts[0])
23502351
// If the part before the colon is a tar file, this is invalid (tar files don't have tags)
23512352
if strings.HasSuffix(firstPart, ".tar") {

0 commit comments

Comments
 (0)