libmodplug
libmodplug copied to clipboard
Avoid unaligned memory access in the PSM loader
This can cause crashes on older ARM processors, as well as on newer ones with alignment exceptions enabled.
There are many other places in code that does foo = *(DWORD *)src; (or
foo = *(WORD *)src) which are potentially unaligned accesses. I ended
up with this yet-incomplete and to-be-verified patch: patch.txt.
ReadSample() of sndfile.c possibly needs similar love & care, not sure. And several of the loaders would need revising for endian and alignment safety.
Does #pragma pack(1) on the affected structs not already fix this?
edit: seems whether or not this forces the compiler to emit unaligned access safe code might be target-dependent.
@ccawley2011, thank you immensly! It helped almost fully to eliminate PSM_Load errors on ARM32 device!.