Skip to content

Do not substitute current time for unparseable FILETIME. Rean IconIndex as signed - #49

Open
k1mb3rlyie wants to merge 1 commit into
strayge:masterfrom
k1mb3rlyie:fix-filetime-and-iconindex
Open

k1mb3rlyie wants to merge 1 commit into
strayge:masterfrom
k1mb3rlyie:fix-filetime-and-iconindex

Conversation

@k1mb3rlyie

Copy link
Copy Markdown

Pull request: pylnk3

Two correctness fixes, addressing issues #47 and [#48 (https://github.com//issues/48).

1. convert_time_to_unix returned datetime.now() for out-of-range FILETIME

Issue : When a FILETIME cannot be represented as a datetime, the function returned the current system time. Not limited to corrupt files datetime.fromtimestamp also rejects negative timestamps on Windows, and FILETIME 0 — the standard representation of an unset timestamp maps to unix time -11644473600. So on Windows, any shortcut with unset timestamps reported the current time. Two of the project's own test fixtures, send_to_fax.lnk and uwp_calc.lnk, have all three timestamps set to zero and are affected

Status : This change catches (OSError, ValueError, OverflowError) and returns None, so the failure is visible to the caller on every platform. It also makes the function deterministic — previously, parsing the same bytes twice a minute apart on Windows returned two values a minute apart.

2. IconIndex read as unsigned

Issue : IconIndex at header offset 0x38 is a signed 32-bit integer per
MS-SHLLINK §2.1.
It was being read with <I, so -1 came back as 4294967295 and -7 as 4294967289.
-1 is not unusual, as it appears in shortcuts using resource-relative icon references.

Status : Adds read_signed_int / write_signed_int alongside the existing helpers and uses them for this field only. The write side matters too: write_int uses <I and raises struct.error on a negative value, so a link with a negative icon index could be read (incorrectly) but not saved at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant