Artifacts Associated With Ticket 992f94d847
Ticket change [23ed893984] (rid 196783) by chrstphrchvz on 2021-12-11 00:17:39:
- assignee initialized to: "nobody"
- closer initialized to: "nobody"
- cmimetype initialized to: "text/x-fossil-wiki"
- comment initialized to:
In <tt>TclMacOSXGetFileAttribute()</tt> and <tt>TclMacOSXSetFileAttribute()</tt> (macosx/tclMacOSXFCmd.c), <tt>fileinfobuf finfo</tt> only has 4-byte alignment. When <tt>finfo.data</tt> is not 8-byte aligned, casting <tt>&finfo.data</tt> to <tt>(*off_t)</tt> is undefined behavior, and UBSan (<tt>-fsanitize=alignment</tt>) will complain when <tt>off_t *rsrcForkSize</tt> is dereferenced. Output for macOSXFCmd.test (with macOSXFCmd-2.7 reenabled, which I observe passes on APFS): <pre> $ ./tcltest ../tests/macOSXFCmd.test <span style="font-weight:bold">tcl/macosx/tclMacOSXFCmd.c:199:39: <span style="color:red">runtime error:</span> load of misaligned address 0x7ff7bf70a1d4 for type 'off_t' (aka 'long long'), which requires 8 byte alignment</span> <span style="font-weight:bold">0x7ff7bf70a1d4: note:</span> pointer points here 0c 00 00 00 00 00 00 00 00 00 00 00 0f 00 00 00 10 6d fe 01 01 00 00 00 80 36 5b 00 00 60 00 00 <span style="color:green">^</span> SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tcl/macosx/tclMacOSXFCmd.c:199:39 in <span style="font-weight:bold">tcl/macosx/tclMacOSXFCmd.c:327:25: <span style="color:red">runtime error:</span> load of misaligned address 0x7ff7bf70a0f4 for type 'off_t' (aka 'long long'), which requires 8 byte alignment</span> <span style="font-weight:bold">0x7ff7bf70a0f4: note:</span> pointer points here 0c 00 00 00 03 00 00 00 00 00 00 00 00 60 00 00 00 42 ca 02 00 60 00 00 68 42 ca 02 00 60 00 00 <span style="color:green">^</span> SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tcl/macosx/tclMacOSXFCmd.c:327:25 in macOSXFCmd.test: Total 14 Passed 14 Skipped 0 Failed 0 </pre> The attached patch uses <tt>memcpy()</tt> to avoid creating or dereferencing misaligned pointers, although there may be a better approach. - foundin initialized to: "8.6.12"
- is_private initialized to: "0"
- login: "chrstphrchvz"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- severity initialized to: "Minor"
- status initialized to: "Open"
- submitter initialized to: "chrstphrchvz"
- subsystem initialized to: "37. File System"
- title initialized to:
avoid misaligned pointers in macOS file attribute functions
- type initialized to: "Patch"
Add attachment "992f94d847.diff" [e8aab0c309] (rid 196784) by chrstphrchvz on 2021-12-11 00:21:32.
Ticket change [cd24f5c690] (rid 198190) by chrstphrchvz on 2022-02-16 23:17:24:
- login: "chrstphrchvz"
- mimetype: "text/plain"
Ticket change [639f80db0d] (rid 243957) by jan.nijtmans on 2025-08-12 10:07:09:
- icomment:
Another possible approach: just making sure that "data" is 8-byte allighed: [d53a634a93ec36ca] How do you think about that?
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- icomment:
Ticket change [b4b42288a3] (rid 244010) by chrstphrchvz on 2025-08-12 17:55:50:
- icomment: "That also seems to work, thanks"
- login: "chrstphrchvz"
- mimetype: "text/x-fossil-wiki"
Ticket change [dcf23c1260] (rid 244019) by jan.nijtmans on 2025-08-12 22:11:47:
- assignee changed to: "jan.nijtmans"
- closedate changed to: "2460900.42485911"
- closer changed to: "jan.nijtmans"
- icomment: "Fixed [6badbfd55e096dac|here]"
- login: "jan.nijtmans"
- mimetype: "text/x-fossil-wiki"
- resolution changed to: "Fixed"
- status changed to: "Closed"