Skip to content

games-retro-install: spec-correct .desktop escaping for ROM names and paths - #13935

Closed
kvnloo wants to merge 11 commits into
omacom:quattrofrom
kvnloo:muse/games-retro-desktop-escaping
Closed

kvnloo wants to merge 11 commits into
omacom:quattrofrom
kvnloo:muse/games-retro-desktop-escaping

Conversation

@kvnloo

@kvnloo kvnloo commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

What

The script interpolated paths/names raw into generated .desktop files. Red-on-base proved four breaks:

  • a quote in a ROM path corrupted the Exec argument grouping (spec-parse yields a wrong path),
  • %/%U un-doubled triggered launcher field-code expansion,
  • a newline in a filename injected a raw second Exec= key line (ROM names are untrusted input),
  • (Europe).sfc wrote an invalid empty-Name .desktop.

Fix

Spec-correct Exec quoting, string escaping for Name/Comment, and empty-name/id fallbacks.

Evidence

  • New test 6/6 (red on base, green on fix), round-trip verified, bin-style green.

Posted by Kevin's agent on his behalf — AI-assisted contribution (Muse, Meta's Muse Spark) under the contributor's direction. The contributor reviewed the change and takes responsibility for it.

Kevin Rajan added 2 commits September 27, 2026 20:42
…es, and empty names

Posted by Kevin's agent on his behalf — AI-assisted (Muse, Meta's Muse Spark).

Rebased onto current quattro (was 28ceaae).
…wline in Exec

Posted by Kevin's agent on his behalf — AI-assisted (Muse, Meta's Muse Spark).

Addresses QA HOLD on PR #85: the newline case inspected
`ls *.desktop | head -1` while $apps held entries from earlier
cases, so it could pass on an unrelated clean file. The case
now clears $apps and asserts on the exact slug-derived entry.
That exposed a real bug: desktop_exec_quote did not escape
newlines, so a newline in the ROM path injected a second Exec=
key line. Newlines (and CR/tab) are now escaped in Exec args.
@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; the latest test change introduces no identified defect.

Summary

The PR escapes ROM names and paths in generated desktop entries, canonicalizes ROM paths, and adds launcher tests. The latest change strengthens the relative-path test by checking that reinstalling uses the same launcher ID.

Reviews (5) · Last reviewed commit: "test(games): require relative install to..." · Reviewed by Greptile

Comment thread bin/omarchy-games-retro-install Resolved
Comment thread bin/omarchy-games-retro-install Resolved
@jandrusk

jandrusk commented Oct 1, 2026

Copy link
Copy Markdown

This is a real Desktop Entry injection / Exec-breakage fix, not just polish.

desktop_exec_quote / desktop_string_escape match the freedesktop rules (quotes, % → %%, newline/CR/tab), and the tests cover quote paths, %U, newline key injection, and empty cleaned names. Ready for review from my side.

Nit: fallback desktop_id=retro-game can collide if multiple empty-name ROMs are installed — low priority.

omarchybot and others added 2 commits October 7, 2026 23:28
…allback id on the ROM path

Exec is a string value first and an argument list second, so a quoted argument needs both layers: the Exec-spec quoting for the argument, then the string escaping for the line. With one layer, a quote in a ROM path wrote \" into the file, an escape GLib's key file parser rejects, so gtk-launch refused the whole entry and the game vanished from the launcher. This now composes the two layers the way omarchy-webapp-install does, and escapes ` and $ inside the quotes as the spec asks.

The fallback id for a name that slugs to nothing was a fixed retro-game, so a second such ROM (any title with no ASCII letters or digits, a Japanese one say) overwrote the first's launcher. It now carries a short hash of the ROM path, which stays stable across reinstalls of the same game.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…roarch's argv

The escaping checks compared text in the generated file, which passed while a quote in a ROM path made an entry GLib refused to load. This launches each adversarial entry with gio launch, the same GDesktopAppInfo path gtk-launch takes, against a stub retroarch that records its arguments, and requires the exact ROM path back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Codex Medium <noreply@openai.com>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 7, 2026
Comment thread bin/omarchy-games-retro-install Resolved
@omarchybot omarchybot added the ready Good to merge label Oct 7, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks @kvnloo. The bug is real: on a worker running stock Omarchy, I generated launchers with quattro's script and started them through gtk-launch (what the app launcher uses) and gio launch, against a stub retroarch that records its arguments. A ", %, %U or backslash in the ROM path reached RetroArch as a different path. A newline made the entry unloadable, and (Europe).sfc wrote .desktop.

Your branch fixed most of that, but two things were still wrong, and I've pushed two commits on top:

  • A quote in a ROM path made the entry unloadable. Exec is unescaped as a string first and parsed for quoted arguments second, so a quoted argument needs both layers. Writing \" straight into the file is an invalid string escape, and GLib refused the whole entry, so My "Best" Game.sfc disappeared from the launcher. 71fc24a quotes each argument and then string-escapes the whole Exec line, the way omarchy-webapp-install does, and also escapes ` and $ inside the quotes as the spec asks.
  • The fallback id collided. Every name that slugs to nothing got retro-game.desktop. That covers any title with no ASCII letters or digits, such as a Japanese one, so a second such ROM overwrote the first's launcher. It now carries the MD5 of the ROM path, which stays the same across reinstalls.
  • The test checked the file's text, never the launch. That's how the quote case passed while GLib rejected the entry. 6859dae adds a case that launches each tricky entry with gio launch and requires the exact ROM path back. That case fails on your previous head and passes now.

At 6859dae, every case reaches RetroArch with the exact path through both launchers: quotes, %, %U, backslashes (including a trailing one), $, backticks, tabs, newlines, (Europe).sfc and two Japanese titles. Merged into current quattro, ./test/cli is green and games-retro-install-desktop-test.sh passes 8/8. On your branch's own base, ./test/cli has one unrelated vscode failure, which quattro has since fixed.

Codex Medium reviewed it twice. The first round found the two problems in the second and third points above, plus a cosmetic one: a leading space in a fallback Name= is dropped. I left that one, since it changes only the displayed name. The second round, on 6859dae, found nothing. Greptile's earlier findings on backslashes, fallback collisions and the text-only tests are addressed by these commits. Its new note is that the same empty-slug ROM installed once by absolute and once by relative path gets two launchers. I've left that too: a relative path already writes an Exec the launcher can't start, on quattro as well, and the menu always passes absolute paths.

This is now waiting on the maintainer.

Normalize the ROM path for launcher execution and fallback IDs while
keeping the supplied filename for the displayed game title. The
same ROM now receives one launcher whether selected by an absolute
or relative path, and its Exec argument remains usable after launch.

Address the remaining Greptile finding on omacom#13935.
Credit the original Muse escaping patch and maintainer reviews.
Exercise one ROM through both absolute and relative installs and
require one usable desktop entry, alongside existing GLib round-trips.
Keep the original test cases and original contributor credit.
Comment thread bin/omarchy-games-retro-install Resolved
@omarchybot omarchybot removed verified Omarchy Triage has verified that this issue is ready for final review ready Good to merge labels Oct 16, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks @kvnloo. I read your two new commits (b71e511, 7d3848f) and compared this pull request with #9420, which fixes the same escaping bug in the same file. Nothing was run on a worker this pass. That was deliberate: the comparison settles which fix goes forward, and running this one again would not change that.

#9420 is the fix that goes forward. It was opened first. With the commits I pushed here on 7 October, both pull requests escape Name=, Comment= and Exec= the same way: quote each argument, then string-escape the whole Exec line. #9420 handles every ROM path case this one does. When two fixes are equivalent, the older one keeps the credit. This one does carry real improvements beyond the escaping, and those are being folded into #9420 with credit to you:

  • the raw-filename fallback when a name cleans to nothing, so (Europe).sfc no longer writes .desktop;
  • the path-hashed fallback id, so two titles with no ASCII letters or digits keep separate launchers;
  • absolute ROM paths in Exec, so a launcher installed with a relative path still starts;
  • the GLib launch test that checks the exact argv RetroArch receives.

Two things in the new commits need fixing as they move across. I checked both by hand:

  • bin/omarchy-games-retro-install:41 loses a trailing newline. realpath prints the path plus its own newline, and command substitution strips both. For a ROM whose name ends in a newline, the -f check passes on the real path, but Exec then names a file that does not exist. Greptile flagged this too. Reading realpath -z NUL-delimited avoids it.
  • Test 4c passes even when the relative install fails. The absolute install has already written the launcher, and neither the test nor base-test.sh sets errexit. So a relative install that writes nothing still leaves a launcher for the assertions to find. Check the relative call's exit status, and remove the first launcher before running it.

Codex Medium was asked separately which of the two should win, without my answer. It agreed that, for ROM paths, #9420 misses nothing this one fixes. It also confirmed both findings above. It reached the same conclusion I did, but it can read this session's work, so that agreement is not independent. It noted one difference in this PR's favour: #9420 would drop a trailing newline from a core path. I don't count that, because core paths come from installed libretro packages.

This is now waiting on the maintainer to choose between the two.

omarchybot added a commit to Adolanium/omarchy that referenced this pull request Oct 16, 2026
…uncher of its own

Carried over from omacom#13935. The Exec line now names the game's absolute path, read NUL-delimited from realpath so a file name ending in a newline keeps it, so a launcher installed with a relative path still starts. A name that cleans to nothing, like "(Europe).sfc", keeps its raw file name instead of writing ".desktop", and a name with no ASCII letters or digits gets an id keyed on the game path, so two Japanese titles no longer overwrite one launcher.

The test now starts each tricky entry through gio launch and checks the exact argv retroarch receives, since a file that reads right can still be one GLib refuses.

Co-Authored-By: Kevin Rajan <7121943+kvnloo@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
omarchybot added a commit to Adolanium/omarchy that referenced this pull request Oct 16, 2026
desktop_exec_arg piped the path through sed inside a command substitution, which drops a newline ending the value, so a game whose file name ends in one got a launcher for a path that does not exist. Parameter expansion, as omacom#13935 escapes it, keeps every byte, and covers the core path the same way.

Co-Authored-By: Kevin Rajan <7121943+kvnloo@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks @kvnloo. I read your commits since the last review, 296ea7d through f7684b0. Nothing ran on a worker this pass. The question is still which of this and #9420 goes forward, and running this one again would not answer it.

Both problems from my last comment are fixed:

  • bin/omarchy-games-retro-install:43 now reads realpath -e -z NUL-delimited, so a ROM name ending in a newline keeps it. If realpath fails, the script exits with a message before writing anything.
  • Test 4c now removes the first launcher, fails if the relative install fails, and requires the relative install to recreate the same launcher id. A relative install that exits cleanly but writes nothing fails the test too.

#9420 still goes forward. It was opened first, and since the last review it has taken up the runtime changes this pull request introduced: the canonical ROM path, read the same NUL-delimited way, the raw-filename fallback name, and the path-hashed fallback id. On the escaping, neither one misses a case the other handles. What this pull request still adds is test coverage: test 4c's check that absolute and relative installs share one launcher, the full-entry line count in test 3, and the Super Game (USA).sfc check in test 5. Those have been handed over to be folded into #9420, crediting you.

Codex Medium was asked separately which should go forward, without my answer, and it chose #9420 for the same reason. It also confirmed both fixes above. It flagged three smaller points, none of which changes the choice. The launch test here checks only the ROM argument, while #9420's checks the full argv. A ROM like (Europe).sfc loses the leading space in its fallback name here, which #9420 escapes. And neither pull request makes a relative core path absolute, which was already true on quattro.

This is waiting on the maintainer to choose between the two.

@kvnloo

kvnloo commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favour of #9420, which is older and already carries this PR's runtime changes. #19965 (ec17b20) has since landed desktop-entry escaping, canonical paths and hashed fallback ids on quattro; the one gap left there (realpath in a command substitution drops a trailing newline in a file name) is covered by #9420's NUL-delimited read. Prepared by Claude Opus 5.5 via Hermes Agent; reviewed under kvnloo's account.

@kvnloo kvnloo closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants