diff --git a/src/artifacts/dotnet/DotnetBundle.ts b/src/artifacts/dotnet/DotnetBundle.ts index 4ac457ef32..f9bff1bd56 100644 --- a/src/artifacts/dotnet/DotnetBundle.ts +++ b/src/artifacts/dotnet/DotnetBundle.ts @@ -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 { abortIfNeeded(this.signal); const consumed = this.#position - this.start; diff --git a/tests/boundary/filesystem/dotnetBundleArtifacts.test.ts b/tests/boundary/filesystem/dotnetBundleArtifacts.test.ts index 12c4d3ec75..2b1adc7c6b 100644 --- a/tests/boundary/filesystem/dotnetBundleArtifacts.test.ts +++ b/tests/boundary/filesystem/dotnetBundleArtifacts.test.ts @@ -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,