#13945

[Bug] inspect_windows_shortcut falls back to IDList decoy extension when declared LinkInfo or RELATIVE_PATH is unread

OpenPlastic-timeopened 3d ago

Before submitting

  • I searched the open and closed issues for a related report.
  • I removed credentials, tokens, private paths, and sensitive target data.

Area

Native analysis or decompilation

Observed behavior

In inspect_windows_shortcut, targetPaths() orders target candidates by precedence: LinkInfo, RELATIVE_PATH, LinkTargetIDList, then EnvironmentVariableDataBlock. When a higher-precedence target cannot be read, observationsOf() uses walk.pathUncertainty to keep target_extension as null (and icon_location_differs_from_target from claiming true) instead of falling back to a lower-precedence path (as established in #12612 and #13653).

Three unread high-precedence cases do not set walk.pathUncertainty, so observationsOf() falls through to a lower-precedence LinkTargetIDList file entry (for example decoy.pdf) and reports a misleading target_extension: ".pdf":

  1. HasLinkInfo is set (0x00000002), and LinkInfo could not be read (linkInfo === null): parseLinkInfo() returns null when fewer than 8 bytes remain, when LinkInfoSize < 0x1C, or when LinkInfoSize overruns the file (or when walk.stopped was already set). walk.pathUncertainty stays all false.
  2. LinkInfo declares Unicode offsets (LinkInfoHeaderSize >= 0x24), but LinkInfoSize < 0x24: parseLinkInfo() emits malformed_structure and computes hasUnicodeOffsets = false, leaving localUnicodeOffset = 0 and suffixUnicodeOffset = 0. Unlike parseNetwork() (which sets walk.pathUncertainty.network ||= declaresUnicode && !unicode), parseLinkInfo() does not record declaresUnicodeOffsets && !hasUnicodeOffsets as uncertain.
  3. HasRelativePath is set (0x00000008), and RELATIVE_PATH could not be read (stringData.relative_path === null): when RELATIVE_PATH (or a preceding NAME_STRING field) is truncated, stringData.relative_path stays null without marking target path uncertainty.

Reproduction

  1. Construct a Shell Link (truncated-linkinfo.lnk, 108 bytes) with LinkFlags = HasLinkTargetIDList | HasLinkInfo | IsUnicode, an IDList containing a single file_entry named decoy.pdf, and a truncated 4-byte LinkInfo block after the IDList.
  2. Run:
    rea inspect-windows-shortcut <path>/truncated-linkinfo.lnk --json
  3. Observe exit code 0, coverage.status: "partial", link_info: null, issues: [{"code": "truncated", "offset": 104, "message": "LinkInfo is truncated"}], and observations reporting {"kind": "target_extension", "evidence_kind": "derived", "extension": ".pdf"} even though the declared LinkInfo target was never read.

The same fallback to .pdf reproduces on origin/main (a569ec558) when LinkInfoHeaderSize = 0x24 with LinkInfoSize = 0x1C, or when HasRelativePath is set and RELATIVE_PATH (or preceding NAME_STRING) is truncated.

Expected behavior

Under the same walk.pathUncertainty rule already used for unreadable LinkInfo string offsets, truncated CommonNetworkRelativeLink Unicode headers, and unreadable EnvironmentVariableDataBlock entries, any declared high-precedence target path (LinkInfo, its declared Unicode header offsets, or RELATIVE_PATH) that cannot be read must keep target_extension as null rather than falling through to a lower-precedence IDList entry.

Impact and scope

  • Affects inspect_windows_shortcut (CLI and MCP) on truncated or malformed .lnk files that pair an IDList decoy filename with an unread LinkInfo, truncated Unicode LinkInfo header, or unread RELATIVE_PATH.
  • Reports a concrete target_extension from a lower-precedence field when the declared higher-precedence target is unknown.

REA version

6.10.1 (origin/main a569ec558; compiled CLI reproduced on ef21d8f40, parser tests reproduced on a569ec558)

Runtime and platform

Node.js v24.22.1; Windows x64

Target and artifact context

Synthetic Windows Shell Link (.lnk) fixtures (108 bytes for truncated LinkInfo, plus truncated Unicode LinkInfo header and truncated RELATIVE_PATH fixtures) with IDList file entry decoy.pdf

Interface

CLI

Earliest failure stage

Native analysis or reconstruction

Relevant output or evidence

Observed observations before fix on truncated-linkinfo.lnk (exit code 0):

{
  "kind": "target_extension",
  "evidence_kind": "derived",
  "extension": ".pdf"
}

Source references (src/native/windows/WindowsShortcutParser.ts on a569ec558):

  • parseLinkInfo (:912-997): checks declaresUnicodeOffsets && size >= LINK_INFO_UNICODE_HEADER_BYTES without setting walk.pathUncertainty when declaresUnicodeOffsets && !hasUnicodeOffsets, unlike parseNetwork (:878-885).
  • parseWindowsShortcut (:1408-1435): does not set walk.pathUncertainty when (flags & 0x00000002) !== 0 && linkInfo === null or when (flags & 0x00000008) !== 0 && stringData.relative_path === null.
  • observationsOf (:526-561): derives target_extension from targets[0]?.extension ?? null whenever targetPathUnknown is false.

Typed outcome or recovery expected

coverage.status: "partial" with the existing truncated / block_size_overrun / malformed_structure issue, and observations reporting {"kind": "target_extension", "evidence_kind": "derived", "extension": null}.

Analysis or suspected cause

TargetPathUncertainty tracked unreadable inner LinkInfo offsets and unreadable EnvironmentVariableDataBlock entries, but omitted section-level unread LinkInfo, truncated LinkInfo Unicode header offsets, and unread RELATIVE_PATH.

Additional context

Related prior fixes establishing the walk.pathUncertainty invariant: #12612 and #13653.

Activity

0

No activity yet.