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

fix(java): check if a version exists when determining GAV by file name for jar files #5630

Conversation

DmitriyLewen
Copy link
Contributor

@DmitriyLewen DmitriyLewen commented Nov 22, 2023

Description

See #5627

Related issues

Related PRs

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

@DmitriyLewen DmitriyLewen self-assigned this Nov 22, 2023
@DmitriyLewen DmitriyLewen marked this pull request as ready for review November 28, 2023 04:18
@@ -142,37 +142,49 @@ func (d *DB) SearchBySHA1(sha1 string) (jar.Properties, error) {
}, nil
}

func (d *DB) SearchByArtifactID(artifactID string) (string, error) {
func (d *DB) SearchByArtifactID(artifactID, version string) (string, error) {
indexes, err := d.driver.SelectIndexesByArtifactIDAndFileType(artifactID, types.JarType)
Copy link
Collaborator

Choose a reason for hiding this comment

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

What if changing this method to match the version as well as the artifact ID?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean just to move the following logic to trivy-java-db?

trivy/pkg/javadb/client.go

Lines 157 to 188 in 2f10ed1

func foundGroupID(version string, indexes []types.Index) string {
var groupID, maxGroupID string
var count, maxCount int
var versionFound bool
sort.Slice(indexes, func(i, j int) bool {
return indexes[i].GroupID < indexes[j].GroupID
})
for _, index := range indexes {
if index.GroupID != groupID {
// save a new GroupID with the max number of indexes (if this GroupID contains the required version)
if count > maxCount && versionFound {
maxGroupID = groupID
maxCount = count
}
count = 0
versionFound = false
}
// iterate over all indexes of the current GroupID
groupID = index.GroupID
count++
if index.Version == version {
versionFound = true
}
}
// save latest groupID
if count > maxCount && versionFound {
maxGroupID = groupID
}
return maxGroupID
}

Or update our sql query in trivy-java-db?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I meant SQL query. Is it possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I need more knowledge on SQL.
I will try to do this and then write to you.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I created aquasecurity/trivy-java-db#23 and updated this PR.
Take a look, when you have time, please.

@DmitriyLewen
Copy link
Contributor Author

@knqyf263 i updated trivy-java-db version.
Take a look this PR please.

@knqyf263 knqyf263 added this pull request to the merge queue Jan 10, 2024
Merged via the queue into aquasecurity:main with commit 37e7e3e Jan 10, 2024
13 checks passed
@DmitriyLewen DmitriyLewen deleted the fix-jar/check-version-when-search-gav-by-filename branch January 15, 2024 08:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

identify jar files by file names only for GAV from required version
2 participants