From ca14fefd93ee5614de89add35b9df628e7ce290d Mon Sep 17 00:00:00 2001 From: Doctor <44320105+BlackAsLight@users.noreply.github.com> Date: Mon, 25 Nov 2024 13:26:55 +1100 Subject: [PATCH] fix(tar): untar checksum calculation for the pax format (#6199) --- tar/untar_stream.ts | 2 +- tar/untar_stream_test.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/tar/untar_stream.ts b/tar/untar_stream.ts index 308776b572b8..37bdf5613bfd 100644 --- a/tar/untar_stream.ts +++ b/tar/untar_stream.ts @@ -233,7 +233,7 @@ export class UntarStream // Validate Checksum const checksum = parseInt( - decoder.decode(value.subarray(148, 156 - 2)), + decoder.decode(value.subarray(148, 156)), 8, ); value.fill(32, 148, 156); diff --git a/tar/untar_stream_test.ts b/tar/untar_stream_test.ts index 7c6c39d054fc..b124484baaf8 100644 --- a/tar/untar_stream_test.ts +++ b/tar/untar_stream_test.ts @@ -241,3 +241,30 @@ Deno.test("UntarStream() with extra bytes", async () => { entry.readable?.cancel(); } }); + +Deno.test("UntarStream() with extra checksum digits", async () => { + const bytes = await toBytes( + ReadableStream.from([ + { type: "directory", path: "a" }, + ]).pipeThrough(new TarStream()), + ); + + for await ( + const entry of ReadableStream + .from([bytes.slice()]) + .pipeThrough(new UntarStream()) + ) { + assertEquals(entry.path, "a"); + entry.readable?.cancel(); + } + + bytes.set(bytes.subarray(148, 156 - 2), 148 + 1); // Copy 6 octal digits of checksum and make it seven sigits. Assuming first digit is zero + for await ( + const entry of ReadableStream + .from([bytes.slice()]) + .pipeThrough(new UntarStream()) + ) { + assertEquals(entry.path, "a"); + entry.readable?.cancel(); + } +});