From ee84ab38b383b6a31a10d10faedf84bc9c10e25b Mon Sep 17 00:00:00 2001 From: BlackAsLight <44320105+BlackAsLight@users.noreply.github.com> Date: Thu, 21 Nov 2024 18:53:18 +1100 Subject: [PATCH 1/2] fix: untar checksum calculation for the pax format --- tar/untar_stream.ts | 2 +- 1 file changed, 1 insertion(+), 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); From 9864d4f6ef63d3ccbb7cef3bb7d842883f393fec Mon Sep 17 00:00:00 2001 From: BlackAsLight <44320105+BlackAsLight@users.noreply.github.com> Date: Mon, 25 Nov 2024 12:42:24 +1100 Subject: [PATCH 2/2] add(tar): test to validate checksum behaviour --- tar/untar_stream_test.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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(); + } +});