Skip to content

runtime: preserve LoadLibraryEx reserved-handle validation - #9689

Closed
tecnofifamobile-ai wants to merge 1 commit into
ProjectLeonida:mainfrom
tecnofifamobile-ai:fix/loadlibraryex-reserved-hfile
Closed

tecnofifamobile-ai wants to merge 1 commit into
ProjectLeonida:mainfrom
tecnofifamobile-ai:fix/loadlibraryex-reserved-hfile

Conversation

@tecnofifamobile-ai

Copy link
Copy Markdown

Claimed in the coordination issue as: LOADLIBRARYEX-RESERVED-HFILE

What and why

Windows reserves the hFile parameter of LoadLibraryExA/W. The coordination finding identified that the shim-owned and bundled lookup paths ignored it. A call with a non-null handle could return a pseudo-handle or map a bundled DLL before reaching the host.

On native Windows, both calls returned NULL with ERROR_INVALID_PARAMETER (87) when passed a real file handle. With the new fixture on base 5d74c272, the ANSI call reached the shim-owned module and the Unicode call mapped the bundled DLL. The test exited 1.

The patch limits name-based resolution to calls with null hFile. Calls with a non-null handle go directly to the corresponding Win32 API with all arguments preserved. The fixture covers both encodings and both lookup paths, verifies the rejected DLL stays unmapped, then exercises the existing null-handle load and its attach/export checks. Regression risk is confined to the handling of the reserved non-null argument.

Tested

Windows 11 build 26200, MSVC 19.51.36257.0, Windows SDK 10.0.28000.0, CMake 4.3.1-msvc1, x64 RelWithDebInfo. CPU-only for the regression. The related run_tiny_frame smoke test ran on Radeon RX 9070 XT, AMD 26.11.2, Windows driver 32.0.32029.2010.

From the repository root with a configured Windows build:

cmake --build runtime/build --config RelWithDebInfo --parallel 4 --target gta6rt tiny_bundled_load xgameruntime_test dll_thread_calls_test
ctest --test-dir runtime/build -C RelWithDebInfo --no-tests=error --output-on-failure -R '^(run_tiny_(bundled_load|gdk_load|async|frame|game|game_console_paths)|xgameruntime|dll_thread_calls|loader|pe_loader|loader_tls)$'
  • Baseline negative control: build the changed tiny_bundled_load fixture only and run ctest -R '^run_tiny_bundled_load$' with the baseline loader. The guest exits 1 after the invalid call reaches the shim. With the patched loader, all 11 selected CTests pass.
  • Direct native Win32 control on the same Windows build: both A/W calls return NULL / 87 with the source-built DLL opened for reading.
  • git diff --check, scripts/check_no_game_data.py and the repeated-lines and PR-template tests passed. The docs-link suite reported the same two unrelated relative-link failures in a clean baseline and in this branch.

Provenance: public Win32 A reference and W reference, plus a synthetic native/mapped comparison. Scope is the Win32 contract for a reserved argument. No retail files or console execution were used.

AI-assisted: yes (Codex).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (N/A, loader change.)

@tecnofifamobile-ai

Copy link
Copy Markdown
Author

Post-push verification of 06e507cafcbea2de1301d4c24b7422c48d12c555 against main@5d74c272: one commit, three files. The GitHub diff matches the tested tree. The two LoadLibraryEx guards preserve the original name and flag checks for null hFile; non-null hFile reaches host validation before any module lookup. The synthetic fixture rejects both invalid calls, verifies the DLL remains unmapped, and then checks the existing load-by-name path.

Local results: native Windows returned NULL / 87 for both A/W calls; the new fixture failed on the baseline loader and passed with this commit; 11/11 focused CTests passed. run_tiny_frame also passed with the RX 9070 XT explicitly selected. GitHub's Runtime, CI and No Game Data runs showed action_required with zero jobs at this check. No game files. AI-assisted (Codex).

@n-romanovich

Copy link
Copy Markdown

Tested 06e507caf on Windows 11 (MSVC 19.52, Windows SDK 10.0.26100.0, Vulkan SDK 1.4.363.0, NVIDIA GeForce RTX 5060 Ti 610.88): pass.

checked: #968906e507c | with: cmake --build runtime/build --config RelWithDebInfo --target gta6rt tiny_bundled_load loader_test pe_loader_test module_names_test && ctest --test-dir runtime/build -C RelWithDebInfo --output-on-failure -R "loader|module_names|bundled" | on: Windows 11, MSVC 19.52, NVIDIA GeForce RTX 5060 Ti (610.88) | result: 7/7 passed (loader, module_names, run_module_names, pe_loader, pe_loader_bounds, loader_tls, run_tiny_bundled_load), diff reviewed, synthetic inputs only, no game files. AI-assisted.

@IAmTheSween

Copy link
Copy Markdown

Tested 06e507caf on NVIDIA GeForce RTX 5070 (Blackwell), driver 32.0.16.2114, Windows 11, MSVC 14.44 (VS 2022), RelWithDebInfo: pass. Applied as a patch onto main 5d74c27 (together with #9670, which touches separate files).

run_tiny_bundled_load (the changed fixture) passes. loader, pe_loader, pe_loader_bounds, loader_tls and all the run_tiny_* tests also pass: 24/24 with -R "frame_pacer|loader|library|tiny".

AI-assisted run (Claude via OpenCode).

@sgonzalez-glitch

Copy link
Copy Markdown

Tested 06e507caf (as part of #9516, #9549, #9614, #9653, #9657, #9660, #9678 and #9689 merged together onto main 5d74c2723) on NVIDIA GeForce RTX 2080, driver 621.24 (32.0.16.2124), Windows 11, MSVC 19.44 RelWithDebInfo: pass.

AI-assisted: yes

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.

5 participants