From 10c0b35977f958f802b79475763c62d4f197f8a7 Mon Sep 17 00:00:00 2001 From: Julien Cristau Date: Thu, 8 Oct 2026 12:00:04 +0000 Subject: [PATCH] fix(fetch-content): check the compressed stream's integrity on Windows When extracting with tarfile, reading stops at the end-of-archive marker, which can leave the end of the compressed stream unread. For gzip, that means its CRC never gets checked, so a corrupted archive whose deflate data still decodes would extract without error. Read the decompressed stream to the end after extracting, like the tar pipe already does. This made test_stream_extract_broken_archive_not_retried[gz] fail intermittently on Windows. --- src/taskgraph/run-task/fetch-content | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/taskgraph/run-task/fetch-content b/src/taskgraph/run-task/fetch-content index 6c8390f8c..6adb2efbf 100755 --- a/src/taskgraph/run-task/fetch-content +++ b/src/taskgraph/run-task/fetch-content @@ -642,6 +642,10 @@ def extract_stream(reader, dest_dir): # See extract_archive. reader.forget() TarFile.open(fileobj=ifh, mode="r|").extractall(str(dest_dir)) + # tarfile stops at the end-of-archive marker, which can leave the + # end of the compressed stream, and its checksum, unread. + while ifh.read(CHUNK_SIZE): + pass elif magic == ZSTD_MAGIC and shutil.which("zstd"): # Not tar --use-compress-program: when reading from stdin, tar relays # it to the decompressor in small blocks, which is several times