fix(dotnet): validate bundle string lengths before reader limits (#12272)

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:23 -05:00
1 parent 447735c170
commit e744f5d9e4
2 files changed
+35 -1

No files matched your search

+4 -1
View File
@@ -274,9 +274,12 @@ class BundleCursor {
let length = 0;
for (let shift = 0; shift <= 28; shift += 7) {
const byte = (await this.take(1))[0]!;
if (shift === 28 && byte > 15) fail("Invalid .NET bundle string length");
// BinaryReader.ReadString uses a nonnegative signed Int32 length.
if (shift === 28 && byte > 7) fail("Invalid .NET bundle string length");
length += (byte & 127) * 2 ** shift;
if ((byte & 128) !== 0) continue;
if (length > this.size - this.#position)
fail("Truncated .NET bundle manifest");
if (length > this.limits.string_bytes)
throw artifactReaderLimitFailure(
"artifact_limits.dotnet_bundle.string_bytes",
@@ -24,6 +24,37 @@ import {
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { writeMinimalElfHeader } from "../../fixtures/nativeHeaders.js";
it.each([
{
length: [0x80, 0x80, 0x80, 0x80, 0x08],
message: "Invalid .NET bundle string length",
},
{
length: [0xff, 0xff, 0xff, 0xff, 0x07],
message: "Truncated .NET bundle manifest",
},
])(
"reports malformed bundle ID length $length as a format failure",
async ({ length, message }) => {
const root = await createTestTempDirectory("rea-dotnet-invalid-string-");
const path = join(root, "host.exe");
const fixture = dotnetBundleFixture([
{ path: "member", bytes: Buffer.from("x") },
]);
// The fixed manifest prefix contains two version fields and a file count.
fixture.bytes.set(length, fixture.headerOffset + 12);
await writeFile(path, fixture.bytes);
const handle = await open(path, "r");
try {
await expect(
readDotnetBundle(handle, fixture.bytes.length, fixture.headerOffset),
).rejects.toMatchObject({ reason: "format", message });
} finally {
await handle.close();
}
},
);
it.each(["close", "cancel"] as const)(
"does not complete a .NET bundle inventory after %s at the last entry",
async (interruption) => {