fix(dotnet): validate bundle extents before adjustable limits (#12270)

Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com>
This commit is contained in:
ShuaixinHuangandShuaixinHuang authored and GitHub committed 2026-11-19 06:25:27 -05:00
1 parent e744f5d9e4
commit bf04d616fd
2 files changed
+35 -3

No files matched your search

+13 -3
View File
@@ -91,6 +91,12 @@ export const readDotnetBundle = async (
);
const count = await cursor.i32();
if (count < 0) fail(".NET bundle entry count is negative");
// Include the bundle ID length prefix and, starting at v2, the two
// configuration ranges and flags. Each row has a type and a path prefix.
const minimumHeaderTail = majorVersion >= 2 ? 41 : 1;
const minimumEntry = majorVersion === 6 ? 26 : 18;
if (minimumHeaderTail + count * minimumEntry > cursor.remainingBytes)
fail(".NET bundle entry count cannot fit in the manifest");
if (count > limits.entry_count)
throw artifactReaderLimitFailure(
"artifact_limits.dotnet_bundle.entry_count",
@@ -141,6 +147,9 @@ export const readDotnetBundle = async (
const path = await cursor.string();
const normalized = normalizeArtifactPath(path);
paths.add(normalized, "file");
const storedSize = compressedSize || fileSize;
if (offset > headerOffset || storedSize > headerOffset - offset)
fail(`.NET bundle entry crosses the manifest or file boundary: ${path}`);
if (fileSize > limits.member_bytes || compressedSize > limits.member_bytes)
throw artifactReaderLimitFailure(
"artifact_limits.dotnet_bundle.member_bytes",
@@ -156,9 +165,6 @@ export const readDotnetBundle = async (
"bytes",
expandedBytes,
);
const storedSize = compressedSize || fileSize;
if (offset > headerOffset || storedSize > headerOffset - offset)
fail(`.NET bundle entry crosses the manifest or file boundary: ${path}`);
files.push({ path, offset, size: fileSize, compressedSize, fileType });
}
const ranges = files
@@ -202,6 +208,10 @@ class BundleCursor {
this.#position = start;
}
get remainingBytes(): number {
return this.size - this.#position;
}
async take(length: number): Promise<Buffer> {
abortIfNeeded(this.signal);
const consumed = this.#position - this.start;
@@ -396,6 +396,27 @@ it.each([
() => dotnetBundleFixture(undefined, 7).bytes,
"unavailable",
],
[
"entry count with no room for its manifest rows",
() => {
const fixture = dotnetBundleFixture();
fixture.bytes.writeInt32LE(0x7fff_ffff, fixture.fields.entryCount);
return fixture.bytes;
},
"format",
],
[
"uncompressed member crossing the manifest above the member allowance",
() =>
dotnetBundleFixture([
{
path: "large",
bytes: Buffer.from("x"),
declaredSize: 600 * 1024 * 1024,
},
]).bytes,
"format",
],
[
"expanded budget",
() =>
@@ -403,6 +424,7 @@ it.each([
{
path: "large",
bytes: Buffer.from("x"),
compressed: true,
declaredSize: 600 * 1024 * 1024,
},
]).bytes,