diff --git a/src/native/windows/WindowsShortcutParser.test.ts b/src/native/windows/WindowsShortcutParser.test.ts index 29847f4402..971a1349b7 100644 --- a/src/native/windows/WindowsShortcutParser.test.ts +++ b/src/native/windows/WindowsShortcutParser.test.ts @@ -406,6 +406,26 @@ it("treats any TerminalSize below 4 as the ExtraData terminal", async () => { } }); +it("reports bytes appended after the ExtraData TerminalBlock", async () => { + const link = powershellHiddenIconSpoofShortcut(); + const report = await parse( + Buffer.concat([link, Buffer.from("PK\x03\x04appended", "latin1")]), + ); + expect(report.extra_data.terminal_offset).toBe(link.length - 4); + expect(report.coverage).toMatchObject({ + status: "partial", + failing_offset: link.length, + }); + expect(report.issues).toEqual([ + { + code: "malformed_structure", + offset: link.length, + message: + "12 byte(s) follow the ExtraData TerminalBlock and are not part of the Shell Link", + }, + ]); +}); + it("derives target facts from a stored environment target alone", async () => { const report = await parse( windowsShortcutBytes({ diff --git a/src/native/windows/WindowsShortcutParser.ts b/src/native/windows/WindowsShortcutParser.ts index 1b487b4fcc..bb75971fb0 100644 --- a/src/native/windows/WindowsShortcutParser.ts +++ b/src/native/windows/WindowsShortcutParser.ts @@ -1229,6 +1229,15 @@ export const parseWindowsShortcut = async ( const extraData = !walk.stopped ? await parseExtraData(bytes, walk, input.max_extra_data_blocks, signal) : { blocks: [], terminal_offset: null }; + // The TerminalBlock ends the Shell Link. Appended bytes are not examined, so + // the file is not completely covered; payloads are often hidden there. + if (extraData.terminal_offset !== null && walk.offset < bytes.length) + note( + walk, + "malformed_structure", + walk.offset, + `${String(bytes.length - walk.offset)} byte(s) follow the ExtraData TerminalBlock and are not part of the Shell Link`, + ); const signatures = new Set(extraData.blocks.map((block) => block.signature)); const unseenBlocks = EXPECTED_EXTRA_DATA_BLOCKS.filter( ({ flag, signature }) => (flags & flag) !== 0 && !signatures.has(signature),