libmodplug icon indicating copy to clipboard operation
libmodplug copied to clipboard

Avoid unaligned memory access in the PSM loader

Open ccawley2011 opened this issue 3 years ago • 3 comments
trafficstars

This can cause crashes on older ARM processors, as well as on newer ones with alignment exceptions enabled.

ccawley2011 avatar Apr 07 '22 22:04 ccawley2011

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.

sezero avatar Apr 09 '22 22:04 sezero

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.

AliceLR avatar Apr 09 '22 23:04 AliceLR

@ccawley2011, thank you immensly! It helped almost fully to eliminate PSM_Load errors on ARM32 device!.

Apaczer avatar Jan 24 '23 20:01 Apaczer