libretro / desmume

DeSmuME is a Nintendo DS emulator
http://desmume.org
GNU General Public License v2.0
35 stars 33 forks source link

Null pointer dereference on startup with Unicode path #9

Closed ghost closed 6 years ago

ghost commented 6 years ago

Latest HEAD and RA on Windows 10, I get this crash on starting after loading a rom:

Thread 1 received signal SIGSEGV, Segmentation fault.
0x00000000081700d4 in TSequenceItem_DMA<0, 0>::isTriggered (
    this=0xb647d18 <sequencer+152>) at ../../NDSSystem.cpp:1040
1040                    return (controller->dmaCheck && nds_timer>= controller->nextEvent);
(gdb) print controller
$1 = (DmaController *) 0x0
bearoso commented 6 years ago

I can't reproduce this. Can you post a full backtrace?

ghost commented 6 years ago

Sure. Also I just noticed it only seems to happen when the content path contains Unicode characters.

Thread 1 received signal SIGSEGV, Segmentation fault.
0x00000000080f00d4 in TSequenceItem_DMA<0, 0>::isTriggered (
    this=0xb5c7d18 <sequencer+152>) at ../../NDSSystem.cpp:1040
1040                    return (controller->dmaCheck && nds_timer>= controller->nextEvent);
(gdb) t a a bt full

Thread 10 (Thread 5988.0x430):
#0  0x00007ffa7e0e6bf4 in ntdll!ZwWaitForMultipleObjects ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#1  0x00007ffa7b10796f in WaitForMultipleObjectsEx ()
   from C:\Windows\System32\KernelBase.dll
No symbol table info available.
#2  0x00007ffa7b5ee1fb in USER32!MsgWaitForMultipleObjectsEx ()
   from C:\Windows\System32\user32.dll
No symbol table info available.
#3  0x00007ffa6503abf7 in DirectInput8Create ()
   from C:\Windows\SYSTEM32\dinput8.dll
No symbol table info available.
#4  0x00007ffa7df08364 in KERNEL32!BaseThreadInitThunk ()
   from C:\Windows\System32\kernel32.dll
No symbol table info available.
#5  0x00007ffa7e0a7091 in ntdll!RtlUserThreadStart ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#6  0x0000000000000000 in ?? ()
No symbol table info available.
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 9 (Thread 5988.0x1398):
#0  0x00007ffa7e0e6124 in ntdll!ZwWaitForSingleObject ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#1  0x00007ffa7b0f3acf in WaitForSingleObjectEx ()
   from C:\Windows\System32\KernelBase.dll
No symbol table info available.
#2  0x0000000030399242 in egsvnogl!egSyncWindowInfo ()
   from C:\Program Files\Amazon\EC2ElasticGPUs\bin64\egsvnogl.dll
No symbol table info available.
#3  0x0000000030398f69 in egsvnogl!egSyncWindowInfo ()
   from C:\Program Files\Amazon\EC2ElasticGPUs\bin64\egsvnogl.dll
No symbol table info available.
#4  0x000000003033ab59 in ?? ()
   from C:\Program Files\Amazon\EC2ElasticGPUs\bin64\egsvnogl.dll
No symbol table info available.
#5  0x000000003033ad17 in ?? ()
   from C:\Program Files\Amazon\EC2ElasticGPUs\bin64\egsvnogl.dll
No symbol table info available.
#6  0x00007ffa7df08364 in KERNEL32!BaseThreadInitThunk ()
   from C:\Windows\System32\kernel32.dll
No symbol table info available.
#7  0x00007ffa7e0a7091 in ntdll!RtlUserThreadStart ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#8  0x0000000000000000 in ?? ()
No symbol table info available.
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 8 (Thread 5988.0x1178):
#0  0x00007ffa7e0e6124 in ntdll!ZwWaitForSingleObject ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#1  0x00007ffa7b0f3acf in WaitForSingleObjectEx ()
   from C:\Windows\System32\KernelBase.dll
No symbol table info available.
#2  0x00000000075469f5 in ?? ()
   from C:\Program Files\Amazon\EC2ElasticGPUs\bin64\rvn_receiver.dll
No symbol table info available.
#3  0x000000000754617d in ?? ()
   from C:\Program Files\Amazon\EC2ElasticGPUs\bin64\rvn_receiver.dll
No symbol table info available.
#4  0x00000000075460d9 in ?? ()
   from C:\Program Files\Amazon\EC2ElasticGPUs\bin64\rvn_receiver.dll
No symbol table info available.
#5  0x0000000007546bb7 in ?? ()
   from C:\Program Files\Amazon\EC2ElasticGPUs\bin64\rvn_receiver.dll
No symbol table info available.
#6  0x00007ffa7df08364 in KERNEL32!BaseThreadInitThunk ()
   from C:\Windows\System32\kernel32.dll
No symbol table info available.
#7  0x00007ffa7e0a7091 in ntdll!RtlUserThreadStart ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#8  0x0000000000000000 in ?? ()
No symbol table info available.
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 7 (Thread 5988.0xd04):
#0  0x00007ffa7e0e6124 in ntdll!ZwWaitForSingleObject ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#1  0x00007ffa7b0f3acf in WaitForSingleObjectEx ()
   from C:\Windows\System32\KernelBase.dll
No symbol table info available.
#2  0x000000000754692e in ?? ()
   from C:\Program Files\Amazon\EC2ElasticGPUs\bin64\rvn_receiver.dll
No symbol table info available.
#3  0x000000000754617d in ?? ()
   from C:\Program Files\Amazon\EC2ElasticGPUs\bin64\rvn_receiver.dll
No symbol table info available.
#4  0x00000000075460d9 in ?? ()
   from C:\Program Files\Amazon\EC2ElasticGPUs\bin64\rvn_receiver.dll
No symbol table info available.
#5  0x0000000007546bb7 in ?? ()
   from C:\Program Files\Amazon\EC2ElasticGPUs\bin64\rvn_receiver.dll
No symbol table info available.
#6  0x00007ffa7df08364 in KERNEL32!BaseThreadInitThunk ()
   from C:\Windows\System32\kernel32.dll
No symbol table info available.
#7  0x00007ffa7e0a7091 in ntdll!RtlUserThreadStart ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#8  0x0000000000000000 in ?? ()
No symbol table info available.
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 6 (Thread 5988.0x80):
#0  0x00007ffa7e0e6124 in ntdll!ZwWaitForSingleObject ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#1  0x00007ffa7b0f3acf in WaitForSingleObjectEx ()
   from C:\Windows\System32\KernelBase.dll
No symbol table info available.
#2  0x00000000001c3eb8 in socket_transport!dl_create_client_transport ()
   from C:\Program Files\Amazon\EC2ElasticGPUs\bin64\transport\socket_transport.dll
No symbol table info available.
#3  0x000000003033b4fa in ?? ()
   from C:\Program Files\Amazon\EC2ElasticGPUs\bin64\egsvnogl.dll
No symbol table info available.
#4  0x000000003033ad17 in ?? ()
   from C:\Program Files\Amazon\EC2ElasticGPUs\bin64\egsvnogl.dll
No symbol table info available.
#5  0x00007ffa7df08364 in KERNEL32!BaseThreadInitThunk ()
   from C:\Windows\System32\kernel32.dll
No symbol table info available.
#6  0x00007ffa7e0a7091 in ntdll!RtlUserThreadStart ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#7  0x0000000000000000 in ?? ()
No symbol table info available.
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 5 (Thread 5988.0x14a4):
#0  0x0000000062e86a47 in ?? () from C:\msys64\mingw64\bin\zlib1.dll
No symbol table info available.
#1  0x0000000062e88291 in ?? () from C:\msys64\mingw64\bin\zlib1.dll
No symbol table info available.
#2  0x0000000000762224 in zlib_inflate_trans (data=0x2db2c310, flush=false,
    rd=0x7bcfd0c, wn=0x7bcfd08, error=0x7bcfd10)
    at libretro-common/streams/trans_stream_zlib.c:227
        zret = 32762
        ret = false
        pre_avail_in = 24399
        pre_avail_out = 16590960
        zt = 0x2db2c310
        z = 0x2db2c318
#3  0x000000000076bc8f in rpng_load_image_argb_process_inflate_init (
    rpng=0x2db2b900, data=0x2deaa9e8, width=0x7bcfe24, height=0x7bcfe20)
    at libretro-common/formats/png/rpng.c:784
        zstatus = false
        terror = 129826128
        rd = 0
        wn = 925139008
        process = 0x2db2c230
        to_continue = true
#4  0x000000000076c6b8 in rpng_process_image (rpng=0x2db2b900,
    _data=0x2deaa9e8, size=24538, width=0x7bcfe24, height=0x7bcfe20)
    at libretro-common/formats/png/rpng.c:1099
        data = 0x2deaa9e8
#5  0x0000000000781530 in image_transfer_process (data=0x2db2b900,
    type=IMAGE_TYPE_PNG, buf=0x2deaa9e8, len=24538, width=0x7bcfe24,
    height=0x7bcfe20) at libretro-common/formats/image_transfer.c:222
No locals.
#6  0x0000000000422726 in task_image_process (image=0x2deaa9b0,
    width=0x7bcfe24, height=0x7bcfe20) at tasks/task_image.c:94
        retval = 0
#7  0x000000000042283d in task_image_iterate_process_transfer (
    image=0x2deaa9b0) at tasks/task_image.c:137
        i = 0
        retval = 0
        width = 0
        height = 0
#8  0x0000000000422b69 in task_image_load_handler (task=0x2deaa500)
    at tasks/task_image.c:231
        i = 7
        nbio = 0x2deaa800
        image = 0x2deaa9b0
#9  0x0000000000422547 in task_file_load_handler (task=0x2deaa500)
    at tasks/task_file_transfer.c:103
        nbio = 0x2deaa800
#10 0x000000000041a18d in threaded_worker (userdata=0x0)
    at libretro-common/queues/task_queue.c:462
        task = 0x2deaa500
        finished = false
#11 0x0000000000593f36 in thread_wrap (data_=0x15b020)
    at libretro-common/rthreads/rthreads.c:145
        data = 0x15b020
#12 0x00007ffa7df08364 in KERNEL32!BaseThreadInitThunk ()
   from C:\Windows\System32\kernel32.dll
No symbol table info available.
#13 0x00007ffa7e0a7091 in ntdll!RtlUserThreadStart ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#14 0x0000000000000000 in ?? ()
No symbol table info available.
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 4 (Thread 5988.0xc04):
#0  0x00007ffa7e0e9874 in ntdll!ZwWaitForWorkViaWorkerFactory ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#1  0x00007ffa7e07354e in ntdll!RtlReleaseSRWLockExclusive ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#2  0x00007ffa7df08364 in KERNEL32!BaseThreadInitThunk ()
   from C:\Windows\System32\kernel32.dll
No symbol table info available.
#3  0x00007ffa7e0a7091 in ntdll!RtlUserThreadStart ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#4  0x0000000000000000 in ?? ()
No symbol table info available.
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 3 (Thread 5988.0x1460):
#0  0x00007ffa7e0e9874 in ntdll!ZwWaitForWorkViaWorkerFactory ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#1  0x00007ffa7e07354e in ntdll!RtlReleaseSRWLockExclusive ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#2  0x00007ffa7df08364 in KERNEL32!BaseThreadInitThunk ()
   from C:\Windows\System32\kernel32.dll
No symbol table info available.
#3  0x00007ffa7e0a7091 in ntdll!RtlUserThreadStart ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#4  0x0000000000000000 in ?? ()
No symbol table info available.
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 2 (Thread 5988.0x1618):
#0  0x00007ffa7e0e9874 in ntdll!ZwWaitForWorkViaWorkerFactory ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#1  0x00007ffa7e07354e in ntdll!RtlReleaseSRWLockExclusive ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#2  0x00007ffa7df08364 in KERNEL32!BaseThreadInitThunk ()
   from C:\Windows\System32\kernel32.dll
No symbol table info available.
#3  0x00007ffa7e0a7091 in ntdll!RtlUserThreadStart ()
   from C:\Windows\SYSTEM32\ntdll.dll
No symbol table info available.
#4  0x0000000000000000 in ?? ()
No symbol table info available.
Backtrace stopped: previous frame inner to this frame (corrupt stack?)

Thread 1 (Thread 5988.0x1624):
#0  0x00000000080f00d4 in TSequenceItem_DMA<0, 0>::isTriggered (
    this=0xb5c7d18 <sequencer+152>) at ../../NDSSystem.cpp:1040
No locals.
#1  Sequencer::execHardware (this=0xb5c7c80 <sequencer>)
    at ../../NDSSystem.cpp:1742
No locals.
#2  0x00000000083173d8 in NDS_exec<false> (nb=1120380)
    at ../../NDSSystem.cpp:2030
        s32next = 0
        arm9arm7 = {first = 0, second = 0}
        next = 190611456
        nds_timer_base = 1
        arm9 = 0
        arm7 = 0
#3  0x000000000818d17e in retro_run ()
    at ../../frontend/libretro/libretro.cpp:1713
        layout = {dst = 0x2dad0080, dst2 = 0x2dae8080, touch_x = 0,
          touch_y = 192, width = 256, height = 384, pitch = 256,
          draw_screen1 = true, draw_screen2 = true}
        updated = false
        have_touch = false
        gl_initialized = false
        skipped = false
#4  0x0000000000402f0d in core_run () at core_impl.c:415
No locals.
#5  0x000000000040890d in runloop_iterate (sleep_ms=0x55efdc0)
    at retroarch.c:3190
        i = 5
        input_nonblock_state = false
        settings = 0x76f31c0
        max_users = 5
#6  0x000000000040171f in rarch_main (argc=5, argv=0x153790, data=0x0)
    at frontend/frontend.c:131
        sleep_ms = 0
        ret = 0
        args = 0x0
#7  0x000000000040177f in SDL_main (argc=5, argv=0x153790)
    at frontend/frontend.c:154
No locals.
#8  0x00000000007b4e38 in main_getcmdline ()
No symbol table info available.
#9  0x00000000004013f7 in __tmainCRTStartup ()
    at C:/repo/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:341
        lock_free = <optimized out>
        fiberid = <optimized out>
        nested = <optimized out>
        lpszCommandLine = <optimized out>
        StartupInfo = {cb = 104, lpReserved = 0x5718d10 "",
          lpDesktop = 0x5713fa0 "Winsta0\\Default",
          lpTitle = 0x570ffd0 "C:\\msys64\\home\\Administrator\\RetroArch\\retroarch.exe", dwX = 0, dwY = 0, dwXSize = 0, dwYSize = 0, dwXCountChars = 0,
          dwYCountChars = 0, dwFillAttribute = 0, dwFlags = 0,
          wShowWindow = 0, cbReserved2 = 0, lpReserved2 = 0x0,
          hStdInput = 0xffffffffffffffff, hStdOutput = 0xffffffffffffffff,
          hStdError = 0xffffffffffffffff}
        inDoubleQuote = <optimized out>
#10 0x00000000004014fb in WinMainCRTStartup ()
    at C:/repo/mingw-w64-crt-git/src/mingw-w64/mingw-w64-crt/crt/crtexe.c:191
        ret = 255
(gdb)
bearoso commented 6 years ago

This occurs because mingw's c library can't handle unicode paths. There's many functions that this breaks: fopen, stat, access, etc. that desmume uses.

The way forward is probably to wrap those functions, like with fopen_utf8 in the libretro-common tree.

For now, I've fixed the error checking that lead to the crash. Now you just can't load the unicode paths.

bearoso commented 6 years ago

Looks like Desmume standalone Windows can't handle the paths either.

bearoso commented 6 years ago

This works now.