Repository: GuillaumeGomez/sysinfo (language: rust)

Issue:
Misaligned read under wine reintroduced
Same cause as #1001 and #1014. Reintroduced in https://github.com/GuillaumeGomez/sysinfo/commit/fcf73c8f1e11538ad4567827e72fa00972fa423e

https://github.com/GuillaumeGomez/sysinfo/blob/bc08ea26ffb73fdba7d9f7226f05cf341311ab65/src/windows/system.rs#L283-L290

The filter_callback needs moved after the read_unaligned and needs to use that value instead of dereferencing the potentially unaligned pointer.

Causes this error:

```
thread 'os::win::sysinfo_refresh_works' panicked at /home/lun/.cargo/registry/src/index.crates.io-6f17d22bba15001f/sysinfo-0.30.3/src/windows/system.rs:283:40:
misaligned pointer dereference: address must be a multiple of 0x8 but is 0x1b0684a
```


Discussion / hints:

Fix patch:
diff --git a/src/windows/system.rs b/src/windows/system.rs
index b09638e0f..b621e7167 100644
--- a/src/windows/system.rs
+++ b/src/windows/system.rs
@@ -280,15 +280,15 @@ impl SystemInner {
                     .offset(process_information_offset)
                     as *const SYSTEM_PROCESS_INFORMATION;
 
-                if filter_callback(Pid((*p).UniqueProcessId as _), filter) {
-                    process_ids.push(Wrap(p));
-                }
-
                 // read_unaligned is necessary to avoid
                 // misaligned pointer dereference: address must be a multiple of 0x8 but is 0x...
                 // under x86_64 wine (and possibly other systems)
                 let pi = ptr::read_unaligned(p);
 
+                if filter_callback(Pid(pi.UniqueProcessId as _), filter) {
+                    process_ids.push(Wrap(p));
+                }
+
                 if pi.NextEntryOffset == 0 {
                     break;
                 }


Test patch: