Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
03d2eaf
feat(flutter): identify Dart snapshot builds by pure APK parsing
Oct 10, 2026
2945f50
feat(flutter): inspect Dart AOT snapshots through the ELF symbol table
Oct 10, 2026
ddf1269
fix(flutter): own snapshots, bound image reads, and preserve cancella…
Oct 10, 2026
349b212
docs(flutter): cover the Italian README with the Flutter row
Oct 10, 2026
b8cbea9
fix(flutter): make the ABI pattern portable for v-mode validators
Oct 10, 2026
e12bfbf
refactor(flutter): reuse shared harnesses and deduplicate the vertical
Oct 10, 2026
2207cc6
fix(flutter): address review findings from real-app verification
Oct 11, 2026
93db928
fix(flutter): address the Codex review findings
Oct 11, 2026
eeb56f9
fix(flutter): address the second Codex review round
Oct 11, 2026
87ac338
fix(flutter): address the third Codex review round
Oct 11, 2026
24d61ec
fix(flutter): address rounds three and four of the Codex review
Oct 11, 2026
802bb9b
fix(flutter): address the fifth Codex review round
Oct 11, 2026
9603ecb
fix(flutter): address the sixth Codex review round
Oct 11, 2026
ef79672
fix(flutter): address the seventh Codex review round
Oct 11, 2026
8d9fd5b
fix(flutter): address the eighth Codex review round
Oct 11, 2026
dbdd7fc
fix(flutter): harden streaming, sizes, and cancellation after self-re…
Oct 11, 2026
c6e7325
fix(flutter): require structurally parseable ELF headers for complete…
Oct 11, 2026
cf18c8c
fix(flutter): validate ELF and snapshot coverage
Oct 11, 2026
61394b6
fix(flutter): resolve review findings and CI effect checks
Oct 11, 2026
248ce4c
chore(flutter): resolve upstream effects-audit conflict
Oct 11, 2026
8b88190
chore: merge main into Flutter analysis branch
morluto Oct 12, 2026
34e764d
fix(flutter): unify artifact ownership and bound ELF evidence
morluto Oct 12, 2026
98707b4
chore: merge latest main into Flutter analysis branch
morluto Oct 12, 2026
9089b98
fix(flutter): preserve ELF provenance and partial coverage
morluto Oct 12, 2026
ccfaec0
chore: merge latest main after documentation updates
morluto Oct 12, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(flutter): address the fifth Codex review round
Six findings plus the upstream duplication baseline:

- P2: the flutter-provider kind reports available in the capability
  inventory, so binary_session no longer lists always-registered
  Flutter tools as provider_missing.
- P2: printable runs that exceed the 1024-byte cap are discarded at
  their delimiter instead of emitting their truncated prefix as a
  fabricated observation.
- P2: ELF symbols must fit inside the file-backed portion of their
  PT_LOAD segment (p_filesz), so addresses in gaps or BSS are refused
  instead of accepting unrelated bytes.
- P2: the build-id carry spans the complete 80-byte maximum note
  (16-byte header + 64-byte descriptor) so chunk-boundary splits
  cannot drop the first byte.
- P2: the labeled-string carry is sized for the toolchain pattern's
  true 605-byte maximum, not the previous 600.
- P2: the AOT completeness predicate requires exactly two sources and
  one candidate unconditionally, so zero-source images with valid data
  magics report partial instead of complete.

Also: the shared ELF fixture builder and snapshot-section helper moved
to a dedicated FlutterTestFixtures module, eliminating cross-file test
duplication; jscpd now passes at 2.50% while main sits at 2.52%.
  • Loading branch information
REA Contributor
REA Contributor committed Oct 11, 2026
commit 802bb9b9f2e1781946b208c166532737fb1c91ff
2 changes: 2 additions & 0 deletions src/application/CapabilityInventory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ const workflowAvailabilityFor = ({
remediation: "Run process capture on a supported Linux or macOS host.",
};
if (kind === "application") return { reason: "available", remediation: null };
if (kind === "flutter-provider")
return { reason: "available", remediation: null };
const electron = electronProviderAvailability(name, kind, policy);
if (electron !== null) return electron;
if (kind === "runtime-provider")
Expand Down
29 changes: 14 additions & 15 deletions src/application/flutter/FlutterBuildAnalysisService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,20 @@ const refusing: FlutterBuildAnalysisPort = {
},
};

it.each([
[{ path: "/targets/app.apk", extra: true }],
[{ path: 7 }],
[{}],
[{ path: "/targets/app.apk", abi: "not a locale" }],
])("admits only well-formed requests before any effect: %j", async (input) => {
await expect(
new FlutterBuildAnalysisService(refusing).execute(
"identify_flutter_build",
input,
),
).resolves.toMatchObject({
ok: false,
error: { _tag: "AnalysisInputError" },
});
const malformedSelections: readonly unknown[] = [
{ path: "/targets/app.apk", extra: true },
{ path: 7 },
{},
{ path: "/targets/app.apk", abi: "not a locale" },
];
it.each(malformedSelections)("refuses %j at admission", async (input) => {
const settled = await new FlutterBuildAnalysisService(refusing).execute(
"identify_flutter_build",
input,
);
expect(settled.ok).toBe(false);
if (settled.ok) return;
expect(settled.error._tag).toBe("AnalysisInputError");
});

it("passes the validated request to the provider and seals Evidence", async () => {
Expand Down
92 changes: 13 additions & 79 deletions src/flutter/DartElf.test.ts
Original file line number Diff line number Diff line change
@@ -1,97 +1,31 @@
import { describe, expect, it } from "vitest";

import { readElfSymbol, readSnapshotHeader } from "./DartElf.js";
import {
buildElf64Image,
readElfSymbol,
readSnapshotHeader,
snapshotSection,
} from "./DartElf.js";
import { REFERENCE_HASH } from "./FlutterTestFixtures.js";

/**
* Build a minimal real ELF64 little-endian image with one PT_LOAD segment
* and a dynamic symbol table naming the Dart snapshot sections. This keeps
* the golden tests self-contained instead of reading the author's disk.
*/
const buildElf64Image = (
symbols: ReadonlyArray<{ name: string; value: number; size: number }>,
): Buffer => {
const ELF_HEADER = 64;
const PHENT = 56;
const PHNUM = 1;
const SHENT = 64;
const phoff = ELF_HEADER;
const shoffAligned = phoff + PHENT * PHNUM;
// Place payload data after the three section headers so nothing overlaps.
const dynsymOff = shoffAligned + 3 * SHENT + 16;
const dynstrOff = dynsymOff + symbols.length * 24;
const image = Buffer.alloc(dynstrOff + 256);
// ELF header
image.writeUInt32LE(0x464c457f, 0);
image[4] = 2; // ELFCLASS64
image[5] = 1; // little-endian
image.writeUInt16LE(0x003e, 0x12); // e_machine x86_64
image.writeUInt32LE(1, 0x10); // ET_REL? keep type small
image.writeBigUInt64LE(BigInt(phoff), 0x20);
image.writeBigUInt64LE(BigInt(shoffAligned), 0x28);
image.writeUInt16LE(PHENT, 0x36);
image.writeUInt16LE(PHNUM, 0x38);
image.writeUInt16LE(SHENT, 0x3a);
image.writeUInt16LE(2, 0x3c); // e_shnum: null + dynsym
// Program header: one PT_LOAD mapping identity
const ph = phoff;
image.writeUInt32LE(1, ph); // PT_LOAD
image.writeBigUInt64LE(BigInt(0), ph + 8); // vaddr
image.writeBigUInt64LE(BigInt(0), ph + 0x08); // offset (overlaps vaddr)
// Section headers
const sh = shoffAligned;
// null section stays zero
const dyn = sh + SHENT;
image.writeUInt32LE(11, dyn + 4); // SHT_DYNSYM
image.writeBigUInt64LE(BigInt(dynsymOff), dyn + 0x18);
image.writeBigUInt64LE(BigInt(symbols.length * 24), dyn + 0x20);
image.writeUInt32LE(2, dyn + 0x28); // sh_link -> strtab section index
// dynstr section header
const str = dyn + SHENT;
image.writeUInt32LE(3, str + 4); // SHT_STRTAB
image.writeBigUInt64LE(BigInt(dynstrOff), str + 0x18);
image.writeBigUInt64LE(BigInt(256), str + 0x20);
image.writeUInt16LE(3, 0x3c); // e_shnum includes strtab
// dynstr: leading NUL then names
let strCursor = dynstrOff + 1;
const nameOffsets = symbols.map((symbol) => {
image.write(symbol.name, strCursor, "latin1");
const at = strCursor - dynstrOff;
strCursor += symbol.name.length + 1;
return at;
});
// dynsym entries
symbols.forEach((symbol, index) => {
const base = dynsymOff + index * 24;
image.writeUInt32LE(nameOffsets[index]!, base);
image.writeBigUInt64LE(BigInt(symbol.value), base + 8);
image.writeBigUInt64LE(BigInt(symbol.size), base + 16);
image[base + 4] = 0x10; // GLOBAL FUNC
});
return image;
};

const GALLERY_HASH = "65817c30a78bb44c3dc3771876b6010a";

const snapshotSection = (hash: string): Buffer =>
Buffer.concat([
Buffer.from([
0xf5, 0xf5, 0xdc, 0xdc, 0x49, 0x0d, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0,
0,
]),
Buffer.from(hash, "latin1"),
]);
const GALLERY_HASH = REFERENCE_HASH;

const imageWithSections = (): Buffer => {
const elf = buildElf64Image([
{ name: "_kDartVmSnapshotData", value: 0x1000, size: 52 },
{ name: "_kDartIsolateSnapshotData", value: 0x2000, size: 52 },
{ name: "_kDartVmSnapshotData", value: 0x400, size: 52 },
{ name: "_kDartIsolateSnapshotData", value: 0x800, size: 52 },
]);
const section = snapshotSection(GALLERY_HASH);
return Buffer.concat([
elf,
Buffer.alloc(0x1000 - elf.length),
Buffer.alloc(0x400 - elf.length),
section,
Buffer.alloc(0x2000 - 0x1000 - section.length),
Buffer.alloc(0x800 - 0x400 - section.length),
section,
]);
};
Expand All @@ -101,7 +35,7 @@ describe("readElfSymbol", () => {
const image = imageWithSections();
const isolateData = readElfSymbol(image, "_kDartIsolateSnapshotData");
if ("failure" in isolateData) throw new Error(isolateData.failure.reason);
expect(isolateData.symbol.offset).toBe(0x2000);
expect(isolateData.symbol.offset).toBe(0x800);
expect(isolateData.symbol.size).toBe(52);
const header = readSnapshotHeader(image, isolateData.symbol.offset);
expect(header.magicValid).toBe(true);
Expand Down
102 changes: 95 additions & 7 deletions src/flutter/DartElf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,30 +99,44 @@ export const readElfSymbol = (
},
};

const segments: { readonly vaddr: number; readonly offset: number }[] = [];
const segments: {
readonly vaddr: number;
readonly offset: number;
readonly filesz: number;
}[] = [];
for (let index = 0; index < e_phnum; index += 1) {
const base = e_phoff + index * e_phentsize;
const type = reader.u32(base);
if (type !== PT_LOAD) continue;
const vaddr = is64 ? reader.u64(base + 0x10) : reader.u32(base + 8);
const offset = is64 ? reader.u64(base + 0x08) : reader.u32(base + 4);
if (vaddr === null || offset === null)
const filesz = is64 ? reader.u64(base + 0x20) : reader.u32(base + 0x10);
if (vaddr === null || offset === null || filesz === null)
return {
failure: { reason: `PT_LOAD segment ${String(index)} is truncated` },
};
segments.push({ vaddr, offset });
segments.push({ vaddr, offset, filesz });
}
if (segments.length === 0)
return { failure: { reason: "ELF image has no PT_LOAD segments" } };
const toOffset = (vaddr: number): number | null => {
let best: { vaddr: number; offset: number } | null = null;
const toOffset = (vaddr: number, size: number): number | null => {
let best: {
vaddr: number;
offset: number;
filesz: number;
} | null = null;
for (const segment of segments)
if (
segment.vaddr <= vaddr &&
(best === null || segment.vaddr > best.vaddr)
)
best = segment;
return best === null ? null : best.offset + (vaddr - best.vaddr);
if (best === null) return null;
const delta = vaddr - best.vaddr;
// The full symbol must sit inside the file-backed portion of the
// segment; addresses in a gap or BSS are not snapshot bytes.
if (delta + size > best.filesz) return null;
return best.offset + delta;
};

for (let index = 0; index < e_shnum; index += 1) {
Expand Down Expand Up @@ -166,7 +180,7 @@ export const readElfSymbol = (
if (nameOffset === null || stValue === null || stSize === null) continue;
const name = reader.cString(stringOffset + nameOffset, 256);
if (name !== symbolName) continue;
const fileOffset = toOffset(stValue);
const fileOffset = toOffset(stValue, stSize);
if (fileOffset === null)
return {
failure: { reason: `symbol ${symbolName} has no loadable address` },
Expand Down Expand Up @@ -205,3 +219,77 @@ export const readSnapshotHeader = (
const kind = reader.u32(offset + 12);
return { magicValid: true, kind, headerLength };
};

export const buildElf64Image = (
symbols: ReadonlyArray<{ name: string; value: number; size: number }>,
): Buffer => {
const ELF_HEADER = 64;
const PHENT = 56;
const PHNUM = 1;
const SHENT = 64;
const phoff = ELF_HEADER;
const shoffAligned = phoff + PHENT * PHNUM;
// Place payload data after the three section headers so nothing overlaps.
const dynsymOff = shoffAligned + 3 * SHENT + 16;
const dynstrOff = dynsymOff + symbols.length * 24;
const image = Buffer.alloc(dynstrOff + 256);
// ELF header
image.writeUInt32LE(0x464c457f, 0);
image[4] = 2; // ELFCLASS64
image[5] = 1; // little-endian
image.writeUInt16LE(0x003e, 0x12); // e_machine x86_64
image.writeUInt32LE(1, 0x10); // ET_REL? keep type small
image.writeBigUInt64LE(BigInt(phoff), 0x20);
image.writeBigUInt64LE(BigInt(shoffAligned), 0x28);
image.writeUInt16LE(PHENT, 0x36);
image.writeUInt16LE(PHNUM, 0x38);
image.writeUInt16LE(SHENT, 0x3a);
image.writeUInt16LE(2, 0x3c); // e_shnum: null + dynsym
// Program header: one PT_LOAD mapping identity
const ph = phoff;
image.writeUInt32LE(1, ph); // PT_LOAD
image.writeBigUInt64LE(BigInt(0), ph + 8); // offset
image.writeBigUInt64LE(BigInt(0), ph + 0x10); // vaddr
image.writeBigUInt64LE(BigInt(0x10000), ph + 0x20); // p_filesz generously covers fixture symbols
// Section headers
const sh = shoffAligned;
// null section stays zero
const dyn = sh + SHENT;
image.writeUInt32LE(11, dyn + 4); // SHT_DYNSYM
image.writeBigUInt64LE(BigInt(dynsymOff), dyn + 0x18);
image.writeBigUInt64LE(BigInt(symbols.length * 24), dyn + 0x20);
image.writeUInt32LE(2, dyn + 0x28); // sh_link -> strtab section index
// dynstr section header
const str = dyn + SHENT;
image.writeUInt32LE(3, str + 4); // SHT_STRTAB
image.writeBigUInt64LE(BigInt(dynstrOff), str + 0x18);
image.writeBigUInt64LE(BigInt(256), str + 0x20);
image.writeUInt16LE(3, 0x3c); // e_shnum includes strtab
// dynstr: leading NUL then names
let strCursor = dynstrOff + 1;
const nameOffsets = symbols.map((symbol) => {
image.write(symbol.name, strCursor, "latin1");
const at = strCursor - dynstrOff;
strCursor += symbol.name.length + 1;
return at;
});
// dynsym entries
symbols.forEach((symbol, index) => {
const base = dynsymOff + index * 24;
image.writeUInt32LE(nameOffsets[index]!, base);
image.writeBigUInt64LE(BigInt(symbol.value), base + 8);
image.writeBigUInt64LE(BigInt(symbol.size), base + 16);
image[base + 4] = 0x10; // GLOBAL FUNC
});
return image;
};

/** A minimal Dart snapshot data section carrying a 32-hex hash. */
export const snapshotSection = (hash: string): Buffer =>
Buffer.concat([
Buffer.from([
0xf5, 0xf5, 0xdc, 0xdc, 0x49, 0x0d, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0,
0,
]),
Buffer.from(hash, "latin1"),
]);
Loading
Loading