Skip to content

Commit

Permalink
fix(tar): untar checksum calculation for the pax format (#6199)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackAsLight authored Nov 25, 2024
1 parent 4989ba7 commit ca14fef
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tar/untar_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
27 changes: 27 additions & 0 deletions tar/untar_stream_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TarStreamInput>([
{ 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();
}
});

0 comments on commit ca14fef

Please sign in to comment.