Changing a lockfile `url` but not its `sha256` silently serves the old binary from the repository cache
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 66/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Domain
- build-system
Research direction
Start with the three download calls in multitool/private/multitool.bzl (the issue links to lines 83, 98, and 132), then compare their cache handling with http_archive or http_file and @bazel_tools//tools/build_defs/repo:cache.bzl. The issue also calls for an environ addition to tool_repo; reproduce using the lockfile URL/SHA mismatch. Done when a cached run fails with the checksum error, as an uncached run does.
Written by the indexing model from the issue text.
Description
tool_repo passes sha256 to rctx.download / rctx.download_and_extract but no canonical_id (multitool.bzl L83, L98, L132). Bazel's repository cache is keyed by sha256. So if a lockfile entry's url is bumped and its sha256 is left at the old value, any machine that already has the old file cached gets the old binary, with no error. A machine without it fails with a checksum mismatch. The same commit builds differently depending on the cache.
Repro
rules_multitool 1.11.1, Bazel 9.2.0, macOS arm64. main (5ef5b45) behaves the same.
.bazelversion
9.2.0
MODULE.bazel
module(name = "multitool_repro")
bazel_dep(name = "rules_multitool", version = "1.11.1")
multitool = use_extension("@rules_multitool//multitool:extension.bzl", "multitool")
multitool.hub(lockfile = "//:multitool.lock.json")
use_repo(multitool, "multitool")
BUILD.bazel: empty
multitool.lock.json
{
"$schema": "https://raw.githubusercontent.com/bazel-contrib/rules_multitool/main/lockfile.schema.json",
"jq": {
"binaries": [
{
"kind": "file",
"url": "https://github.com/jqlang/jq/releases/download/jq-1.8.0/jq-macos-arm64",
"sha256": "aaf1efbb376d6e3eaf61f63807c32c1df519f5857dfc4f581826fa2df4b715ae",
"os": "macos",
"cpu": "arm64"
},
{
"kind": "file",
"url": "https://github.com/jqlang/jq/releases/download/jq-1.8.0/jq-linux-amd64",
"sha256": "8926c33326111bcd67a47a970b5a5db933ef9194ad925994934c639c76a0605c",
"os": "linux",
"cpu": "x86_64"
}
]
}
}
$ bazel run @multitool//tools/jq -- --version
jq-1.8.0
# bump the URLs to 1.8.1, keep the 1.8.0 sha256
$ sed -i.bak 's/jq-1\.8\.0/jq-1.8.1/g' multitool.lock.json
$ bazel run @multitool//tools/jq -- --version
jq-1.8.0
# same lockfile, nothing cached
$ bazel clean --expunge && bazel run --repository_cache= @multitool//tools/jq -- --version
ERROR: .../multitool/private/multitool.bzl:83:22: An error occurred during the fetch of repository 'rules_multitool++multitool+multitool.jq.macos_arm64':
Error in download: java.io.IOException: Error downloading [https://github.com/jqlang/jq/releases/download/jq-1.8.1/jq-macos-arm64] to .../macos_arm64_executable: Checksum was a9fe3ea2f86dfc72f6728417521ec9067b343277152b114f4e98d8cb0e263603 but wanted aaf1efbb376d6e3eaf61f63807c32c1df519f5857dfc4f581826fa2df4b715ae
When both url and sha256 are updated, both runs print jq-1.8.1.
Actual: the second run prints jq-1.8.0 and succeeds.
Expected: the second run fails with the same checksum error as the uncached run. http_file does this for the same edit.
Fix
Do what http_archive / http_file do: pass canonical_id = get_default_canonical_id(rctx, [binary["url"]]) (from @bazel_tools//tools/build_defs/repo:cache.bzl) to the three download calls, and add environ = [DEFAULT_CANONICAL_ID_ENV] to tool_repo. With that change applied to 1.11.1, the second run fails with the checksum error.
- Dominant language
- Starlark
- Stars
- 26
- Forks
- 11
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bazel-contrib/rules_multitool
-
make a new releaseOpen
Difficulty 4/5 3-5 days Newbie friendliness 35/100
bazel-contrib/rules_multitool#130 · 2 comments · 3 reactions ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
bazel-contrib/rules_multitool#127 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
bazel-contrib/rules_multitool#113 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
bazel-contrib/rules_multitool#107 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
bazel-contrib/rules_multitool#105 ·
All issues in bazel-contrib/rules_multitool
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
apache/rocketmq-dashboard#7243 ·
Maintainers usually reply within 3 days
-
[Other] error detected in the compilation of Strata/src/qwen35/q36_engine.cuPossibly taken A pull request linked to this issue is open or already merged. Openneeds-format
Difficulty 2/5 1-3 hours Newbie friendliness 69/100
Niko1221/Strata#3368 · 1 comment ·
Maintainers usually reply within 3 days
-
Bug React-Native Waiting for: Product Owner
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
getsentry/sentry-react-native#6913 · 1 comment ·
Maintainers usually reply within 1 day
-
out-of-date
Difficulty 1/5 Under an hour Newbie friendliness 72/100
CachyOS/CachyOS-PKGBUILDS#2022 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 78/100
krizaka/krizaka-notifications#22 ·
Maintainers usually reply within 1 day