GTkorvo / ffs

FFS is a middleware library for data communication, including representation, processing and marshaling that preserves the performance of traditional approaches while relaxing the requirement of a priori knowledge and providing complex run-time flexibility. FFS provides for highly efficient binary data communication, XML-like examination of unknown data, and both third party and in situ data processing via dynamic code generation. All of these capabilities are fully dynamic at run-time, without requiring a priori agreements or knowledge of the exact form of the data being communicated or analyzed.
Other
0 stars 4 forks source link

Undefined behavior in FFS unit tests ran through ADIOS2 #16

Open NAThompson opened 4 years ago

NAThompson commented 4 years ago

If we compile ADIOS2 with

cmake -DCMAKE_CXX_COMPILER="clang++" -DCMAKE_C_COMPILER="clang" \
      -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS} -fsanitize=undefined -fsanitize=address -fno-sanitize=function" \
      -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -fsanitize=address -fsanitize=undefined -fno-sanitize=vptr -fno-sanitize=function" \
      -DADIOS2_USE_MPI=OFF -DCMAKE_BUILD_TYPE=Debug \
      -DCMAKE_EXE_LINKER_FLAGS="${CMAKE_EXE_LINKER_FLAGS} -fsanitize=undefined -fsanitize=address -fno-sanitize=vptr -fno-sanitize=function" -DCMAKE_SHARED_LINKER_FLAGS="${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address -fsanitize=undefined -fno-sanitize=vptr -fno-sanitize=function"  ../

then run the unit tests, we have the following errors:

336: /home/4nt/ADIOS2/thirdparty/ffs/ffs/fm/fm_formats.c:873:13: runtime error: member access within null pointer of type 'struct (anonymous struct at /home/4nt/ADIOS2/thirdparty/ffs/ffs/fm/fm_formats.c:831:9)'
336: /home/4nt/ADIOS2/thirdparty/ffs/ffs/fm/fm_formats.c:890:10: runtime error: member access within null pointer of type 'struct (anonymous struct at /home/4nt/ADIOS2/thirdparty/ffs/ffs/fm/fm_formats.c:846:9)'
336: /home/4nt/ADIOS2/thirdparty/ffs/ffs/fm/fm_formats.c:889:14: runtime error: member access within null pointer of type 'struct (anonymous struct at /home/4nt/ADIOS2/thirdparty/ffs/ffs/fm/fm_formats.c:841:9)'
eisenhauer commented 4 years ago

It appears that sanitize=address doesn't like the traditional (pre-ANSI) way of determining the offset of a field in a structure. Knowing where fields are is a fundamental thing to FFS, so if this was ever broken absolutely nothing would work. That hasn't happened on anywhere yet, but I understand that this is "theoretically undefined" behavior. So, maybe it's time to switch to offsetof(). Submit a PR?