mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 05:02:40 +00:00
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.
This commit is contained in:
2 files changed
+29
No files matched your search
@@ -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({
|
||||
|
||||
@@ -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),
|
||||
|
||||
Reference in new issue
Block a user