Compare commits

..
Author SHA1 Message Date
Kaoru0822 4ff226e98e Merge remote-tracking branch 'origin/main' into fix/nativeaot-pe-virtual-extent 2026-10-11 03:10:16 +00:00
morluto e5bc4e85ec fix(ci): close speculative browser fixture connections 2026-10-11 11:05:08 +08:00
Kaoru0822andClaude Opus 5.5 9f30b01387 style(native): format NativeAOT diagnostics after lint fix
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 02:50:20 +00:00
Kaoru0822andClaude Opus 5.5 707797d80f fix(native): bound NativeAOT PE reads by section virtual size
The NativeAOT PE parser from 76d8f68cb treated a section as
`max(VirtualSize, SizeOfRawData)` bytes when reading, and as
SizeOfRawData bytes when classifying executable code and choosing scan
ranges. These are the extents #1596 removed from managed RVA reads.
Raw alignment padding past VirtualSize could supply frozen strings with
complete status, and vtable slots pointing into it counted as executable.

Reads, executable checks, hydration extents and the image-extent check now
use the loader's virtual extent (VirtualSize, or SizeOfRawData when it is
zero). Pointer scans cover only bytes that are both file-backed and mapped.

Refs #1596

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 02:47:37 +00:00
4 changed files with 63 additions and 62 deletions

No files matched your search

+3 -18
View File
@@ -99,12 +99,6 @@ const scenarioFor = (browser, origin) =>
capture: { after_each_step: ["dom"], at_end: ["dom"] },
});
const storageStart = Date.now();
const stage = (name) =>
process.stderr.write(
`[verify:browser:storage] ${name} +${String(Date.now() - storageStart)}ms\n`,
);
const raceWithTimeout = (operation, timeoutMs, onTimeout = () => undefined) => {
const controller = new AbortController();
return Promise.race([
@@ -181,9 +175,10 @@ const startStorageSite = async () => {
return {
origin: `http://127.0.0.1:${port}`,
close: async () => {
// The external browser outlives this site and can keep sockets open.
server.closeAllConnections();
server.close();
// Chrome can leave speculative TCP connections without an HTTP request;
// server.close() alone waits indefinitely for those owned sockets.
server.closeAllConnections();
await once(server, "close");
},
};
@@ -208,11 +203,8 @@ export async function verifyScenarioStorage({
}) {
const site = await startStorageSite();
try {
stage("launch");
await verifyLaunchStorage(executable, site.origin);
stage("connect");
await verifyConnectedStorage(endpoint, targetId, site.origin);
stage("close");
return {
mocked: false,
launch: true,
@@ -235,7 +227,6 @@ const verifyLaunchStorage = async (executable, origin) => {
origin,
);
const profilesBefore = await scenarioProfiles();
stage("launch: scenario CLI");
const result = await runScenarioCli(scenario);
const capture = result.normalized_result;
assert.ok(capture, "Launch-mode storage scenario returned no result");
@@ -248,7 +239,6 @@ const verifyLaunchStorage = async (executable, origin) => {
...scenario,
actions: [scenario.actions[0]],
});
stage("launch: fresh in-process scenario");
const fresh = await createBrowserScenarioProvider(
process.env,
).captureScenario(freshScenario);
@@ -310,9 +300,7 @@ const verifyConnectedStorage = async (endpoint, targetId, origin) => {
"capture_browser_scenario",
);
try {
stage("connect: storage partition");
await assertStorageKeyPartition(observer, origin);
stage("connect: scenario CLI");
const result = await runScenarioCli(scenario);
const capture = result.normalized_result;
assert.ok(capture, "Connect-mode storage scenario returned no result");
@@ -323,12 +311,9 @@ const verifyConnectedStorage = async (endpoint, targetId, origin) => {
empty: "main-empty-seed",
});
assert.equal(capture.browser.cleanup, "disconnected-external");
stage("connect: caller debugger pause");
await verifyCallerDebuggerPause(observer, origin, scenario);
stage("connect: cancellation");
await verifyCancelledStorage(observer, endpoint, targetId, scenario);
} finally {
stage("connect: restore target");
await raceWithTimeout(restoreTarget(observer, target.url), 1_000).catch(
() => undefined,
);
+4 -20
View File
@@ -53,12 +53,6 @@ const SCENARIO_URL_SECRET_VALUE = "rea-browser-url-verifier-secret";
process.env.REA_BROWSER_VERIFIER_SECRET = SCENARIO_SECRET_VALUE;
process.env.REA_BROWSER_VERIFIER_URL = SCENARIO_URL_SECRET_VALUE;
const verifierRun = createVerifierRun();
const verifierStart = Date.now();
// Stage markers locate a stalled step when CI cancels the job at its limit.
const stage = (name) =>
process.stderr.write(
`[verify:browser] ${name} +${String(Date.now() - verifierStart)}ms\n`,
);
const executable = await browserExecutable();
const profile = await mkdtemp(join(tmpdir(), "rea-real-browser-"));
@@ -115,7 +109,6 @@ try {
);
if (!observed.ok) throw observed.error;
assertObservation(observed.value, site.origin);
stage("verifyBrowserDomDestinations");
const domDestinations = await verifyBrowserDomDestinations({
cdp_endpoint: endpoint,
target_id: target,
@@ -175,7 +168,6 @@ try {
);
assertSensitiveShapes(withSource.value);
stage("verifyPublicBundle");
const bundle = await verifyPublicBundle(endpoint, target, site.origin);
const captureDiff = await provider.compareCaptures(
@@ -239,7 +231,6 @@ try {
throw new Error("Real Chrome same-origin SPA timeline was missing");
pageProxy = await startPageCdpProxy(endpoint);
stage("verifyPageScopedTransport");
await verifyPageScopedTransport(provider, pageProxy, site.origin);
const attachedScenarioInput = browserScenario(
{
@@ -286,19 +277,18 @@ try {
throw new Error("Scenario attachment terminated its external browser");
const profilesBefore = await scenarioProfiles();
stage("verifyScenarioEnvironment");
process.stderr.write("Browser verifier: scenario environment\n");
const scenarioEnvironment = await verifyScenarioEnvironment(
endpoint,
target,
site.origin,
);
stage("verifyScenarioStorage");
process.stderr.write("Browser verifier: scenario storage\n");
const scenarioStorage = await verifyScenarioStorage({
executable,
endpoint,
targetId: target,
});
stage("launchedScenario");
const launchedScenario = await createBrowserScenarioProvider(
process.env,
).captureScenario(
@@ -320,7 +310,6 @@ try {
if ([...profilesAfter].some((entry) => !profilesBefore.has(entry)))
throw new Error("Scenario launch retained a temporary browser profile");
assertScenarioCapture(launchedScenario.value);
stage("verifyScenarioFailureEvidence");
const scenarioFailure = await verifyScenarioFailureEvidence(
executable,
site.origin,
@@ -352,24 +341,20 @@ try {
`Browser scenario included unselected structured value: ${unselectedValue}`,
);
stage("verifyLargeScreenshotE2e");
process.stderr.write("Browser verifier: large screenshot\n");
const largeScreenshot = await verifyLargeScreenshotE2e(endpoint, site.origin);
stage("verifyPopupEventCoverage");
process.stderr.write("Browser verifier: popup coverage\n");
const popupEvents = await verifyPopupEventCoverage(executable);
stage("verifyBrowserNetworkEvidence");
const networkEvidence = await verifyBrowserNetworkEvidence(
executable,
undefined,
{ cdp_endpoint: endpoint, target_id: target },
);
stage("verifyBrowserScriptExport");
const scriptExport = await verifyBrowserScriptExport(executable, undefined, {
cdp_endpoint: endpoint,
target_id: target,
});
stage("verifyBrowserModules");
const moduleTrace = await verifyBrowserModules(executable);
stage("verifyBrowserCaptureMetadataBudget");
const captureMetadata = await verifyBrowserCaptureMetadataBudget(endpoint);
report = {
browser: observed.value.browser.product,
@@ -412,7 +397,6 @@ try {
process.stderr.write("Browser verifier cleanup: stopping owned Chrome\n");
if (browser !== undefined) await stopProcess(browser);
process.stderr.write("Browser verifier cleanup: closing fixture site\n");
stage("cleanup");
await site.close();
await rm(profile, {
recursive: true,
+36
View File
@@ -103,3 +103,39 @@ describe("read-only NativeAOT PE parser", () => {
});
});
});
describe("NativeAOT PE section virtual extent", () => {
const TEXT_VIRTUAL_SIZE = 0x188 + 8;
const RDATA_VIRTUAL_SIZE = 0x188 + 40 + 8;
const parseWithVirtualSize = (at: number, virtualSize: number) => {
const bytes = nativeAotPeFixture();
bytes.writeUInt32LE(virtualSize, at);
return parseNativeAotPe(
bytes,
nativeAotPeDigest(bytes),
SUMMARY_BUDGET,
"0x140000000",
).summary;
};
it("does not treat raw padding past VirtualSize as executable code", () => {
// The 0x2280 MethodTable's only slot targets 0x1040, past .text's 0x40 bytes.
expect(parseWithVirtualSize(TEXT_VIRTUAL_SIZE, 0x40)).toMatchObject({
method_tables: 2,
});
});
it("does not read a frozen string from raw padding past VirtualSize", () => {
expect(parseWithVirtualSize(RDATA_VIRTUAL_SIZE, 0x300)).toMatchObject({
status: "partial",
frozen_strings: [],
});
});
it("maps raw bytes when VirtualSize is zero, as the image loader does", () => {
expect(parseWithVirtualSize(TEXT_VIRTUAL_SIZE, 0)).toMatchObject({
status: "complete",
method_tables: 3,
});
});
});
+20 -24
View File
@@ -366,6 +366,13 @@ const parsedSummary = (
readTypeDetail: () => undefined,
});
// The image loader maps VirtualSize bytes, using SizeOfRawData only when
// VirtualSize is zero. Raw bytes past that extent are file-alignment padding.
const virtualExtent = (section: Section): number =>
section.virtualSize === 0 ? section.rawSize : section.virtualSize;
const fileBackedExtent = (section: Section): number =>
Math.min(section.rawSize, virtualExtent(section));
class PeImage {
readonly imageBase: bigint;
readonly sizeOfImage: number;
@@ -417,10 +424,7 @@ class PeImage {
});
for (const section of this.sections) {
this.#range(section.rawOffset, section.rawSize);
if (
section.rva + Math.max(section.virtualSize, section.rawSize) >
this.sizeOfImage
)
if (section.rva + virtualExtent(section) > this.sizeOfImage)
throw new Error("PE section exceeds the declared image extent");
}
}
@@ -456,11 +460,11 @@ class PeImage {
for (const section of this.sections) {
if (this.#budget !== undefined && !this.#budget.consumeWork(1))
return null;
const extent = Math.max(section.virtualSize, section.rawSize);
const extent = virtualExtent(section);
if (relative < section.rva || relative - section.rva > extent - size)
continue;
const delta = relative - section.rva;
if (delta > section.rawSize - size) return null;
if (delta > fileBackedExtent(section) - size) return null;
const offset = section.rawOffset + delta;
return this.#bytes.subarray(offset, offset + size);
}
@@ -475,7 +479,7 @@ class PeImage {
if (
(section.characteristics & 0x20000000) !== 0 &&
rva >= BigInt(section.rva) &&
rva < BigInt(section.rva + section.rawSize)
rva < BigInt(section.rva + virtualExtent(section))
)
return true;
}
@@ -492,10 +496,7 @@ class PeImage {
if (this.#budget !== undefined && !this.#budget.consumeWork(1)) return 0;
if (
rva >= BigInt(candidate.rva) &&
rva <
BigInt(
candidate.rva + Math.max(candidate.virtualSize, candidate.rawSize),
)
rva < BigInt(candidate.rva + virtualExtent(candidate))
) {
section = candidate;
break;
@@ -503,9 +504,7 @@ class PeImage {
}
return section === undefined
? 0
: section.rva +
Math.max(section.virtualSize, section.rawSize) -
Number(rva);
: section.rva + virtualExtent(section) - Number(rva);
}
#range(offset: number, size: number): void {
if (
@@ -602,7 +601,7 @@ const findDirectory = (
)
continue;
const begin = section.rawOffset;
const end = begin + section.rawSize;
const end = begin + fileBackedExtent(section);
const first = (begin + 7) & ~7;
const candidateBytes =
first <= end - 16 ? (Math.floor((end - 16 - first) / 8) + 1) * 8 : 0;
@@ -970,10 +969,10 @@ const discoverTables = (
(section.characteristics & 0x20000000) !== 0
)
continue;
if (section.rawSize > 0) {
if (fileBackedExtent(section) > 0) {
ranges.push({
start: image.addressForRva(section.rva),
end: image.addressForRva(section.rva + section.rawSize),
end: image.addressForRva(section.rva + fileBackedExtent(section)),
});
}
}
@@ -984,9 +983,7 @@ const discoverTables = (
(candidate.characteristics & 0x20000000) === 0 &&
hydrated.base >= image.addressForRva(candidate.rva) &&
hydrated.base + BigInt(hydrated.sizeBytes) <=
image.addressForRva(
candidate.rva + Math.max(candidate.virtualSize, candidate.rawSize),
),
image.addressForRva(candidate.rva + virtualExtent(candidate)),
);
if (section !== undefined)
ranges.push({
@@ -1592,11 +1589,10 @@ export const parseNativeAotPe = (
? "raw-image-pointer-scan"
: "raw-image-and-rehydrated-pointer-scan",
},
diagnostics: [
...(hydrationError === null
diagnostics:
hydrationError === null
? []
: [`Read-only hydration stopped: ${hydrationError}`]),
],
: [`Read-only hydration stopped: ${hydrationError}`],
limitations: reportLimitations,
};
if (Buffer.byteLength(JSON.stringify(summary)) > maximumSummaryBytes)