From cc8ecc5ad847969cc7e4b23c3a4facc8bd56ee36 Mon Sep 17 00:00:00 2001 From: Fabian Meumertzheim Date: Thu, 4 May 2023 21:24:55 -0700 Subject: [PATCH] Ignore hash string casing Fixes this crash when e.g. the `sha256` attribute is passed an upper case string: ``` Caused by: java.lang.IllegalArgumentException: Illegal hexadecimal character: D at com.google.common.hash.HashCode.decode(HashCode.java:360) at com.google.common.hash.HashCode.fromString(HashCode.java:346) at com.google.devtools.build.lib.bazel.repository.downloader.Checksum.fromString(Checksum.java:47) at com.google.devtools.build.lib.bazel.repository.starlark.StarlarkBaseExternalContext.validateChecksum(StarlarkBaseExternalContext.java:302) at com.google.devtools.build.lib.bazel.repository.starlark.StarlarkBaseExternalContext.downloadAndExtract(StarlarkBaseExternalContext.java:650) ... ``` Fixes #18291 Closes #18305. PiperOrigin-RevId: 529601921 Change-Id: I75deee47bcac80ee81603591c22f43d013ba0c29 --- .../bazel/repository/downloader/Checksum.java | 3 ++- .../shell/bazel/external_integration_test.sh | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/Checksum.java b/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/Checksum.java index a63e1b4f4a5bf9..09b3aeea884ac0 100644 --- a/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/Checksum.java +++ b/src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/Checksum.java @@ -14,6 +14,7 @@ package com.google.devtools.build.lib.bazel.repository.downloader; +import com.google.common.base.Ascii; import com.google.common.hash.HashCode; import com.google.devtools.build.lib.bazel.repository.cache.RepositoryCache.KeyType; import java.util.Base64; @@ -44,7 +45,7 @@ public static Checksum fromString(KeyType keyType, String hash) throws InvalidCh if (!keyType.isValid(hash)) { throw new InvalidChecksumException(keyType, hash); } - return new Checksum(keyType, HashCode.fromString(hash)); + return new Checksum(keyType, HashCode.fromString(Ascii.toLowerCase(hash))); } /** Constructs a new Checksum from a hash in Subresource Integrity format. */ diff --git a/src/test/shell/bazel/external_integration_test.sh b/src/test/shell/bazel/external_integration_test.sh index bc2847adee857b..9b2bcf8cca594b 100755 --- a/src/test/shell/bazel/external_integration_test.sh +++ b/src/test/shell/bazel/external_integration_test.sh @@ -221,6 +221,22 @@ EOF assert_contains "test content" "${base_external_path}/test_dir/test_file" } +function test_http_archive_upper_case_sha() { + cat >> $(create_workspace_with_default_repos WORKSPACE) <> $(create_workspace_with_default_repos WORKSPACE) <