Page MenuHome

Fix undefined behavior: Don't shift by illegal value
ClosedPublic

Authored by Simon G. (intrigus) on Jan 27 2020, 1:28 AM.

Details

Summary

Instrumenting blender with "-fsanitize=undefined" showed that blender exhibits undefined behavior.
This is caused by mikktspace.c, where a rotate left is performed, which exhibits undefined behavior:
intern/mikktspace/mikktspace.c:1608:29: runtime error: shift exponent 32 is too large for 32-bit type 'unsigned int'
This can be tested by rendering the benchmark.blend file found in https://download.blender.org/demo/test/benchmark.zip

Implementation is inspired by https://en.wikipedia.org/wiki/Circular_shift#Implementing_circular_shifts

Diff Detail

Repository
rB Blender