Viewing Issue Advanced Details
ID Category [?] Severity [?] Reproducibility Date Submitted Last Update
06834 Misc. Critical (emulator) Always Jan 8, 2018, 09:47 Jan 9, 2018, 22:08
Tester Firewave View Status Public Platform
Assigned To Resolution Open OS
Status [?] Acknowledged Driver gb.cpp
Version 0.193 Fixed in Version Build
Summary MESS-specific 06834: supergb, supergb2: AddressSanitizer: heap-buffer-overflow with -cart 188in1
Description
==150863==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x6290005135ad at pc 0x00000d403a66 bp 0x7ffebd373a00 sp 0x7ffebd3739f8
READ of size 1 at 0x6290005135ad thread T0
    #0 0xd403a65 in sgb_ppu_device::update_sprites() /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/devices/video/gb_lcd.cpp:1326:17
    #1 0xd40573c in sgb_ppu_device::update_scanline(unsigned int) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/devices/video/gb_lcd.cpp:1581:5
    #2 0xd40e7b8 in dmg_ppu_device::update_state() /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/devices/video/gb_lcd.cpp:2074:5
    #3 0xd40c44d in dmg_ppu_device::device_timer(emu_timer&, unsigned int, int, void*) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/devices/video/gb_lcd.cpp:1928:2
    #4 0xe795168 in timer_expired /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/device.h:520:83
    #5 0xe795168 in device_scheduler::execute_timers() /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/schedule.cpp:906
    #6 0xe78ea0f in device_scheduler::timeslice() /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/schedule.cpp:530:2
    #7 0xe6a324b in running_machine::run(bool) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/machine.cpp:357:17
    #8 0x8cd10e0 in mame_machine_manager::execute() /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/frontend/mame/mame.cpp:236:19
    #9 0x8e1e0d3 in cli_frontend::start_execution(mame_machine_manager*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/frontend/mame/clifront.cpp:257:22
    #10 0x8e20ee0 in cli_frontend::execute(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/frontend/mame/clifront.cpp:273:3
    #11 0x8cd3717 in emulator_info::start_frontend(emu_options&, osd_interface&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/frontend/mame/mame.cpp:336:18
    #12 0x8acddf2 in main /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/osd/sdl/sdlmain.cpp:216:9
    #13 0x7fe8d85a582f in __libc_start_main /build/glibc-bfm8X4/glibc-2.23/csu/../csu/libc-start.c:291
    #14 0x1431838 in _start (/mnt/mame/mame64_as+0x1431838)

0x6290005135ad is located 717 bytes to the right of 16608-byte region [0x62900050f200,0x6290005132e0)
freed by thread T0 here:
    #0 0x14fe342 in operator delete(void*) /opt/media/clang_nightly/llvm/utils/release/final/llvm.src/projects/compiler-rt/lib/asan/asan_new_delete.cc:137:3
    #1 0xf288497 in operator() /usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/unique_ptr.h:76:2
    #2 0xf288497 in ~unique_ptr /usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/unique_ptr.h:236
    #3 0xf288497 in util::archive_file::open_zip(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::unique_ptr<util::archive_file, std::default_delete<util::archive_file> >&) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/lib/util/unzip.cpp:1468
    #4 0xe477f7c in emu_file::attempt_zipped() /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/fileio.cpp:680:39
    #5 0xe4753f7 in emu_file::open_next() /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/fileio.cpp:358:13
    #6 0xe475117 in emu_file::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/fileio.cpp:283:9
    #7 0xe6e7447 in render_target::load_layout_file(char const*, char const*) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/render.cpp:1865:39
    #8 0xe6d584e in render_target::load_layout_files(internal_layout const*, bool) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/render.cpp:1590:7
    #9 0xe6d49ad in render_target::render_target(render_manager&, internal_layout const*, unsigned int) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/render.cpp:970:2
    #10 0xe6ecc81 in render_manager::target_alloc(internal_layout const*, unsigned int) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/render.cpp:2831:31
    #11 0x8adcc71 in sdl_window_info::window_init() /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/osd/sdl/window.cpp:416:32
    #12 0x8ad0236 in sdl_osd_interface::video_init() /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/osd/sdl/video.cpp:79:12
    #13 0x8af970a in osd_common_t::init_subsystems() /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/osd/modules/lib/osdobj_common.cpp:650:7
    #14 0x8acf161 in sdl_osd_interface::init(running_machine&) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/osd/sdl/sdlmain.cpp:500:16
    #15 0xe69f690 in running_machine::start() /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/machine.cpp:214:18
    #16 0xe6a2a41 in running_machine::run(bool) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/machine.cpp:310:3
    #17 0x8cd10e0 in mame_machine_manager::execute() /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/frontend/mame/mame.cpp:236:19
    #18 0x8e1e0d3 in cli_frontend::start_execution(mame_machine_manager*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/frontend/mame/clifront.cpp:257:22
    #19 0x8e20ee0 in cli_frontend::execute(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/frontend/mame/clifront.cpp:273:3
    #20 0x8cd3717 in emulator_info::start_frontend(emu_options&, osd_interface&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/frontend/mame/mame.cpp:336:18
    #21 0x8acddf2 in main /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/osd/sdl/sdlmain.cpp:216:9
    #22 0x7fe8d85a582f in __libc_start_main /build/glibc-bfm8X4/glibc-2.23/csu/../csu/libc-start.c:291

previously allocated by thread T0 here:
    #0 0x14fd722 in operator new(unsigned long) /opt/media/clang_nightly/llvm/utils/release/final/llvm.src/projects/compiler-rt/lib/asan/asan_new_delete.cc:92:3
    #1 0xf285303 in make_unique<util::(anonymous namespace)::zip_file_impl, const std::__cxx11::basic_string<char> &> /usr/lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/unique_ptr.h:765:30
    #2 0xf285303 in util::archive_file::open_zip(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::unique_ptr<util::archive_file, std::default_delete<util::archive_file> >&) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/lib/util/unzip.cpp:1452
    #3 0xe477f7c in emu_file::attempt_zipped() /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/fileio.cpp:680:39
    #4 0xe4753f7 in emu_file::open_next() /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/fileio.cpp:358:13
    #5 0xe475117 in emu_file::open(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/fileio.cpp:283:9
    #6 0xe6e7447 in render_target::load_layout_file(char const*, char const*) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/render.cpp:1865:39
    #7 0xe6d584e in render_target::load_layout_files(internal_layout const*, bool) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/render.cpp:1590:7
    #8 0xe6d49ad in render_target::render_target(render_manager&, internal_layout const*, unsigned int) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/render.cpp:970:2
    #9 0xe6ecc81 in render_manager::target_alloc(internal_layout const*, unsigned int) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/render.cpp:2831:31
    #10 0x8adcc71 in sdl_window_info::window_init() /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/osd/sdl/window.cpp:416:32
    #11 0x8ad0236 in sdl_osd_interface::video_init() /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/osd/sdl/video.cpp:79:12
    #12 0x8af970a in osd_common_t::init_subsystems() /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/osd/modules/lib/osdobj_common.cpp:650:7
    #13 0x8acf161 in sdl_osd_interface::init(running_machine&) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/osd/sdl/sdlmain.cpp:500:16
    #14 0xe69f690 in running_machine::start() /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/machine.cpp:214:18
    #15 0xe6a2a41 in running_machine::run(bool) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/emu/machine.cpp:310:3
    #16 0x8cd10e0 in mame_machine_manager::execute() /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/frontend/mame/mame.cpp:236:19
    #17 0x8e1e0d3 in cli_frontend::start_execution(mame_machine_manager*, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > const&) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/frontend/mame/clifront.cpp:257:22
    #18 0x8e20ee0 in cli_frontend::execute(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/frontend/mame/clifront.cpp:273:3
    #19 0x8cd3717 in emulator_info::start_frontend(emu_options&, osd_interface&, std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&) /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/frontend/mame/mame.cpp:336:18
    #20 0x8acddf2 in main /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/osd/sdl/sdlmain.cpp:216:9
    #21 0x7fe8d85a582f in __libc_start_main /build/glibc-bfm8X4/glibc-2.23/csu/../csu/libc-start.c:291

SUMMARY: AddressSanitizer: heap-buffer-overflow /mnt/mame/build/projects/sdl/mame/gmake-linux-clang/../../../../../src/devices/video/gb_lcd.cpp:1326:17 in sgb_ppu_device::update_sprites()
Shadow bytes around the buggy address:
  0x0c528009a660: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c528009a670: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c528009a680: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c528009a690: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c528009a6a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x0c528009a6b0: fa fa fa fa fa[fa]fa fa fa fa fa fa fa fa fa fa
  0x0c528009a6c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c528009a6d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c528009a6e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c528009a6f0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c528009a700: 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
Steps To Reproduce
Additional Information
Flags
Regression Version
Affected Sets / Systems supergb, supergb2
Attached Files
 
Relationships
There are no relationship linked to this issue.
Notes
1
User avatar
No.14642
Firewave
Senior Tester
Jan 9, 2018, 22:08
uint16_t xindex = m_oam[oam_address + 1] - 8;

uint8_t pal = m_sgb_pal_map[(xindex < 0) ? 0 : (xindex >> 3)][((yindex - SGB_YOFFSET) >> 3)] << 2;
The < 0 check never works since it is unsigned - xindex also seems to underflow to 0xffff causing this access to be always out of bounds since m_sgb_pal_map[20][18].