Boost.Endian is the library here and this code is safe because the big_uint32_t type has an alignment requirement of 1 byte.
This is why ubsan is silent and not even injecting a check in to the compiled code.
You can check the alignment constraints with static_assert (something else you can't do in standard C): https://gcc.godbolt.org/z/KTcf9ax6r
Re:The Byte Order Fiasco
by kevin_thibedeau on Saturday May 08, 2021 @11:27AM
(#27087988)
C11 has static_assert: https://gcc.godbolt.org/z/E3bGc95o3
Is also has _Generic() so you can roll up a family of endianness conversion functions and safely change types without blowing up somewhere else with a hardcoded conversion routine.
If you need to change byte orders, you should use library to achieve that.