Skip to content

Commit 3fa3fdf

Browse files
committed
build: verify the zlib tarball before it lands, and mirror the fetch
Two release jobs failed on a checksum mismatch and passed on a re-run. The release matrix fans out twenty-two jobs that each fetch the same tarball at the same moment, and zlib.net is one host serving them; curl's --retry covers a transport error, not a request that completes carrying the wrong body. That was the trigger, not the defect. curl wrote straight to the cached path, so a bad body stayed there and the next run's existence test skipped the download and failed identically — recoverable only by deleting the file by hand. CI recovered because that job's cache was never saved; had it been, every later run restoring it would have failed the same way, re-runs included. Fetch to a temporary name, verify, and move into place only on a match, so a bad body never reaches the cached path. An existing tarball is verified before use and re-fetched when it does not match, which repairs a workspace or cache entry already holding one. Both checksums are printed on a mismatch, since the failure this replaces named neither. The GitHub release becomes the first source, byte-identical to zlib.net and served by a CDN that twenty-two concurrent fetches do not trouble; zlib.net stays as the fallback and each source is tried in turn. KASLD_ZLIB_TARBALL keeps failing rather than re-fetching: naming a file and silently getting a different one is not what it asks for.
1 parent 3c2fbdb commit 3fa3fdf

1 file changed

Lines changed: 27 additions & 6 deletions

File tree

Makefile

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,11 @@ cross-extra-flags :
10921092
# list, so it names its triple rather than relying on that list.
10931093
ZLIB_VERSION := 1.3.1
10941094
ZLIB_SHA256 := 9a93b2b7dfdac77ceba5a558a580e74667dd6fede4585b91eefb60f03b72df23
1095-
ZLIB_URL := https://zlib.net/fossils/zlib-$(ZLIB_VERSION).tar.gz
1095+
# Two sources, same bytes. The GitHub release is first because the release
1096+
# matrix fans out twenty-two jobs that all fetch this at once, which zlib.net
1097+
# is a single host serving; it stays as the fallback.
1098+
ZLIB_URLS := https://github.com/madler/zlib/releases/download/v$(ZLIB_VERSION)/zlib-$(ZLIB_VERSION).tar.gz \
1099+
https://zlib.net/fossils/zlib-$(ZLIB_VERSION).tar.gz
10961100

10971101
.PHONY: cross-deps
10981102
cross-deps :
@@ -1101,14 +1105,31 @@ cross-deps :
11011105
{ echo "cross-deps: sha256sum not found" >&2; exit 1; }; \
11021106
src='$(DEPS_DIR)/src'; mkdir -p "$$src"; \
11031107
tb="$${KASLD_ZLIB_TARBALL:-$$src/zlib-$(ZLIB_VERSION).tar.gz}"; \
1104-
if [ ! -f "$$tb" ]; then \
1108+
ok() { [ -f "$$1" ] && \
1109+
[ "$$(sha256sum <"$$1" | cut -d' ' -f1)" = '$(ZLIB_SHA256)' ]; }; \
1110+
if ! ok "$$tb"; then \
1111+
if [ -n "$${KASLD_ZLIB_TARBALL:-}" ]; then \
1112+
echo "cross-deps: KASLD_ZLIB_TARBALL=$$tb is not zlib-$(ZLIB_VERSION)" >&2; \
1113+
echo " expected $(ZLIB_SHA256)" >&2; \
1114+
echo " got $$(sha256sum <"$$tb" 2>/dev/null | cut -d' ' -f1)" >&2; \
1115+
exit 1; \
1116+
fi; \
11051117
command -v curl >/dev/null 2>&1 || \
11061118
{ echo "cross-deps: curl not found; set KASLD_ZLIB_TARBALL" >&2; exit 1; }; \
1107-
echo " FETCH zlib-$(ZLIB_VERSION)"; \
1108-
curl -fsSL --retry 3 --retry-delay 2 -o "$$tb" '$(ZLIB_URL)'; \
1119+
rm -f "$$tb"; \
1120+
for url in $(ZLIB_URLS); do \
1121+
echo " FETCH zlib-$(ZLIB_VERSION) ($$url)"; \
1122+
curl -fsSL --retry 3 --retry-delay 2 -o "$$tb.part" "$$url" || continue; \
1123+
if ok "$$tb.part"; then mv -f "$$tb.part" "$$tb"; break; fi; \
1124+
echo " checksum mismatch from $$url" >&2; \
1125+
echo " expected $(ZLIB_SHA256)" >&2; \
1126+
echo " got $$(sha256sum <"$$tb.part" | cut -d' ' -f1)" >&2; \
1127+
rm -f "$$tb.part"; \
1128+
done; \
1129+
rm -f "$$tb.part"; \
11091130
fi; \
1110-
echo "$(ZLIB_SHA256) $$tb" | sha256sum -c - >/dev/null || \
1111-
{ echo "cross-deps: checksum mismatch for $$tb" >&2; exit 1; }; \
1131+
ok "$$tb" || \
1132+
{ echo "cross-deps: no source matching $(ZLIB_SHA256)" >&2; exit 1; }; \
11121133
built=0; have=0; absent=0; \
11131134
for triple in $${TRIPLE:-$(CROSS_TARGETS)}; do \
11141135
command -v $${triple}-gcc >/dev/null 2>&1 || { absent=$$((absent+1)); continue; }; \

0 commit comments

Comments
 (0)