Skip to content

Fix bugs found by reading the merged v1.2.0 code - #27

Merged
diegoparrilla merged 6 commits into
release/v1.2.0from
epic/20-bugs-found-by-analysis
Dec 2, 2026
Merged

diegoparrilla merged 6 commits into
release/v1.2.0from
epic/20-bugs-found-by-analysis

Conversation

@diegoparrilla

@diegoparrilla diegoparrilla commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Two independent readings of the merged v1.2.0 code turned up a long list of findings, area by area. That list also includes a command-by-command check of what the ST sends against what the RP reads, and a comparison of GEMDRIVE with md-drives-emulator's. This PR fixes the ones that lose data, escape the GEMDRIVE folder or give programs a wrong answer, and that are small and can be proven without the device. The m68k-side and larger findings are left for review at the release gate.

Fixed

The GEMDRIVE folder is a real boundary again (two independent ways out of it):

  • From the ST: Dsetpath("..") at the drive's root made the root of the card current. Relative paths are now normalised, with .. stopping at the root (md-drives-emulator's normaliser).
  • Over HTTP: %5C.. (a backslash) got past the path check, so a listing, PUT or DELETE could reach any file on the card. \ now separates folders exactly like /.

GEMDRIVE answers as TOS does:

  • Dsetpath, Fclose and Fdelete errors reached programs as -1. They were written as longs and read as words.
  • A search ends with ENMFIL (-49). Fsfirst("NAME.*") and Fsfirst("C:*.BIN") find their files.
  • Ddelete no longer deletes files, and Fdelete no longer deletes folders.
  • Dfree is capped so TOS's 32-bit byte count cannot wrap (a 32 GB card showed about 720 MB).

No more lost data, or stray data:

  • An overwrite upload that is cut off no longer deletes the original: it goes through UPLOAD~N.TMP and replaces the original only when complete.
  • Command-frame words no longer leak into the debug channel as stray bytes.

HTTP:

  • Listings of paths of 48 or more characters work.
  • URLs that are too long get 414 instead of acting on a cut-off name.
  • Replies no longer send bytes past their stack buffers.

CLI:

  • Errors on refused uploads keep their real exit code.
  • A 200 with a broken body is an error.
  • Listings with non-ASCII names work.
  • get -r on a complete file succeeds.
  • debug tail shows bytes as they arrive.

Checked

  • GDTEST: GDTEST.TOS gains nine checks for the GEMDRIVE fixes. In EmuMD, all nine fail on the code before this branch, and on this branch all 16 checks pass on ST TOS 1.04, STE 1.62 and Mega STE 2.06.
  • Debug channel: the stray debug bytes went from 94 per run to 0.
  • HTTP against the emulated firmware:
    • %5C.. gets 400 bad_path.
    • An interrupted overwrite leaves the original as it was, and put -f replaces it with no temporary file left behind.
    • A 54-character path lists.
    • A 200-character URL gets 414.
  • CLI: 128 unit tests (9 new, written to fail first).
  • Builds: release and debug build. BSS grows by about 640 bytes.

Not fixed here

These go to the release gate:

  • Runner launch crash on TOS 1.04: an intermittent halt after a Runner launch (2nd or 3rd program); this is the parked Runner exec crash.
  • Loader: checks in GEMDRIVE's program loader.
  • Pexec / Frename / Dgetpath drive routing.
  • Settings over-read: the global settings defaults over-read. A fix touches the Booster's settings sector, and nothing is lost today.
  • Mega STE [G] hang: an intermittent hang in 1 of 4 EmuMD runs.

- ".." no longer climbs out of the GEMDRIVE folder. FatFs follows ".."
  (FF_FS_RPATH is 2), so Dsetpath("..") at the drive's root made the
  root of the card current, and every relative Fopen or Fdelete after
  it acted on the whole card. Paths on the emulated drive are now
  normalised before use, with ".." stopping at the root, in Dsetpath and
  in every path a call turns into a card path. The normaliser is
  md-drives-emulator's sdcard_normalizePath, with its segment count
  bounded.
- Dsetpath, Fclose and Fdelete errors reach the program. The status was
  written as a long and read with move.w, so the program got its sign
  half: every error was -1. They are written as words, as
  md-drives-emulator does for Dsetpath and Fclose.
- The end of a search is ENMFIL (-49), as with TOS, not EFILNF (-33).
- Fsfirst("NAME.*") finds NAME.TXT. The trailing ".*" that lets "*.*"
  match folders was cut from every pattern, leaving "NAME", which only
  a file called NAME matched. Fsfirst("C:*.BIN") no longer keeps "C:"
  in the pattern.
- Ddelete only removes folders and Fdelete only files: both called
  f_unlink, so Ddelete("FILE.TXT") deleted the file.
- Dfree caps the cluster counts so TOS's 32-bit byte count cannot wrap:
  a 32 GB card showed its free space modulo 4 GiB, from
  md-drives-emulator.
Every ROM3 sample whose high byte is $FF was taken as a debug byte, and
a command frame's own words produce such samples whenever their m68k
value has $7F in the high byte. A program writing a file through
GEMDRIVE put one stray byte in the debug stream for every 256 bytes of
a pattern rich in $7F. A sample is now a debug byte only while the
parser is between frames: waiting for a header, or past its resync gap.
Nine more checks: the error codes of Dsetpath and Fclose, ".." at the
drive's root, Fsfirst with "NAME.*" and with a drive letter, the code
that ends a search, Ddelete of a file and Fdelete of a folder, and
Dfree's free bytes as TOS multiplies them. Before the fixes just made
they all failed in EmuMD; now GDTEST passes on an ST, an STE and a Mega
STE.
- A backslash no longer escapes the GEMDRIVE folder. Paths were split
  into segments on '/' only, but FatFs takes '\' as a separator too and
  follows "..", so ?path=%5C.. listed the root of the card and a DELETE
  or PUT through "\..\" reached any file on it. '\' now separates
  folders exactly like '/', so the ST's own GAMES\ARKANOID still works,
  and the Runner's stored folder is always the normalised form, which
  keeps the status JSON valid.
- An overwrite that is cut off no longer deletes the original. The file
  was truncated as the upload began and deleted when it failed; an
  overwrite is now written to UPLOAD~N.TMP in the same folder and
  replaces the original only once the whole body is on the card.
- Listing a folder whose path is 48 characters or longer sent its 200
  headers and then closed the connection: the buffer is sized for the
  longest path the server accepts, and anything longer is refused
  before the headers go out.
- A URL path or query longer than the server keeps is refused with 414,
  instead of acting on the cut-off name.
- Replies built with snprintf could send bytes past their stack buffer
  on long paths: the buffers are sized for two paths, and a reply never
  sends more than its text.
- An upload the server refuses before reading the body (409 exists,
  503 busy, 404, 400, 413) used to end in a connection reset and exit
  8, "cannot reach", with the reason lost. The CLI now reads the reply
  after a failed send and exits with the code for that status. Also for
  runner adv load.
- A 200 whose body is not valid JSON printed "error (200)" and exited
  0: it now exits 1. Bodies are decoded leniently, so a listing with a
  name in the Atari's character set (an umlaut) works.
- gemdrive get -r on a file that is already complete printed a range
  error and exited 5: it now says the file is complete and exits 0, and
  refuses, without touching it, a local file larger than the remote one.
- debug tail shows bytes as they arrive instead of in 256-byte blocks,
  so the end of a program's output is no longer held back.

Nine new tests, 128 in all.
@diegoparrilla
diegoparrilla merged commit 2b9954c into release/v1.2.0 Dec 2, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant