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

Error: Invalid tar header. Maybe the tar is corrupted or it needs to be gunzipped? #158

Open
catdevnull opened this issue Jun 23, 2023 · 4 comments

Comments

@catdevnull
Copy link

    at Object.decode (/home/diablo/proy/fireactions/js/node_modules/.pnpm/tar-stream@3.1.4/node_modules/tar-stream/headers.js:116:43)
    at Extract._consumeHeader (/home/diablo/proy/fireactions/js/node_modules/.pnpm/tar-stream@3.1.4/node_modules/tar-stream/extract.js:144:30)
    at Extract._update (/home/diablo/proy/fireactions/js/node_modules/.pnpm/tar-stream@3.1.4/node_modules/tar-stream/extract.js:272:41)
    at Extract._write (/home/diablo/proy/fireactions/js/node_modules/.pnpm/tar-stream@3.1.4/node_modules/tar-stream/extract.js:287:10)
    at WritableState.update (/home/diablo/proy/fireactions/js/node_modules/.pnpm/streamx@2.15.0/node_modules/streamx/index.js:180:16)
    at WritableState.updateWriteNT (/home/diablo/proy/fireactions/js/node_modules/.pnpm/streamx@2.15.0/node_modules/streamx/index.js:532:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:77:11)

repro:

import gunzip from "gunzip-maybe";
import { Duplex, Writable } from "node:stream";
import { extract } from "tar-stream";

const ex = extract();

ex.on("entry", (header, stream, next) => {
  console.debug(header.name);
  stream.on("end", function () {
    next(); // ready for next entry
  });

  stream.resume();
});
const res = await fetch("https://0x0.st/HQqY.bin");
const stream = res.body;
await stream.pipeThrough(Duplex.toWeb(gunzip())).pipeTo(Writable.toWeb(ex));
@mafintosh
Copy link
Owner

Can you add a proper test with the tar that fails as a fixture, without the fetch and stream wrappers

@catdevnull
Copy link
Author

I don't really know what's the issue so I can't develop a proper fixture for it, but here you go: https://gitea.nulo.in/Nulo/tar-stream (uploaded to a self-hosted repo because GitHub doesn't allow LFS in forks...)

@personalizedrefrigerator
Copy link

personalizedrefrigerator commented Dec 23, 2023

I'm encountering a similar (but maybe completely different?) issue.

I'm using tar-stream with feross/buffer in React Native (and a tar file generated with tar-stream).

For me, val.subarray(offset, end).toString() in decodeOct is evaluating to a list of numbers instead of as ASCII (e.g. 48,48,48,54,52,52 instead of 000644).

return parseInt(val.subarray(offset, end).toString(), 8)

Replacing that line with

return parseInt(Buffer.from(val).toString('utf-8', offset, end), 8)

and adding

const {Buffer} = require('buffer');

to the top of the file seems to fix the issue.

Edit: Upstream issue: feross/buffer#329

@FrederikBolding
Copy link
Contributor

I ran into a similar problem as @personalizedrefrigerator and ended up submitting a PR for it: #164

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants