Skip to content

file_system: a MAXIMUM_ALLOWED open is a write-open, so it cannot write the package (RT-229) - #3602

Merged
ItsNotRexed merged 2 commits into
ProjectLeonida:mainfrom
MrCheese5:claude/fs-maximum-allowed
Nov 23, 2026
Merged

ItsNotRexed merged 2 commits into
ProjectLeonida:mainfrom
MrCheese5:claude/fs-maximum-allowed

Conversation

@MrCheese5

Copy link
Copy Markdown
Contributor

RT-229 (claim)

AI-assisted (Claude Code). I ran everything under "Tested" on Windows.

Problem

docs/runtime_imports.md promises "The package is never written": an open that can write goes to the overlay. writes() in runtime/shims/file_system.cpp decides that from the access mask, and its mask had no MAXIMUM_ALLOWED. That bit names no right and grants every one the file allows, write included. So CreateFileW("GAME:\data\x", MAXIMUM_ALLOWED, ..., OPEN_EXISTING) was treated as a read, the shim handed out a handle to the package file itself, and a WriteFile through it changed the user's install. CreateFileA and CreateFile2 share the function.

Change

MAXIMUM_ALLOWED is in the write mask, so such an open gets the overlay copy like any other write-open (copy-up for OPEN_EXISTING). One constant and a comment; nothing else in the open path changes. The cost is a copy-up for a title that asks for MAXIMUM_ALLOWED and then only reads.

Test

file_system_test (synthetic folders in %TEMP%, no game files) opens a package file with MAXIMUM_ALLOWED through CreateFileW, CreateFileA (with GENERIC_READ added) and CreateFile2, writes through the handle, and checks that the package file still holds its bytes and the overlay copy holds the write. It also checks that a GENERIC_READ open still makes no overlay copy.

Tested

Windows 11 (build 26200), MSVC 19.44.35222, Visual Studio's CMake and ctest 3.31.6 with Ninja, RelWithDebInfo, built by scripts/build_runtime.ps1. Base f847748c (main).

  • file_system_test with the new checks on main's file_system.cpp: 4 failures of 142 (the package file was written and no overlay copy existed, for each of the three entry points). With the change: 142 checks, 0 failures.
  • ctest --test-dir runtime/build -C RelWithDebInfo with LEONIDA_GAME_DIR set: 140 run, 134 passed, 6 skipped, 0 failed (gameinput is disabled, no SDL3 here). NVIDIA GeForce RTX 4090, driver 32.0.16.2114, for the Vulkan tests in that run; this change needs no GPU.

#3063 and #2957 also edit file_system.cpp or its test; this touches neither's hunks (writes() and a new block after the CreateFile2 checks).

🤖 Generated with Claude Code

…te the package

writes() did not count MAXIMUM_ALLOWED as write access. CreateFileW/A and CreateFile2
then opened the package file itself, and a WriteFile through the handle changed the
package, which docs/runtime_imports.md says is never written. Such an open now gets
the overlay copy like any other write-open.

file_system_test: the three entry points, with the package bytes and the overlay
copy checked after a write; a plain read still makes no overlay copy.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At 0977b5d all 142 native Windows checks passed. Synthetic writes through CreateFileA/W/2 preserved the package and used the overlay. A scratch partial-overwrite fixture additionally verified preservation of the untouched suffix through all three APIs. Consider retaining that assertion. AI-assisted CPU validation.

@Kam471

Kam471 commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

Tested 0977b5dc7ed6638a6e13aa94df11149b5b601f7b on Windows 11, MSVC 19.44.35228 + Ninja, RelWithDebInfo.

  • file_system_test.exe -> 142 check(s), 0 failure(s), exit 0 (includes the 4 new MAXIMUM_ALLOWED cases).
  • ctest -R file_system --output-on-failure -> 1/1 passed, 0.12 s.

Private build dir; runtime/build untouched. No game files.

A two-byte write leaves the rest of the file to compare, so the test also shows the
overlay copy began as the package file's bytes (suggested in review).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@MrCheese5

Copy link
Copy Markdown
Contributor Author

Thanks both. Taken up in 75f1351 (test only): the write through each MAXIMUM_ALLOWED handle is now two bytes into a seven-byte file, and the checks expect the overlay copy to hold the two new bytes followed by the package file's untouched suffix, for CreateFileW, CreateFileA and CreateFile2. file_system_test: 142 checks, 0 failures on this head (focused run; the shim is unchanged since the full run in the description).

@kacper-serewis kacper-serewis left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At 75f1351 all 142 native Windows LLVM-MinGW checks passed. Across W/A/CreateFile2 the two-byte overwrite preserved the copied suffix and the package source. A scratch mutation creating an empty overlay instead made all three content assertions fail despite successful writes. AI-assisted CPU-only synthetic validation.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 75f1351 on Windows 11, MSVC (VS 2022 Build Tools) RelWithDebInfo, with RTX 5080 (driver 616.92) and AMD Radeon iGPU gfx1036 (driver 26.10.1) each selected in turn (LEONIDA_VK_DEVICE, VK_LOADER_LAYERS_DISABLE=~implicit~; the test itself needs no GPU): ctest -R "^file_system$" — pass, 1/1 per run, 142 check(s), 0 failure(s).

No negative control run.

AI-assisted.

@traeb0n

traeb0n commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested 0977b5d (on its base main f847748) on NVIDIA GeForce RTX 5070, driver 621.01, Windows 11 Pro (26300), MSVC 14.44 (VS 2022 Build Tools, Ninja, RelWithDebInfo), Vulkan SDK 1.4.363, LEONIDA_VK_VALIDATION=1: pass.

  • Build: exit 0.
  • ctest -E loader -j 4: 128/128 passed, as on main f847748 here.
  • file_system: passed.

AI-assisted (Claude Code).

@ItsNotRexed
ItsNotRexed merged commit edbaf7c into ProjectLeonida:main Nov 23, 2026
2 of 4 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.

6 participants