mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 13:45:30 +00:00
fix(windows): floor LinkInfo string offsets at the mandatory header (#12403)
A LinkInfoHeaderSize below 0x1C no longer lowers the string-offset floor. Reserved 0x1D..0x23 headers still end at their declared size, so ANSI fields after that header stay readable. Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: morluto <morluto@users.noreply.github.com>
This commit is contained in:
3 files changed
+82
-5
No files matched your search
@@ -108,7 +108,9 @@ partial success. Truncation after a valid header, ExtraData size overruns, and
|
||||
odd Unicode lengths return partial coverage with `coverage.failing_offset`.
|
||||
A LinkInfo, VolumeID, or network-name string offset that points inside its
|
||||
structure header or outside its structure is reported at the offset field itself,
|
||||
so every issue offset lies inside the file.
|
||||
so every issue offset lies inside the file. A `LinkInfoHeaderSize` below 0x1C
|
||||
does not shrink the mandatory 28-byte header, so an offset in that header is
|
||||
still reported at the offset field and the path stays unreadable.
|
||||
Coverage is never `complete` when issues are present.
|
||||
A PropertyStoreDataBlock shorter than 12 bytes or a ShimDataBlock shorter than
|
||||
136 bytes makes coverage partial. The report retains the block's signature,
|
||||
|
||||
@@ -854,6 +854,77 @@ it.each([
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
{ field: 16, key: "local_base_path" },
|
||||
{ field: 24, key: "common_path_suffix" },
|
||||
] as const)(
|
||||
"treats a $key inside the mandatory header as unreadable when HeaderSize is below 0x1C",
|
||||
async ({ field, key }) => {
|
||||
const bytes = windowsShortcutBytes({
|
||||
idList: null,
|
||||
linkInfo: { localBasePath: "C:\\Apps\\safe.exe", commonPathSuffix: "" },
|
||||
iconLocation: "C:\\Apps\\other.exe",
|
||||
extraData: [],
|
||||
});
|
||||
const link = 76;
|
||||
// HeaderSize 0x10 is below the mandatory 0x1C, and 0x14 still sits in that
|
||||
// header. The bytes there would otherwise decode as the full path "C:\\x".
|
||||
bytes.writeUInt32LE(0x10, link + 4);
|
||||
bytes.writeUInt32LE(0x14, link + field);
|
||||
bytes.write("C:\\x", link + 0x14, "latin1");
|
||||
if (field !== 24) bytes.writeUInt32LE(0, link + 24);
|
||||
const report = await parse(bytes);
|
||||
expect(report.link_info?.header_size).toBe(0x10);
|
||||
expect(report.link_info?.[key]).toBeNull();
|
||||
expect(report.coverage.status).toBe("partial");
|
||||
expect(report.issues).toContainEqual(
|
||||
expect.objectContaining({
|
||||
code: "malformed_structure",
|
||||
offset: link + field,
|
||||
}),
|
||||
);
|
||||
expect(
|
||||
report.observations.find(
|
||||
({ kind }) => kind === "icon_location_differs_from_target",
|
||||
),
|
||||
).toMatchObject({ value: null });
|
||||
expect(
|
||||
report.observations.find(({ kind }) => kind === "target_extension"),
|
||||
).toMatchObject({ extension: null });
|
||||
},
|
||||
);
|
||||
|
||||
it("reads a LinkInfo path that starts at the mandatory header when HeaderSize is below 0x1C", async () => {
|
||||
const bytes = windowsShortcutBytes({
|
||||
idList: null,
|
||||
linkInfo: { localBasePath: "C:\\Apps\\safe.exe", commonPathSuffix: "" },
|
||||
iconLocation: "C:\\ok.exe",
|
||||
extraData: [],
|
||||
});
|
||||
const link = 76;
|
||||
bytes.writeUInt32LE(0x10, link + 4);
|
||||
bytes.writeUInt32LE(0, link + 12);
|
||||
bytes.writeUInt32LE(0x1c, link + 16);
|
||||
bytes.writeUInt32LE(0, link + 24);
|
||||
bytes.write("C:\\ok.exe\0", link + 0x1c, "latin1");
|
||||
const report = await parse(bytes);
|
||||
expect(report.link_info?.local_base_path).toBe("C:\\ok.exe");
|
||||
expect(report.issues).not.toContainEqual(
|
||||
expect.objectContaining({
|
||||
code: "malformed_structure",
|
||||
offset: link + 16,
|
||||
}),
|
||||
);
|
||||
expect(
|
||||
report.observations.find(
|
||||
({ kind }) => kind === "icon_location_differs_from_target",
|
||||
),
|
||||
).toMatchObject({ value: false });
|
||||
expect(
|
||||
report.observations.find(({ kind }) => kind === "target_extension"),
|
||||
).toMatchObject({ extension: ".exe" });
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
name: "ANSI volume label",
|
||||
|
||||
@@ -921,6 +921,10 @@ const parseLinkInfo = (
|
||||
declaresUnicodeOffsets && size >= LINK_INFO_UNICODE_HEADER_BYTES;
|
||||
const localUnicodeOffset = hasUnicodeOffsets ? view.readUInt32LE(28) : 0;
|
||||
const suffixUnicodeOffset = hasUnicodeOffsets ? view.readUInt32LE(32) : 0;
|
||||
// A declared HeaderSize below the mandatory 0x1C must not expose those
|
||||
// fields as string data. Larger declared headers, including reserved
|
||||
// 0x1D..0x23 sizes, keep their own end as the floor.
|
||||
const stringOffset = Math.max(headerSize, LINK_INFO_FIXED_HEADER_BYTES);
|
||||
const info: NonNullable<WindowsShortcut["link_info"]> = {
|
||||
location: { offset: walk.offset, bytes: size },
|
||||
header_size: headerSize,
|
||||
@@ -935,7 +939,7 @@ const parseLinkInfo = (
|
||||
: null,
|
||||
local_base_path:
|
||||
(flags & 0x1) !== 0
|
||||
? readAnsiAt(view, walk.offset, localOffset, 16, walk, headerSize)
|
||||
? readAnsiAt(view, walk.offset, localOffset, 16, walk, stringOffset)
|
||||
: null,
|
||||
local_base_path_unicode:
|
||||
(flags & 0x1) !== 0
|
||||
@@ -945,7 +949,7 @@ const parseLinkInfo = (
|
||||
localUnicodeOffset,
|
||||
28,
|
||||
walk,
|
||||
headerSize,
|
||||
stringOffset,
|
||||
)
|
||||
: null,
|
||||
common_network_relative_link:
|
||||
@@ -958,7 +962,7 @@ const parseLinkInfo = (
|
||||
suffixOffset,
|
||||
24,
|
||||
walk,
|
||||
headerSize,
|
||||
stringOffset,
|
||||
),
|
||||
common_path_suffix_unicode: readUtf16At(
|
||||
view,
|
||||
@@ -966,7 +970,7 @@ const parseLinkInfo = (
|
||||
suffixUnicodeOffset,
|
||||
32,
|
||||
walk,
|
||||
headerSize,
|
||||
stringOffset,
|
||||
),
|
||||
};
|
||||
walk.pathUncertainty.local ||=
|
||||
|
||||
Reference in new issue
Block a user