# HG changeset patch # User Benjamin Golinvaux # Date 1565006274 -7200 # Node ID ce29644acd190b52af3438e5e9d7089c590fb818 # Parent 5e9fae2faff24ba124075ffd33e1b28efc10c50e Prevented unaligned memcpy when using Web Assembly diff -r 5e9fae2faff2 -r ce29644acd19 Core/Images/PamReader.cpp --- a/Core/Images/PamReader.cpp Sat Aug 03 10:56:13 2019 +0200 +++ b/Core/Images/PamReader.cpp Mon Aug 05 13:57:54 2019 +0200 @@ -208,7 +208,7 @@ { throw OrthancException(ErrorCode_NotImplemented); } - + if (Toolbox::DetectEndianness() == Endianness_Little && bytesPerChannel == 2) { @@ -218,12 +218,35 @@ for (unsigned int w = 0; w < GetWidth(); ++w, ++pixel) { +#if ORTHANC_ENABLE_WASM == 1 + /* + + crash (2019-08-05): + + Uncaught abort(alignment fault) at Error + at jsStackTrace + at stackTrace + at abort + at alignfault + at SAFE_HEAP_LOAD_i32_2_2 (wasm-function[251132]:39) + at __ZN7Orthanc9PamReader12ParseContentEv (wasm-function[11457]:8088) + + Web Assenmbly IS LITTLE ENDIAN! + + Perhaps in htobe16 ? + */ + uint8_t* srcdst = reinterpret_cast(pixel); + uint8_t tmp = srcdst[0]; + srcdst[0] = srcdst[1]; + srcdst[1] = tmp; +#else // memcpy() is necessary to avoid segmentation fault if the // "pixel" pointer is not 16-bit aligned (which is the case // if "offset" is an odd number). Check out issue #99: // https://bitbucket.org/sjodogne/orthanc/issues/99 uint16_t v = htobe16(*pixel); memcpy(pixel, &v, sizeof(v)); +#endif } } }