Skip to content

Commit

Permalink
fix: don't fail on malformed tar headers (#6674)
Browse files Browse the repository at this point in the history
close #5362
  • Loading branch information
illright committed Jun 14, 2023
1 parent b9ffc28 commit e57e2d3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changeset/orange-garlics-compete.md
@@ -0,0 +1,6 @@
---
"@pnpm/cafs": patch
"pnpm": patch
---

Don't fail when a package is archived in a tarball with malformed tar headers [#5362](https://github.com/pnpm/pnpm/issues/5362).
2 changes: 1 addition & 1 deletion store/cafs/src/addFilesFromTarball.ts
Expand Up @@ -11,7 +11,7 @@ export async function addFilesFromTarball (
manifest?: DeferredManifestPromise
): Promise<FilesIndex> {
const ignore = _ignore ?? (() => false)
const extract = tar.extract()
const extract = tar.extract({ allowUnknownFormat: true })
const filesIndex: FilesIndex = {}
await new Promise<void>((resolve, reject) => {
extract.on('entry', (header, fileStream, next) => {
Expand Down
Binary file not shown.
8 changes: 8 additions & 0 deletions store/cafs/test/index.ts
Expand Up @@ -74,3 +74,11 @@ test('file names are normalized when unpacking a tarball', async () => {
'package.json',
])
})

test('broken magic in tarball headers is handled gracefully', async () => {
const dest = tempy.directory()
const cafs = createCafs(dest)
await cafs.addFilesFromTarball(
createReadStream(path.join(__dirname, 'fixtures/jquery.dirtyforms-2.0.0.tgz'))
)
})

0 comments on commit e57e2d3

Please sign in to comment.