When in-cockpit view, there is a buffer overflow read when driving into something.
It is very easily reproducible, when building with the address sanitizer.
Drive into something. I can reproduce it by simply crashing into an opponent when starting the race.
The game crashes...
Terminal log
```
==52185==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x63000003fe44 at pc 0x7fb7cd249e0b bp 0x7ffe4d2d3da0 sp 0x7ffe4d2d3550
READ of size 320 at 0x63000003fe44 thread T0
#0 0x7fb7cd249e0a in __interceptor_memcpy (/lib64/libasan.so.8+0x49e0a)
#1 0x7fb7c890ccd9 in util_copy_rect (/usr/lib64/dri/crocus_dri.so+0x10ccd9)
#2 0x7fb7c8e0551a in util_copy_box (/usr/lib64/dri/crocus_dri.so+0x60551a)
#3 0x7fb7c93e1372 in u_default_texture_subdata (/usr/lib64/dri/crocus_dri.so+0xbe1372)
#4 0x7fb7c8979869 in st_TexSubImage (/usr/lib64/dri/crocus_dri.so+0x179869)
#5 0x7fb7c897a34f in st_TexImage (/usr/lib64/dri/crocus_dri.so+0x17a34f)
#6 0x7fb7c894049a in teximage_err (/usr/lib64/dri/crocus_dri.so+0x14049a)
#7 0x7fb7c89428f4 in _mesa_TexImage2D (/usr/lib64/dri/crocus_dri.so+0x1428f4)
#8 0x6dea11 in GLRenderer_SetBlendTable /home/maarten/programming/dethrace/src/harness/renderers/gl/gl_renderer.c:330
#9 0x6e2f0d in setActiveMaterial /home/maarten/programming/dethrace/src/harness/renderers/gl/gl_renderer.c:537
#10 0x6e3cac in GLRenderer_Model /home/maarten/programming/dethrace/src/harness/renderers/gl/gl_renderer.c:591
#11 0x6d96de in Harness_Hook_renderActor /home/maarten/programming/dethrace/src/harness/harness.c:376
#12 0x7565f9 in renderFaces /home/maarten/programming/dethrace/src/BRSRC13/CORE/V1DB/modrend.c:67
#13 0x72e4f4 in BrDbModelRender /home/maarten/programming/dethrace/src/BRSRC13/CORE/V1DB/render.c:32
#14 0x72f2ee in actorRender /home/maarten/programming/dethrace/src/BRSRC13/CORE/V1DB/render.c:142
#15 0x72ffb8 in sceneRenderAdd /home/maarten/programming/dethrace/src/BRSRC13/CORE/V1DB/render.c:254
#16 0x730862 in BrZbSceneRenderAdd /home/maarten/programming/dethrace/src/BRSRC13/CORE/V1DB/render.c:332
#17 0x4c88d8 in DoHorizon /home/maarten/programming/dethrace/src/DETHRACE/common/depth.c:552
#18 0x4c8da0 in DepthEffectSky /home/maarten/programming/dethrace/src/DETHRACE/common/depth.c:600
#19 0x508501 in RenderAFrame /home/maarten/programming/dethrace/src/DETHRACE/common/graphics.c:1675
#20 0x5512a9 in MainGameLoop /home/maarten/programming/dethrace/src/DETHRACE/common/mainloop.c:594
#21 0x55245e in DoRace /home/maarten/programming/dethrace/src/DETHRACE/common/mainloop.c:726
#22 0x66b497 in DoGame /home/maarten/programming/dethrace/src/DETHRACE/common/structur.c:540
#23 0x66c0e1 in DoProgram /home/maarten/programming/dethrace/src/DETHRACE/common/structur.c:647
#24 0x54ccfb in GameMain /home/maarten/programming/dethrace/src/DETHRACE/common/main.c:105
#25 0x6ba1c4 in original_main /home/maarten/programming/dethrace/src/DETHRACE/pc-dos/dossys.c:674
#26 0x6bb884 in main /home/maarten/programming/dethrace/src/DETHRACE/main.c:32
#27 0x7fb7ccc2950f in __libc_start_call_main (/lib64/libc.so.6+0x2950f)
#28 0x7fb7ccc295c8 in __libc_start_main_alias_2 (/lib64/libc.so.6+0x295c8)
#29 0x404ce4 in _start (/home/maarten/programming/dethrace/cmake-build-debug-asan/dethrace+0x404ce4)
0x63000003fe44 is located 0 bytes to the right of 64068-byte region [0x630000030400,0x63000003fe44)
allocated by thread T0 here:
#0 0x7fb7cd2ba6af in __interceptor_malloc (/lib64/libasan.so.8+0xba6af)
#1 0x4db55e in DRStdlibAllocate /home/maarten/programming/dethrace/src/DETHRACE/common/drmem.c:301
#2 0x6eb0bc in BrMemAllocate /home/maarten/programming/dethrace/src/BRSRC13/CORE/FW/mem.c:12
#3 0x6ed33d in BrResAllocate /home/maarten/programming/dethrace/src/BRSRC13/CORE/FW/resource.c:67
#4 0x715efd in DevicePixelmapMemAllocate /home/maarten/programming/dethrace/src/BRSRC13/CORE/PIXELMAP/pmmem.c:150
#5 0x717731 in _M_br_device_pixelmap_mem_match /home/maarten/programming/dethrace/src/BRSRC13/CORE/PIXELMAP/pmmem.c:333
#6 0x710967 in BrPixelmapMatch /home/maarten/programming/dethrace/src/BRSRC13/CORE/PIXELMAP/pmdsptch.c:72
#7 0x6b8323 in PDAllocateScreenAndBack /home/maarten/programming/dethrace/src/DETHRACE/pc-dos/dossys.c:373
#8 0x4faf9f in SetBRenderScreenAndBuffers /home/maarten/programming/dethrace/src/DETHRACE/common/graphics.c:523
#9 0x5153ee in InitializeBRenderEnvironment /home/maarten/programming/dethrace/src/DETHRACE/common/init.c:254
#10 0x515f28 in InitialiseApplication /home/maarten/programming/dethrace/src/DETHRACE/common/init.c:359
#11 0x5161b0 in InitialiseDeathRace /home/maarten/programming/dethrace/src/DETHRACE/common/init.c:410
#12 0x54ccf6 in GameMain /home/maarten/programming/dethrace/src/DETHRACE/common/main.c:104
#13 0x6ba1c4 in original_main /home/maarten/programming/dethrace/src/DETHRACE/pc-dos/dossys.c:674
#14 0x6bb884 in main /home/maarten/programming/dethrace/src/DETHRACE/main.c:32
#15 0x7fb7ccc2950f in __libc_start_call_main (/lib64/libc.so.6+0x2950f)
SUMMARY: AddressSanitizer: heap-buffer-overflow (/lib64/libasan.so.8+0x49e0a) in __interceptor_memcpy
Shadow bytes around the buggy address:
0x0c607fffff70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c607fffff80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c607fffff90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c607fffffa0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c607fffffb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c607fffffc0: 00 00 00 00 00 00 00 00[04]fa fa fa fa fa fa fa
0x0c607fffffd0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c607fffffe0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c607ffffff0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c6080000000: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c6080000010: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
==52185==ABORTING
```
By setting the environment variable ASAN_OPTIONS=abort_on_error=0 (before starting dethrace), I was able to attach a debugger and get the following stack trace:
When in-cockpit view, there is a buffer overflow read when driving into something. It is very easily reproducible, when building with the address sanitizer.
build/dethrace
Terminal log
``` ==52185==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x63000003fe44 at pc 0x7fb7cd249e0b bp 0x7ffe4d2d3da0 sp 0x7ffe4d2d3550 READ of size 320 at 0x63000003fe44 thread T0 #0 0x7fb7cd249e0a in __interceptor_memcpy (/lib64/libasan.so.8+0x49e0a) #1 0x7fb7c890ccd9 in util_copy_rect (/usr/lib64/dri/crocus_dri.so+0x10ccd9) #2 0x7fb7c8e0551a in util_copy_box (/usr/lib64/dri/crocus_dri.so+0x60551a) #3 0x7fb7c93e1372 in u_default_texture_subdata (/usr/lib64/dri/crocus_dri.so+0xbe1372) #4 0x7fb7c8979869 in st_TexSubImage (/usr/lib64/dri/crocus_dri.so+0x179869) #5 0x7fb7c897a34f in st_TexImage (/usr/lib64/dri/crocus_dri.so+0x17a34f) #6 0x7fb7c894049a in teximage_err (/usr/lib64/dri/crocus_dri.so+0x14049a) #7 0x7fb7c89428f4 in _mesa_TexImage2D (/usr/lib64/dri/crocus_dri.so+0x1428f4) #8 0x6dea11 in GLRenderer_SetBlendTable /home/maarten/programming/dethrace/src/harness/renderers/gl/gl_renderer.c:330 #9 0x6e2f0d in setActiveMaterial /home/maarten/programming/dethrace/src/harness/renderers/gl/gl_renderer.c:537 #10 0x6e3cac in GLRenderer_Model /home/maarten/programming/dethrace/src/harness/renderers/gl/gl_renderer.c:591 #11 0x6d96de in Harness_Hook_renderActor /home/maarten/programming/dethrace/src/harness/harness.c:376 #12 0x7565f9 in renderFaces /home/maarten/programming/dethrace/src/BRSRC13/CORE/V1DB/modrend.c:67 #13 0x72e4f4 in BrDbModelRender /home/maarten/programming/dethrace/src/BRSRC13/CORE/V1DB/render.c:32 #14 0x72f2ee in actorRender /home/maarten/programming/dethrace/src/BRSRC13/CORE/V1DB/render.c:142 #15 0x72ffb8 in sceneRenderAdd /home/maarten/programming/dethrace/src/BRSRC13/CORE/V1DB/render.c:254 #16 0x730862 in BrZbSceneRenderAdd /home/maarten/programming/dethrace/src/BRSRC13/CORE/V1DB/render.c:332 #17 0x4c88d8 in DoHorizon /home/maarten/programming/dethrace/src/DETHRACE/common/depth.c:552 #18 0x4c8da0 in DepthEffectSky /home/maarten/programming/dethrace/src/DETHRACE/common/depth.c:600 #19 0x508501 in RenderAFrame /home/maarten/programming/dethrace/src/DETHRACE/common/graphics.c:1675 #20 0x5512a9 in MainGameLoop /home/maarten/programming/dethrace/src/DETHRACE/common/mainloop.c:594 #21 0x55245e in DoRace /home/maarten/programming/dethrace/src/DETHRACE/common/mainloop.c:726 #22 0x66b497 in DoGame /home/maarten/programming/dethrace/src/DETHRACE/common/structur.c:540 #23 0x66c0e1 in DoProgram /home/maarten/programming/dethrace/src/DETHRACE/common/structur.c:647 #24 0x54ccfb in GameMain /home/maarten/programming/dethrace/src/DETHRACE/common/main.c:105 #25 0x6ba1c4 in original_main /home/maarten/programming/dethrace/src/DETHRACE/pc-dos/dossys.c:674 #26 0x6bb884 in main /home/maarten/programming/dethrace/src/DETHRACE/main.c:32 #27 0x7fb7ccc2950f in __libc_start_call_main (/lib64/libc.so.6+0x2950f) #28 0x7fb7ccc295c8 in __libc_start_main_alias_2 (/lib64/libc.so.6+0x295c8) #29 0x404ce4 in _start (/home/maarten/programming/dethrace/cmake-build-debug-asan/dethrace+0x404ce4) 0x63000003fe44 is located 0 bytes to the right of 64068-byte region [0x630000030400,0x63000003fe44) allocated by thread T0 here: #0 0x7fb7cd2ba6af in __interceptor_malloc (/lib64/libasan.so.8+0xba6af) #1 0x4db55e in DRStdlibAllocate /home/maarten/programming/dethrace/src/DETHRACE/common/drmem.c:301 #2 0x6eb0bc in BrMemAllocate /home/maarten/programming/dethrace/src/BRSRC13/CORE/FW/mem.c:12 #3 0x6ed33d in BrResAllocate /home/maarten/programming/dethrace/src/BRSRC13/CORE/FW/resource.c:67 #4 0x715efd in DevicePixelmapMemAllocate /home/maarten/programming/dethrace/src/BRSRC13/CORE/PIXELMAP/pmmem.c:150 #5 0x717731 in _M_br_device_pixelmap_mem_match /home/maarten/programming/dethrace/src/BRSRC13/CORE/PIXELMAP/pmmem.c:333 #6 0x710967 in BrPixelmapMatch /home/maarten/programming/dethrace/src/BRSRC13/CORE/PIXELMAP/pmdsptch.c:72 #7 0x6b8323 in PDAllocateScreenAndBack /home/maarten/programming/dethrace/src/DETHRACE/pc-dos/dossys.c:373 #8 0x4faf9f in SetBRenderScreenAndBuffers /home/maarten/programming/dethrace/src/DETHRACE/common/graphics.c:523 #9 0x5153ee in InitializeBRenderEnvironment /home/maarten/programming/dethrace/src/DETHRACE/common/init.c:254 #10 0x515f28 in InitialiseApplication /home/maarten/programming/dethrace/src/DETHRACE/common/init.c:359 #11 0x5161b0 in InitialiseDeathRace /home/maarten/programming/dethrace/src/DETHRACE/common/init.c:410 #12 0x54ccf6 in GameMain /home/maarten/programming/dethrace/src/DETHRACE/common/main.c:104 #13 0x6ba1c4 in original_main /home/maarten/programming/dethrace/src/DETHRACE/pc-dos/dossys.c:674 #14 0x6bb884 in main /home/maarten/programming/dethrace/src/DETHRACE/main.c:32 #15 0x7fb7ccc2950f in __libc_start_call_main (/lib64/libc.so.6+0x2950f) SUMMARY: AddressSanitizer: heap-buffer-overflow (/lib64/libasan.so.8+0x49e0a) in __interceptor_memcpy Shadow bytes around the buggy address: 0x0c607fffff70: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c607fffff80: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c607fffff90: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c607fffffa0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0x0c607fffffb0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 =>0x0c607fffffc0: 00 00 00 00 00 00 00 00[04]fa fa fa fa fa fa fa 0x0c607fffffd0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c607fffffe0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c607ffffff0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c6080000000: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x0c6080000010: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa Shadow byte legend (one shadow byte represents 8 application bytes): Addressable: 00 Partially addressable: 01 02 03 04 05 06 07 Heap left redzone: fa Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb ==52185==ABORTING ```By setting the environment variable
ASAN_OPTIONS=abort_on_error=0
(before starting dethrace), I was able to attach a debugger and get the following stack trace:Stacktrace of crashing into something in cockpit view with address sanitizer
``` #0 0x00007ffff78e4840 in __sanitizer::Die() () at /lib64/libasan.so.8 #1 0x00007ffff78c3c3e in __asan::ScopedInErrorReport::~ScopedInErrorReport() () at /lib64/libasan.so.8 #2 0x00007ffff78c31a6 in __asan::ReportGenericError(unsigned long, unsigned long, unsigned long, unsigned long, bool, unsigned long, unsigned int, bool) () at /lib64/libasan.so.8 #3 0x00007ffff7849e2a in memcpy () at /lib64/libasan.so.8 #4 0x00007ffff340551b in util_copy_box () at /usr/lib64/dri/crocus_dri.so #5 0x00007ffff39e1373 in u_default_texture_subdata () at /usr/lib64/dri/crocus_dri.so #6 0x00007ffff2f7986a in st_TexSubImage () at /usr/lib64/dri/crocus_dri.so #7 0x00007ffff2f7a350 in st_TexImage () at /usr/lib64/dri/crocus_dri.so #8 0x00007ffff2f4049b in teximage_err () at /usr/lib64/dri/crocus_dri.so #9 0x00007ffff2f428f5 in _mesa_TexImage2D () at /usr/lib64/dri/crocus_dri.so #10 0x00000000006dea12 in GLRenderer_SetBlendTable (table=0x60d0000f2dc8) at /home/maarten/programming/dethrace/src/harness/renderers/gl/gl_renderer.c:330 stored = 0x10008c8d0 #11 0x00000000006e2f0e in setActiveMaterial (material=0x6110000f89c0) at /home/maarten/programming/dethrace/src/harness/renderers/gl/gl_renderer.c:537 #12 0x00000000006e3cad in GLRenderer_Model (actor=0x610000385a68, model=0x60e000026168, model_matrix=..., render_type=BRT_TRIANGLE) at /home/maarten/programming/dethrace/src/harness/renderers/gl/gl_renderer.c:591 ctx = 0x6030000e7ee0 v11 = 0x62400030e140 m = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} __FUNCTION__ = {71 'G', 76 'L', 82 'R', 101 'e', 110 'n', 100 'd', 101 'e', 114 'r', 101 'e', 114 'r', 95 '_', 77 'M', 111 'o', 100 'd', 101 'e', 108 'l', 0 '\000'} group = 0x7ffff3d68abcI think the
GLRenderer_SetBlendTable
frame is key. https://github.com/dethrace-labs/dethrace/blob/256ab39925f8d3fc5c0e79ee2b9d92c9b3551ebc/src/harness/renderers/gl/gl_renderer.c#L330Applying the following (quicly written) patch fixes the crash: