Aleph-One-Marathon / alephone

Aleph One is the open source continuation of Bungie’s Marathon 2 game engine.
https://alephone.lhowon.org/
GNU General Public License v3.0
644 stars 100 forks source link

UBSAN: map.cpp:1613:45: runtime error: left shift of negative value -1 #519

Open Kangie opened 1 week ago

Kangie commented 1 week ago

While investigating #518 I attempted to reproduce the error with ubsan enabled. Unfortunately upon attempting to generate noise and have enemies move into my line of sight the following error occurred. I believe it has to do with drawing the projectile/hitscan effect.

https://github.com/Aleph-One-Marathon/alephone/blob/d46b849aed6550f8ff26906c33998293cea48ad7/Source_Files/GameWorld/map.cpp#L1613

To Reproduce

kangie@monolith /data/development/temp/alephone (master?) $ CFLAGS="-march=native -O2 -pipe -flto -fsanitize=undefined" CXXFLAGS="-march=native -O2 -pipe -flto -fsanitize=undefined" ./configure --prefix=/usr --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --mandir=/usr/share/man --infodir=/usr/share/info --datadir=/usr/share --sysconfdir=/etc --localstatedir=/var/lib --datarootdir=/usr/share --disable-dependency-tracking --disable-silent-rules --docdir=/usr/share/doc/alephone-99999999 --htmldir=/usr/share/doc/alephone-99999999/html --libdir=/usr/lib64 --enable-opengl --with-ffmpeg --with-png --with-sdl_image --with-zzip --with-curl --without-miniupnpc
kangie@monolith /data/development/temp/alephone (master?) $ export UBSAN_OPTIONS="print_stacktrace=1:halt_on_error=1"
kangie@monolith /data/development/temp/alephone (master?) $ ./Source_Files/alephone /usr/share/alephone-marathon
Aleph One Linux 2024-08-22 1.10
https://alephone.lhowon.org/

Original code by Bungie Software <http://www.bungie.com/>
Additional work by Loren Petrich, Chris Pruett, Rhys Hill et al.
TCP/IP networking by Woody Zenfell
SDL port by Christian Bauer <Christian.Bauer@uni-mainz.de>

This is free software with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
For details, see the file COPYING.

Built with network play enabled.
GL_VENDOR: NVIDIA Corporation
GL_RENDERER: NVIDIA GeForce RTX 3060 Ti/PCIe/SSE2
GL_VERSION: 4.6.0 NVIDIA 560.28.03
map.cpp:1613:45: runtime error: left shift of negative value -1
    #0 0x559872a1634d in find_line_intersection(world_point2d*, world_point2d*, world_point3d*, world_point3d*, world_point3d*) [clone .isra.0] [clone .cold] (/data/development/temp/alephone/Source_Files/alephone+0xeba34d)
    #1 0x559872c30b50 in translate_projectile(short, world_point3d*, short, world_point3d*, short*, short, short*, short*, bool, short) (/data/development/temp/alephone/Source_Files/alephone+0x10d4b50)
    #2 0x559872c340bf in move_projectiles() (/data/development/temp/alephone/Source_Files/alephone+0x10d80bf)
    #3 0x559872bcc54b in update_world() (/data/development/temp/alephone/Source_Files/alephone+0x107054b)
    #4 0x559872a73ca4 in main_event_loop() (/data/development/temp/alephone/Source_Files/alephone+0xf17ca4)
    #5 0x559872a1fd45 in main (/data/development/temp/alephone/Source_Files/alephone+0xec3d45)
    #6 0x7fcf7244c3ed in __libc_start_call_main (/usr/lib64/libc.so.6+0x263ed)
    #7 0x7fcf7244c4a8 in __libc_start_main_impl (/usr/lib64/libc.so.6+0x264a8)
    #8 0x559872a5a0c4 in _start (/data/development/temp/alephone/Source_Files/alephone+0xefe0c4)
Kangie commented 1 week ago

Going to lump this one in here too, triggered when a Pfhor Fighter tried to attack.

./Source_Files/alephone /usr/share/alephone-marathon
Aleph One Linux 2024-08-22 1.10
https://alephone.lhowon.org/

Original code by Bungie Software <http://www.bungie.com/>
Additional work by Loren Petrich, Chris Pruett, Rhys Hill et al.
TCP/IP networking by Woody Zenfell
SDL port by Christian Bauer <Christian.Bauer@uni-mainz.de>

This is free software with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
For details, see the file COPYING.

Built with network play enabled.
GL_VENDOR: NVIDIA Corporation
GL_RENDERER: NVIDIA GeForce RTX 3060 Ti/PCIe/SSE2
GL_VERSION: 4.6.0 NVIDIA 560.28.03
map.cpp:1646:43: runtime error: left shift of negative value -1
    #0 0x565064191155 in closest_point_on_line(world_point2d*, world_point2d*, world_point2d*, world_point2d*) [clone .isra.0] [clone .cold] (/data/development/temp/alephone/Source_Files/alephone+0xeba155)
    #1 0x56506432ce9f in keep_line_segment_out_of_walls(short, world_point3d*, world_point3d*, short, short, short*, short*, short*) (/data/development/temp/alephone/Source_Files/alephone+0x1055e9f)
    #2 0x56506437b004 in instantiate_physics_variables(physics_constants*, physics_variables*, short, bool, bool) (/data/development/temp/alephone/Source_Files/alephone+0x10a4004)
    #3 0x5650643945ad in update_players(ActionQueues*, bool) (/data/development/temp/alephone/Source_Files/alephone+0x10bd5ad)
    #4 0x565064347546 in update_world() (/data/development/temp/alephone/Source_Files/alephone+0x1070546)
    #5 0x5650641eeca4 in main_event_loop() (/data/development/temp/alephone/Source_Files/alephone+0xf17ca4)
    #6 0x56506419ad45 in main (/data/development/temp/alephone/Source_Files/alephone+0xec3d45)
    #7 0x7f2e5364c3ed in __libc_start_call_main (/usr/lib64/libc.so.6+0x263ed)
    #8 0x7f2e5364c4a8 in __libc_start_main_impl (/usr/lib64/libc.so.6+0x264a8)
    #9 0x5650641d50c4 in _start (/data/development/temp/alephone/Source_Files/alephone+0xefe0c4)

https://github.com/Aleph-One-Marathon/alephone/blob/d46b849aed6550f8ff26906c33998293cea48ad7/Source_Files/GameWorld/map.cpp#L1646

treellama commented 1 week ago

These are technically undefined, but they are universally 2's complement, which will become official once we switch the compiler to C++20