Skip to content

Commit cc8ecc5

Browse files
fmeumcopybara-github
authored andcommitted
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
1 parent 3253d46 commit cc8ecc5

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/main/java/com/google/devtools/build/lib/bazel/repository/downloader/Checksum.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.google.devtools.build.lib.bazel.repository.downloader;
1616

17+
import com.google.common.base.Ascii;
1718
import com.google.common.hash.HashCode;
1819
import com.google.devtools.build.lib.bazel.repository.cache.RepositoryCache.KeyType;
1920
import java.util.Base64;
@@ -44,7 +45,7 @@ public static Checksum fromString(KeyType keyType, String hash) throws InvalidCh
4445
if (!keyType.isValid(hash)) {
4546
throw new InvalidChecksumException(keyType, hash);
4647
}
47-
return new Checksum(keyType, HashCode.fromString(hash));
48+
return new Checksum(keyType, HashCode.fromString(Ascii.toLowerCase(hash)));
4849
}
4950

5051
/** Constructs a new Checksum from a hash in Subresource Integrity format. */

src/test/shell/bazel/external_integration_test.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,22 @@ EOF
221221
assert_contains "test content" "${base_external_path}/test_dir/test_file"
222222
}
223223

224+
function test_http_archive_upper_case_sha() {
225+
cat >> $(create_workspace_with_default_repos WORKSPACE) <<EOF
226+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
227+
http_archive(
228+
name = 'test_zstd_repo',
229+
url = 'file://$(rlocation io_bazel/src/test/shell/bazel/testdata/zstd_test_archive.tar.zst)',
230+
sha256 = '12B0116F2A3C804859438E102A8A1D5F494C108D1B026DA9F6CA55FB5107C7E9',
231+
build_file_content = 'filegroup(name="x", srcs=glob(["*"]))',
232+
)
233+
EOF
234+
bazel build @test_zstd_repo//...
235+
236+
base_external_path=bazel-out/../external/test_zstd_repo
237+
assert_contains "test content" "${base_external_path}/test_dir/test_file"
238+
}
239+
224240
function test_http_archive_no_server() {
225241
cat >> $(create_workspace_with_default_repos WORKSPACE) <<EOF
226242
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

0 commit comments

Comments
 (0)