Skip to content

Commit 13d6195

Browse files
authored
Merge pull request #141 from arethetypeswrong/bug/extract-padded-tarball
Fix tarball extract crash
2 parents 9227047 + 6840409 commit 13d6195

File tree

6 files changed

+20
-7
lines changed

6 files changed

+20
-7
lines changed

.changeset/clever-clouds-bake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@arethetypeswrong/core": patch
3+
---
4+
5+
Fix extracting some non-compliant tarballs

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
},
4949
"dependencies": {
5050
"@andrewbranch/untar.js": "^1.0.3",
51-
"fflate": "^0.7.4",
51+
"fflate": "^0.8.2",
5252
"semver": "^7.5.4",
5353
"ts-expose-internals-conditionally": "1.0.0-empty.0",
5454
"typescript": "5.3.3",

packages/core/src/createPackage.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { untar } from "@andrewbranch/untar.js";
2-
import { gunzipSync } from "fflate";
2+
import { Gunzip } from "fflate";
33
import { major, maxSatisfying, minor, valid, validRange } from "semver";
44
import ts from "typescript";
55
import { parsePackageSpec, type ParsedPackageSpec } from "./utils.js";
@@ -279,7 +279,10 @@ export function createPackageFromTarballData(tarball: Uint8Array): Package {
279279
}
280280

281281
function extractTarball(tarball: Uint8Array) {
282-
const data = untar(gunzipSync(tarball));
282+
// Use streaming API to work around https://github.com/101arrowz/fflate/issues/207
283+
let unzipped: Uint8Array;
284+
new Gunzip((chunk) => (unzipped = chunk)).push(tarball, /*final*/ true);
285+
const data = untar(unzipped!);
283286
const prefix = data[0].filename.substring(0, data[0].filename.indexOf("/") + 1);
284287
const packageJsonText = data.find((f) => f.filename === `${prefix}package.json`)?.fileData;
285288
const packageJson = JSON.parse(new TextDecoder().decode(packageJsonText));
10 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"packageName": "openurl",
3+
"packageVersion": "1.0.2",
4+
"types": false
5+
}

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)