fix(flutter): reject ambiguous ELF mappings and bound note reads (#2334)
* fix(flutter): reject ambiguous mappings and bound ELF notes Resolve PT_LOAD interpretations once for symbols and dynamic tables, including partial overlaps. Preserve equivalent mappings and leave conflicting or invalid alternate definitions unresolved. Bound distinct nonempty ELF note ranges before retention and reads, deduplicate shared ranges, preserve observed build-ID candidates and report partial coverage on exhaustion. Correct shared verifier workspace ownership and structured Windows path assertions. Addresses the two post-merge review findings on PR #1582. Validation: 147 focused cases across Linux, macOS Sonoma 14.8.9 and non-administrator Windows 11 build 26300.9457; real Gallery CLI/MCP checks on all three hosts; six compiler-produced ELF32/ELF64 hash-layout cases; static, docs, discovery and duplication checks. Full string-pool projections remain explicitly bounded. * test(flutter): parse complete facts through named result schemas --------- Co-authored-by: me <me@medz.org> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
co-authored by
me
morluto
parent
fd65e278be
commit
e3a012d6c9
@@ -8,6 +8,9 @@ import {
|
||||
|
||||
const MAX_METADATA_BYTES = 8 * 1024 * 1024;
|
||||
const MAX_BUILD_IDS = 64;
|
||||
// Range bookkeeping and separate positional reads need a budget independent
|
||||
// of payload bytes: tiny/overlapping declarations can otherwise fan out I/O.
|
||||
const MAX_NOTE_RANGES = 1024;
|
||||
|
||||
export interface ElfBuildIds {
|
||||
readonly candidates: readonly string[];
|
||||
@@ -21,9 +24,10 @@ export const readElfBuildIds = async (
|
||||
signal: AbortSignal | undefined,
|
||||
): Promise<ElfBuildIds> => {
|
||||
const candidates = new Set<string>();
|
||||
const failures: ElfParseFailure[] = [];
|
||||
const failure = (reason: string): ElfBuildIds => ({
|
||||
candidates: [...candidates],
|
||||
failures: [{ reason }],
|
||||
failures: [...failures, { reason }],
|
||||
});
|
||||
let examined = 0;
|
||||
const read = async (offset: number, size: number): Promise<Buffer | null> => {
|
||||
@@ -59,7 +63,7 @@ export const readElfBuildIds = async (
|
||||
if (parsed.failure !== undefined) return failure(parsed.failure.reason);
|
||||
const h = parsed.header;
|
||||
const ranges = new Map<string, { offset: number; size: number }>();
|
||||
for (const table of [
|
||||
tables: for (const table of [
|
||||
{
|
||||
offset: h.e_phoff,
|
||||
width: h.e_phentsize,
|
||||
@@ -105,7 +109,17 @@ export const readElfBuildIds = async (
|
||||
size > totalBytes - offset
|
||||
)
|
||||
return failure("ELF note range is not file-backed");
|
||||
ranges.set(`${offset}:${size}`, { offset, size });
|
||||
if (size === 0) continue;
|
||||
const key = `${offset}:${size}`;
|
||||
if (ranges.has(key)) continue;
|
||||
if (ranges.size === MAX_NOTE_RANGES) {
|
||||
failures.push({
|
||||
reason:
|
||||
"ELF notes exceed the 1024-range note-range inventory/read budget",
|
||||
});
|
||||
break tables;
|
||||
}
|
||||
ranges.set(key, { offset, size });
|
||||
}
|
||||
}
|
||||
const align4 = (value: number): number => Math.ceil(value / 4) * 4;
|
||||
@@ -154,5 +168,5 @@ export const readElfBuildIds = async (
|
||||
}
|
||||
}
|
||||
signal?.throwIfAborted();
|
||||
return { candidates: [...candidates], failures: [] };
|
||||
return { candidates: [...candidates], failures };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user