fix(tar): account for retained pax owner names (#15195)

* fix(tar): account for retained pax owner names

* test(tar): cover retained names across global replacements

* test(tar): narrow owner metadata to its format

* test(tar): use the measured retained metadata boundary

---------

Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com>
Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
This commit is contained in:
authored and GitHub committed 2026-11-30 18:06:03 +08:00
1 parent 81384ecfdc
commit 2f01f653ce
3 files changed
+97 -6

No files matched your search

+1 -1
View File
@@ -78,7 +78,7 @@ extraction never writes outside its fresh output root.
- Gzip decompression, including the preparation pass, is charged to the archive plaintext-work allowance `artifact_limits.expanded_bytes`. Its default is the larger of 256 MiB and 500 times the file size.
- Members opened in archive order share one forward decompression. A member opened out of order starts a new decompression, which is charged again.
- `artifact_limits.tar.extended_header_bytes` (default 1 MiB) bounds one pax or GNU long-name record.
- `artifact_limits.tar.metadata_bytes` (default 64 MiB) bounds retained member metadata: a fixed 512 bytes per member plus its path and link bytes. A refusal reports either field in `details.reader_limit`.
- `artifact_limits.tar.metadata_bytes` (default 64 MiB) bounds retained member metadata: a fixed 512 bytes per member plus its path, link, and extended PAX owner names. A refusal reports either field in `details.reader_limit`.
- A reader serves at most four member streams at once.
## CLI
@@ -710,6 +710,92 @@ describe("tar header edge cases", () => {
}
});
it("charges retained pax owner names across members", async () => {
const owner = "a".repeat(8_000);
const group = "b".repeat(8_000);
const archive = Buffer.concat([
...[
["uname", owner],
["gname", group],
].map(([key, value], index) => {
const pax = Buffer.from(`8012 ${key}=${value}\n`);
return Buffer.concat([
tarHeader({ name: "PaxHeader", type: "x" }, pax.length),
pax,
Buffer.alloc(512 - (pax.length % 512)),
tarHeader({ name: `file-${String(index)}` }, 0),
]);
}),
end,
]);
const reader = new TarArtifactReader(
await write("pax-owner-budget.tar", archive),
undefined,
undefined,
{ ...DEFAULT_TAR_READER_LIMITS, metadata_bytes: 24 * 1024 },
);
try {
await expect(async () => {
for await (const entry of reader.entries()) void entry;
}).rejects.toMatchObject({
reason: "limit",
readerLimit: { parameter: "artifact_limits.tar.metadata_bytes" },
});
} finally {
await reader.close();
}
const accepted = await read(archive);
expect(accepted.entries[0]?.formatMetadata).toMatchObject({ uname: owner });
expect(accepted.entries[1]?.formatMetadata).toMatchObject({ gname: group });
expect(accepted.coverage[0]?.status).toBe("complete");
});
it("keeps inherited owner charges when a global name is replaced", async () => {
const owner = "a".repeat(3_000);
const replacement = "b".repeat(3_000);
const globalOwner = (value: string) => {
const pax = Buffer.from(`3012 uname=${value}\n`);
return Buffer.concat([
tarHeader({ name: "GlobalHead", type: "g" }, pax.length),
pax,
Buffer.alloc(512 - (pax.length % 512)),
]);
};
const inventory = async (fourthMember: boolean) => {
const archive = Buffer.concat([
globalOwner(owner),
tarHeader({ name: "first" }, 0),
tarHeader({ name: "second" }, 0),
globalOwner(replacement),
tarHeader({ name: "third" }, 0),
...(fourthMember ? [tarHeader({ name: "fourth" }, 0)] : []),
end,
]);
const reader = new TarArtifactReader(
await write("pax-global-owner-budget.tar", archive),
undefined,
undefined,
{ ...DEFAULT_TAR_READER_LIMITS, metadata_bytes: 24 * 1024 },
);
try {
const entries: ArtifactEntry[] = [];
for await (const entry of reader.entries()) entries.push(entry);
return entries;
} finally {
await reader.close();
}
};
expect(
(await inventory(false)).map(({ formatMetadata }) =>
formatMetadata?.kind === "tar-entry" ? formatMetadata.uname : undefined,
),
).toEqual([owner, owner, replacement]);
await expect(inventory(true)).rejects.toMatchObject({
reason: "limit",
readerLimit: { parameter: "artifact_limits.tar.metadata_bytes" },
});
});
it("charges hdrcharset=BINARY warnings to the retained metadata allowance", async () => {
const metadataBytes = 64 * 1024;
// The same-sized uname leaves the global map charge unchanged; only the
+10 -5
View File
@@ -33,9 +33,9 @@ import { TarStreamEnded, type TarByteStream } from "./TarByteStream.js";
* or GNU long-name record read into memory. Real records hold one path or a
* few attributes; the allowance only stops a declared size from forcing an
* arbitrary allocation. `artifact_limits.tar.metadata_bytes` bounds retained
* member metadata: a fixed per-member charge plus decoded path and link
* bytes, and the global pax map, for streams of many tiny members or repeated
* pax global headers.
* member metadata: a fixed per-member charge plus decoded paths, links and
* pax owner names, and the global pax map, for streams of many tiny members or
* repeated pax global headers.
*/
const MEMBER_OVERHEAD_BYTES = 512;
/** One map entry retained with a pax keyword, besides its key and value bytes. */
@@ -520,11 +520,16 @@ export const walkTar = async (
// Only an inventoried member keeps its pax warnings.
if ("omit" in role || role.member === "root")
retained.refund(chargedMemberLimitations);
const keepsMetadata = "member" in role && role.member !== "root";
const paxUser = keepsMetadata ? records.get("uname") : undefined;
const paxGroup = keepsMetadata ? records.get("gname") : undefined;
// Omissions are retained too, so they share the metadata allowance.
if ("omit" in role || role.member !== "root")
retained.charge(
MEMBER_OVERHEAD_BYTES +
2 * (Buffer.byteLength(path) + Buffer.byteLength(linkName ?? "")) +
// Pax owner names can exceed the fixed-width ustar fields.
2 * ((paxUser?.length ?? 0) + (paxGroup?.length ?? 0)) +
// Each target byte becomes two retained UTF-16 hex digits.
4 * (symlinkBytes?.length ?? 0),
metadataLimit,
@@ -546,12 +551,12 @@ export const walkTar = async (
gid: safeNumber(decimal(records.get("gid")) ?? header.gid),
mtime: safeNumber(paxSeconds(records.get("mtime")) ?? header.mtime),
uname:
records.get("uname") ??
paxUser ??
(header.uname.length === 0
? null
: decodeName(header.uname, "user name", memberLimitations)),
gname:
records.get("gname") ??
paxGroup ??
(header.gname.length === 0
? null
: decodeName(header.gname, "group name", memberLimitations)),