Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tar): untar checksum calculation for the pax format #6199

Merged
merged 4 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
});