-
Notifications
You must be signed in to change notification settings - Fork 1.1k
fix(flue-review): cap tar entry size and honor pax linkpath overrides #2388
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -126,6 +126,72 @@ describe("untarInto", () => { | |||||||||||||||||||||||||||||||||||||
| expect(r.files.has("/repo/ignored-name.txt")).toBe(false); | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| it("applies pax linkpath and GNU longlink overrides to symlink targets", async () => { | ||||||||||||||||||||||||||||||||||||||
| const longTarget = `deep/${"d/".repeat(40)}target.txt`; | ||||||||||||||||||||||||||||||||||||||
| const paxBody = `linkpath=${longTarget}\n`; | ||||||||||||||||||||||||||||||||||||||
| const paxLen = String(paxBody.length + 3).length + 1 + paxBody.length; | ||||||||||||||||||||||||||||||||||||||
| const paxBytes = encoder.encode(`${paxLen} ${paxBody}`); | ||||||||||||||||||||||||||||||||||||||
| const longLinkBytes = encoder.encode(longTarget); | ||||||||||||||||||||||||||||||||||||||
| const r = recorder(); | ||||||||||||||||||||||||||||||||||||||
| await untarInto( | ||||||||||||||||||||||||||||||||||||||
| r.target, | ||||||||||||||||||||||||||||||||||||||
| tarball([ | ||||||||||||||||||||||||||||||||||||||
| header({ name: "repo-abc/PaxHeader", type: "x", size: paxBytes.length }), | ||||||||||||||||||||||||||||||||||||||
| contentBlocks(paxBytes), | ||||||||||||||||||||||||||||||||||||||
| header({ name: "repo-abc/pax-link", type: "2", linkTarget: "short" }), | ||||||||||||||||||||||||||||||||||||||
| header({ name: "repo-abc/@LongLink", type: "K", size: longLinkBytes.length }), | ||||||||||||||||||||||||||||||||||||||
| contentBlocks(longLinkBytes), | ||||||||||||||||||||||||||||||||||||||
| header({ name: "repo-abc/gnu-link", type: "2", linkTarget: "short" }), | ||||||||||||||||||||||||||||||||||||||
| header({ name: "repo-abc/plain-link", type: "2", linkTarget: "short" }), | ||||||||||||||||||||||||||||||||||||||
| ]), | ||||||||||||||||||||||||||||||||||||||
| "/repo", | ||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||
| expect(r.symlinks.get("/repo/pax-link")).toBe(longTarget); | ||||||||||||||||||||||||||||||||||||||
| expect(r.symlinks.get("/repo/gnu-link")).toBe(longTarget); | ||||||||||||||||||||||||||||||||||||||
| expect(r.symlinks.get("/repo/plain-link")).toBe("short"); | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| it("rejects pax linkpath targets that escape the destination", async () => { | ||||||||||||||||||||||||||||||||||||||
| const paxBody = "linkpath=../../etc/passwd\n"; | ||||||||||||||||||||||||||||||||||||||
| const paxLen = String(paxBody.length + 3).length + 1 + paxBody.length; | ||||||||||||||||||||||||||||||||||||||
| const paxBytes = encoder.encode(`${paxLen} ${paxBody}`); | ||||||||||||||||||||||||||||||||||||||
| const r = recorder(); | ||||||||||||||||||||||||||||||||||||||
| await expect( | ||||||||||||||||||||||||||||||||||||||
| untarInto( | ||||||||||||||||||||||||||||||||||||||
| r.target, | ||||||||||||||||||||||||||||||||||||||
| tarball([ | ||||||||||||||||||||||||||||||||||||||
| header({ name: "repo-abc/PaxHeader", type: "x", size: paxBytes.length }), | ||||||||||||||||||||||||||||||||||||||
| contentBlocks(paxBytes), | ||||||||||||||||||||||||||||||||||||||
| header({ name: "repo-abc/evil", type: "2", linkTarget: "harmless" }), | ||||||||||||||||||||||||||||||||||||||
| ]), | ||||||||||||||||||||||||||||||||||||||
| "/repo", | ||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||
| ).rejects.toThrow(/escapes the destination/); | ||||||||||||||||||||||||||||||||||||||
| expect(r.symlinks.size).toBe(0); | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| it("rejects entries whose size field is not strictly octal", async () => { | ||||||||||||||||||||||||||||||||||||||
| for (const sizeField of ["10x", "size!", "-0000001"]) { | ||||||||||||||||||||||||||||||||||||||
| const block = header({ name: "repo-abc/bad.bin" }); | ||||||||||||||||||||||||||||||||||||||
| block.set(encoder.encode(sizeField), 124); | ||||||||||||||||||||||||||||||||||||||
| const r = recorder(); | ||||||||||||||||||||||||||||||||||||||
| await expect(untarInto(r.target, tarball([block]), "/repo")).rejects.toThrow(/not octal/); | ||||||||||||||||||||||||||||||||||||||
| expect(r.files.size).toBe(0); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| it("rejects entries whose declared size exceeds the cap", async () => { | ||||||||||||||||||||||||||||||||||||||
| const r = recorder(); | ||||||||||||||||||||||||||||||||||||||
| await expect( | ||||||||||||||||||||||||||||||||||||||
| untarInto( | ||||||||||||||||||||||||||||||||||||||
| r.target, | ||||||||||||||||||||||||||||||||||||||
| tarball([header({ name: "repo-abc/huge.bin", size: 128 * 1024 * 1024 })]), | ||||||||||||||||||||||||||||||||||||||
| "/repo", | ||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||
| ).rejects.toThrow(/size out of range/); | ||||||||||||||||||||||||||||||||||||||
| expect(r.files.size).toBe(0); | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [needs fixing] The PR description says entries with a non-numeric or negative size field are now rejected, but the only new test covers an oversized (128 MiB) field. AGENTS.md asks for a failing test before the fix and verification after it; adding coverage for malformed size fields protects the new guard from future regressions.
Suggested change
|
||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| it("joins the ustar prefix field with the name", async () => { | ||||||||||||||||||||||||||||||||||||||
| const r = recorder(); | ||||||||||||||||||||||||||||||||||||||
| await untarInto( | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[suggestion] This one-line
!addition in the R2 instrumentation fixes a type error but is unrelated to the untar parser change. AGENTS.md discourages drive-by cleanups in unrelated files; if this was needed to keeppnpm typecheckgreen for the worker, note that in the test evidence, otherwise it belongs in its own PR.