joncampbell123 / dosbox-x

DOSBox-X fork of the DOSBox project
GNU General Public License v2.0
2.81k stars 383 forks source link

Segfault on write to overlay dir when starting from a ZIP #4994

Closed unmacaque closed 5 months ago

unmacaque commented 6 months ago

Describe the bug

When attempting to save in any game that is started from a ZIP file and using an overlay directory, dosbox-x crashes with a SIGSEGV. The overlay directory will contain 0 byte files named after the files that should have been written.

The attached output log contains a gdb trace.

Used vanilla configuration. Seems to occur regardless of filesystem or tested game.

Steps to reproduce the behaviour

  1. Create a ZIP archive of any game that offers a save feature (I tried Simcity 2000)
  2. Start dosbox-x
  3. mount C "/home/user/path/to/game.zip"
  4. mount C "/home/user/anotherpath" -t overlay
  5. Launch game
  6. Save in game or wait for game to write any file to disk

Expected behavior

Expected dosbox-x to not crash and the save file to be properly written to the overlay dir

What operating system(s) this bug have occurred on?

Arch Linux x86_64

What version(s) of DOSBox-X have this bug?

2024.03.01

Used configuration

No response

Output log

GNU gdb (GDB) 14.2
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<https://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
    <http://www.gnu.org/software/gdb/documentation/>.

For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from dosbox-x...
Reading symbols from /usr/lib/debug/usr/bin/dosbox-x.debug...
(No debugging symbols found in /usr/lib/debug/usr/bin/dosbox-x.debug)
(gdb) run
Starting program: /usr/bin/dosbox-x
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
LOG: Early LOG Init complete
LOG: DOSBox-X's working directory: /home/andy
LOG: Logging init: beginning logging proper. This is the end of the early init logging
LOG: Logging: No logfile was given. All further logging will be discarded.
LOG: DOSBox-X version 2024.03.01 Commit 02f36ba (Linux SDL1 64-bit)
[New Thread 0x75b8bc6006c0 (LWP 73021)]
Warning: XMODIFIERS is unspecified
[New Thread 0x75b8b76006c0 (LWP 73022)]
[Thread 0x75b8b76006c0 (LWP 73022) exited]
LOG: Current X11 keyboard layout (token) is: 'us'
LOG: Host keyboard layout is now us (US English)
LOG: Mapper keyboard layout is now us (US English)
LOG: SDL1 auto-detected desktop as 1920 x 1080
LOG: The default output for the video system: surface
LOG: Configured windowposition: -
LOG: X11 main window is 640 x 400 maximized=0
LOG: X11 extension XRANDR is available
LOG: XRandR CRTC 0: pos=(0,0) size=(1920,1080) outputs=1
LOG: Our window lies on this CRTC display (window pos=(86,120) size=(640,400) match=(406,320)).
LOG:   Goes to output 0: name='HDMI-1' size_mm=(530 x 300)
LOG: Screen report: Method 'XRandR' (1920.000 x 1080.000 pixels) at (0.000 x 0.000) (530.000 x 300.000 mm) (20.866 x 11.811 in) (92.015 x 91.440 DPI)
LOG: Current X11 keyboard layout (token) is: 'us'
LOG: SDL_mapper: US keyboard detected, set usescancodes=false
LOG: ISA BCLK: 8333333.333Hz (25000000/3)
LOG: monopal: green,
LOG: Active save slot: 1 [Empty]
LOG: USING AVI+ZMBV
LOG: Max 3670016 sz 16384
LOG: Final 16384
[New Thread 0x75b8b76006c0 (LWP 73025)]
LOG: SDLNet_TCP_Open: Couldn't connect to remote host
LOG: TiMidity: can't open control connection (host=127.0.0.1, port=7777)
LOG: MIDI:fluidsynth: SoundFont not specified, and no system SoundFont found
LOG: MIDI:synth: Specify .SF2 sound font file with midiconfig=
LOG: MT32: failed to locate ROMs.
LOG: MT32 emulation requires the PCM and CONTROL ROM files.
LOG: To eliminate this error message, check the DOSBox-X wiki.
LOG: The ROM files are: CM32L_CONTROL.ROM and CM32L_PCM.ROM or MT32_CONTROL.ROM and MT32_PCM.ROM
LOG: MIDI:Opened device:none
LOG: Pentium CMPXCHG8B emulation is enabled
LOG: VOODOO LFB now at d0000000
LOG: Serial1: BASE 3f8h
LOG: Serial2: BASE 2f8h
LOG: Parallel1: BASE 378h
LOG: MPU-401 Registering I/O ports as if IBM PC MPU-401 at base 330h
LOG: Memory I/O complexity optimization enabled aka option 'memory io optimization 1'. If the game or demo is unable to draw to the screen properly, set the option to false.
LOG: The 'scanline render on demand' option is available and may provide a modest boost in video render performance if set to true.
LOG: GetDesktopResolution reading X11 desktop resolution
LOG: Root window (ID 1183) is 1920 x 1080
LOG: X11 main window is 640 x 400 maximized=0
LOG: XRandR CRTC 0: pos=(0,0) size=(1920,1080) outputs=1
LOG: Our window lies on this CRTC display (window pos=(86,120) size=(640,400) match=(406,320)).
LOG:   Goes to output 0: name='HDMI-1' size_mm=(530 x 300)
LOG: Screen report: Method 'XRandR' (1920.000 x 1080.000 pixels) at (0.000 x 0.000) (530.000 x 300.000 mm) (20.866 x 11.811 in) (92.015 x 91.440 DPI)
LOG: Allocated APM BIOS pm entry point at f000:ce40
LOG: Writing code to fce40
LOG: Writing code to fce60
LOG: X11 main window is 640 x 400 maximized=0
LOG: XRandR CRTC 0: pos=(0,0) size=(1920,1080) outputs=1
LOG: Our window lies on this CRTC display (window pos=(86,120) size=(640,400) match=(406,320)).
LOG:   Goes to output 0: name='HDMI-1' size_mm=(530 x 300)
LOG: Screen report: Method 'XRandR' (1920.000 x 1080.000 pixels) at (0.000 x 0.000) (530.000 x 300.000 mm) (20.866 x 11.811 in) (92.015 x 91.440 DPI)
LOG: ISA Plug & Play BIOS enabled
LOG: VGA ROM BIOS init callback
LOG: pixratio 1.000, dw false, dh false
LOG: Aspect ratio: 640 x 480  xToY=1.333 yToX=0.750
LOG: menuScale=1
LOG: surface consider=640x497 final=640x497
LOG: X11 main window is 640 x 497 maximized=0
LOG: XRandR CRTC 0: pos=(0,0) size=(1920,1080) outputs=1
LOG: Our window lies on this CRTC display (window pos=(86,120) size=(640,497) match=(406,368)).
LOG:   Goes to output 0: name='HDMI-1' size_mm=(530 x 300)
LOG: Screen report: Method 'XRandR' (1920.000 x 1080.000 pixels) at (0.000 x 0.000) (530.000 x 300.000 mm) (20.866 x 11.811 in) (92.015 x 91.440 DPI)
LOG: WARNING: No translation support (to host) for code page 0
LOG:    3017787 ERROR BIOS:Keyboard layout file auto not found
LOG:    3017787 ERROR BIOS:Keyboard layout file auto not found
LOG: XMS: 50 handles allocated for use by the DOS environment
LOG: EMS page frame at 0xe000-0xefff
LOG: COMMAND.COM env size:             720 bytes
LOG: COMMAND.COM environment block:    0x0701 sz=0x002d
LOG: COMMAND.COM main body (PSP):      0x072f sz=0x009a
LOG: COMMAND.COM stack:                0x0749
LOG: pixratio 1.350, dw false, dh false
LOG: Aspect ratio: 720 x 540  xToY=1.333 yToX=0.750
LOG: menuScale=1
LOG: surface consider=720x417 final=720x417
LOG: X11 main window is 720 x 417 maximized=0
LOG: XRandR CRTC 0: pos=(0,0) size=(1920,1080) outputs=1
LOG: Our window lies on this CRTC display (window pos=(86,120) size=(720,417) match=(446,328)).
LOG:   Goes to output 0: name='HDMI-1' size_mm=(530 x 300)
LOG: Screen report: Method 'XRandR' (1920.000 x 1080.000 pixels) at (0.000 x 0.000) (530.000 x 300.000 mm) (20.866 x 11.811 in) (92.015 x 91.440 DPI)
LOG:    3052022 ERROR BIOS:INT15:Unknown call ax=BFDE
LOG:    3052100 ERROR BIOS:INT15:Unknown call ax=BFDE
LOG: DOSBox-X has switched to max cycles, because of the setting: cycles=auto.
If the game runs too fast, try a fixed cycles amount in DOSBox-X's options.
LOG:    3066914 ERROR BIOS:INT15:Unknown call ax=BF01
LOG:    5589855 ERROR BIOS:INT15:Unknown call ax=BFDE
LOG:    5597019 ERROR BIOS:INT15:Unknown call ax=BFDE
LOG:   17970978 ERROR MOUSE:Unhandled videomode 69 on reset
LOG: pixratio 1.000, dw false, dh false
LOG: Aspect ratio: 640 x 480  xToY=1.333 yToX=0.750
LOG: menuScale=1
LOG: surface consider=640x497 final=640x497
LOG: X11 main window is 640 x 497 maximized=0
LOG: XRandR CRTC 0: pos=(0,0) size=(1920,1080) outputs=1
LOG: Our window lies on this CRTC display (window pos=(86,120) size=(640,497) match=(406,368)).
LOG:   Goes to output 0: name='HDMI-1' size_mm=(530 x 300)
LOG: Screen report: Method 'XRandR' (1920.000 x 1080.000 pixels) at (0.000 x 0.000) (530.000 x 300.000 mm) (20.866 x 11.811 in) (92.015 x 91.440 DPI)
LOG:   18041048 ERROR MOUSE:Unhandled videomode 69 on reset

Thread 1 "dosbox-x" received signal SIGSEGV, Segmentation fault.
0x0000568f4706d5bf in physfsFile::prepareWrite() ()
(gdb) bt full
#0  0x0000568f4706d5bf in physfsFile::prepareWrite() ()
#1  0x0000568f4706d7f8 in physfsFile::Write(unsigned char const*, unsigned short*) ()
#2  0x0000568f46fc06f8 in DOS_WriteFile(unsigned short, unsigned char const*, unsigned short*, bool) ()
#3  0x0000568f46fad4cf in DOS_21Handler() ()
#4  0x0000568f46efe106 in Normal_Loop() ()
#5  0x0000568f46efe39e in DOSBOX_RunMachine() ()
#6  0x0000568f4746b322 in CALLBACK_RunRealInt(unsigned char) ()
#7  0x0000568f471133ba in DOS_Shell::Execute(char*, char const*) ()
#8  0x0000568f470f6ce7 in DOS_Shell::DoCommand(char*) ()
#9  0x0000568f470dbc00 in DOS_Shell::ParseLine(char*) ()
#10 0x0000568f470dc79b in DOS_Shell::Run() ()
#11 0x0000568f470e6374 in SHELL_Run() ()
#12 0x0000568f471bfd1d in VM_Boot_DOSBox_Kernel() ()
#13 0x0000568f471661ed in BIOS::cb_bios_boot__func() ()
#14 0x0000568f46efe106 in Normal_Loop() ()
#15 0x0000568f46efe39e in DOSBOX_RunMachine() ()
#16 0x0000568f46e99bc2 in main ()

Additional information

When used individually, the ZIP launch and overlay dir features work fine.

Have you checked that no similar bug report(s) exist?

Code of Conduct & Contributing Guidelines

grapeli commented 6 months ago

I reported this bug a year and a half ago. https://github.com/joncampbell123/dosbox-x/issues/3535#issuecomment-1242416569

Remove or comment out this code and it will work perfectly fine.

//#ifndef WIN32
//              fcntl(**(int**)fhandle->opaque,F_SETFL,0);
//#endif
joncampbell123 commented 5 months ago

I reported this bug a year and a half ago. #3535 (comment)

Remove or comment out this code and it will work perfectly fine.

//#ifndef WIN32
//              fcntl(**(int**)fhandle->opaque,F_SETFL,0);
//#endif

That might explain why the crash does not happen here on Linux.

joncampbell123 commented 5 months ago

Looking at the physfs code, I have a few questions. If the Windows-specific code is using CreateFileW(), why the hacky fcntl() on file handle typecast from int** pointer? It's unnecessary.

What was the original intent? To clear O_TEXT?

I think it's best to fix this issue by just removing the code.

joncampbell123 commented 5 months ago

Now I'm going to pull out my Windows 11 laptop and see if I can mount a ZIP and overlay, and write a file without segfaulting.

joncampbell123 commented 5 months ago

Looks good.