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

GradleInspector: Ignore artifacts of zero byte size #8305

Merged
merged 2 commits into from
Feb 19, 2024

Conversation

fviernau
Copy link
Member

See individual commits.

This simplifies an upcoming change.

Signed-off-by: Frank Viernau <[email protected]>
@fviernau fviernau requested a review from a team as a code owner February 19, 2024 10:25
@@ -87,6 +87,11 @@ private val GRADLE_USER_HOME = Os.env["GRADLE_USER_HOME"]?.let { File(it) } ?: O
*/
const val OPTION_GRADLE_VERSION = "gradleVersion"

/**
Copy link
Member

@sschuberth sschuberth Feb 19, 2024

Choose a reason for hiding this comment

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

Commit message nits:

  • Should we say "Maven" instead of "Gradle" artifacts?
  • Typo in "rot" -> "root".

/**
* The sha1 sum for a zero by size file.
*/
private const val ZERO_BYTES_FILE_SHA1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
Copy link
Member

Choose a reason for hiding this comment

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

We already have this as EMPTY_PACKAGE_VERIFICATION_CODE. How about refactoring that first to a constant in HashAlgorithm?

Copy link
Member Author

Choose a reason for hiding this comment

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

EMPTY_PACKAGE_VERIFICATION_CODE is in spdx-utils and does not know about the HashAlgorithm class. What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

It's only used in UtilsTest which could add the model as a dependency. I'll propose a follow-up refactoring.

@@ -371,7 +376,11 @@ private fun createRemoteArtifact(
val checksum = okHttpClient.downloadText("$artifactUrl.$algorithm")
.getOrElse { return RemoteArtifact.EMPTY }

return RemoteArtifact(artifactUrl, parseChecksum(checksum, algorithm))
// Ignore file with zero byte size, because it cannot be a valid archive.
val hash = parseChecksum(checksum, algorithm).takeIf { it.value != ZERO_BYTES_FILE_SHA1 }
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Do better document the expected default, consider takeUnless { it == ZERO_BYTES_FILE_SHA1 }.

Maven artifacts are archive files. A file with zero bytes size never
is a valid archive, so fallback to `RemoteArtifact.EMPTY` in that case.

This fixes one possible root cause of #8116.

Signed-off-by: Frank Viernau <[email protected]>
@fviernau fviernau force-pushed the gradle-inspector-ignore-zero-byte-archives branch from 6849f66 to 769f34d Compare February 19, 2024 10:50
@fviernau fviernau requested a review from sschuberth February 19, 2024 10:53
@sschuberth sschuberth merged commit 25c9790 into main Feb 19, 2024
20 of 21 checks passed
@sschuberth sschuberth deleted the gradle-inspector-ignore-zero-byte-archives branch February 19, 2024 11:09
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.

2 participants