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

jar: support unconventional jar names #1467

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RTann
Copy link
Contributor

@RTann RTann commented Jan 14, 2025

Some JAR files just have bad names 🤷. Claircore should still continue to search for inner JARs in case the found JAR embeds valid JARs. Before this, we just stopped looking through any top-level JAR file with an unconventional name.

When testing, I realized we cannot really tell the difference between JARs and "inner" JARs. I'm wondering if I should also update the package name to be the full path instead of just the final portion. That is:

return testdata/inner/inner.jar:BOOT-INF/lib/log4j-api-2.14.jar:META-INF/inner-jar/log4j-2.14.0.jar instead of META-INF/inner-jar/log4j-2.14.0.jar.

Also, I realized the packagescanner does not consider a JAR file a valid JAR unless it has a META-INF directory. According to the JAR spec from the last few LTS releases (11, 17, and 21) as well as the latest non-LTS release (23):

A JAR file is essentially a zip file that contains an optional META-INF directory.

So, the META-INF directory is not required, so we may want to consider dropping that constraint. Thoughts?

@RTann RTann force-pushed the jar-unidentified branch 5 times, most recently from 2245436 to f0d251e Compare January 16, 2025 00:01
@RTann RTann marked this pull request as ready for review January 16, 2025 00:11
@RTann RTann requested a review from a team as a code owner January 16, 2025 00:11
@RTann RTann requested review from crozzy and hdonnay and removed request for a team January 16, 2025 00:11
@RTann RTann force-pushed the jar-unidentified branch 2 times, most recently from 552f32f to 177a66d Compare February 12, 2025 16:48
@RTann RTann force-pushed the jar-unidentified branch 2 times, most recently from f8e7fb8 to 7ff485d Compare February 25, 2025 00:24
@RTann RTann force-pushed the jar-unidentified branch from 7ff485d to 35127cd Compare March 10, 2025 16:41
Copy link
Contributor

@daynewlee daynewlee left a comment

Choose a reason for hiding this comment

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

The changes look ok to me. Maybe get @crozzy to have another look.

Copy link
Contributor

@crozzy crozzy left a comment

Choose a reason for hiding this comment

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

The logic essentially looks good to me, just a few comments on the tests

},
}

if !cmp.Equal(got, want) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if !cmp.Equal(got, want) {
if !cmp.Equal(got, want, cmpopts.IgnoreFields(Info{}, "SHA")) {

Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't seem to render correctly as markdown.

@@ -185,7 +185,7 @@ func (s *Scanner) Scan(ctx context.Context, layer *claircore.Layer) ([]*claircor
infos, err := jar.Parse(ctx, n, z)
switch {
case err == nil:
case errors.Is(err, jar.ErrUnidentified) || errors.Is(err, jar.ErrNotAJar):
case errors.Is(err, jar.ErrNotAJar):
// If there's an error that's one of the "known" reasons (e.g. not a
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: This comment could probably be updated to be more specific to ErrNotAJar now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants