From ce9635bcb410416dc7960abf75e003f727c9f261 Mon Sep 17 00:00:00 2001 From: RRFZ <247457381+Plastic-time@users.noreply.github.com> Date: Wed, 18 Nov 2026 09:23:48 -0500 Subject: [PATCH] fix(windows): report bytes appended after a Shell Link TerminalBlock (#11745) The ExtraData TerminalBlock ends a Shell Link, but bytes after it were never examined or mentioned, and coverage stayed complete. Appending a payload to a shortcut is a common way to hide one. Record a malformed_structure issue at the first appended byte, with the byte count, so coverage becomes partial. Shortcuts that end at the TerminalBlock are unchanged. --- .../windows/WindowsShortcutParser.test.ts | 20 +++++++++++++++++++ src/native/windows/WindowsShortcutParser.ts | 9 +++++++++ 2 files changed, 29 insertions(+) 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),