diff --git a/src/artifacts/nodeSea/NodeSeaLocation.ts b/src/artifacts/nodeSea/NodeSeaLocation.ts index 1bb997b050f..8922cded24c 100644 --- a/src/artifacts/nodeSea/NodeSeaLocation.ts +++ b/src/artifacts/nodeSea/NodeSeaLocation.ts @@ -515,6 +515,30 @@ const locateElfNotes = async ( little, frames: Math.floor(carrier.fileSize / ELF_NOTE_HEADER_BYTES), }; + const scanNote = async ( + offset: bigint, + length: bigint, + alignment: bigint, + ): Promise => { + const note = { + offset: + offset <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(offset) : undefined, + length: + length <= BigInt(Number.MAX_SAFE_INTEGER) ? Number(length) : undefined, + align: + alignment <= BigInt(Number.MAX_SAFE_INTEGER) + ? Number(alignment) + : undefined, + }; + const scanned = await scanElfNoteTable( + carrier, + note, + scan, + found.length > 0, + ); + if (scanned === undefined) opaque ??= NODE_SEA_ELF_TABLE_TRUNCATED; + else for (const range of scanned) found.push(range); + }; const programs = await readElfTables(carrier, { offset: phoff, count: phnum, @@ -533,28 +557,7 @@ const locateElfNotes = async ( if (!parsedProgram.ok) continue; const program = parsedProgram.value; if (program.type !== PT_NOTE) continue; - const note = { - offset: - program.offset <= BigInt(Number.MAX_SAFE_INTEGER) - ? Number(program.offset) - : undefined, - length: - program.fileSize <= BigInt(Number.MAX_SAFE_INTEGER) - ? Number(program.fileSize) - : undefined, - align: - program.alignment <= BigInt(Number.MAX_SAFE_INTEGER) - ? Number(program.alignment) - : undefined, - }; - const scanned = await scanElfNoteTable( - carrier, - note, - scan, - found.length > 0, - ); - if (scanned === undefined) opaque ??= NODE_SEA_ELF_TABLE_TRUNCATED; - else for (const range of scanned) found.push(range); + await scanNote(program.offset, program.fileSize, program.alignment); } // The runtime locates the blob through PT_NOTE segments. Injectors can // leave stale or misaligned SHT_NOTE entries, so section notes are only a @@ -589,28 +592,7 @@ const locateElfNotes = async ( "Compressed ELF note sections cannot establish raw Node SEA blob offsets"; continue; } - const note = { - offset: - section.offset <= BigInt(Number.MAX_SAFE_INTEGER) - ? Number(section.offset) - : undefined, - length: - section.size <= BigInt(Number.MAX_SAFE_INTEGER) - ? Number(section.size) - : undefined, - align: - section.alignment <= BigInt(Number.MAX_SAFE_INTEGER) - ? Number(section.alignment) - : undefined, - }; - const scanned = await scanElfNoteTable( - carrier, - note, - scan, - found.length > 0, - ); - if (scanned === undefined) opaque ??= NODE_SEA_ELF_TABLE_TRUNCATED; - else for (const range of scanned) found.push(range); + await scanNote(section.offset, section.size, section.alignment); } if (found.length > 0 && opaque !== undefined) throw formatFailure(opaque); return found;