winhttp_offline: an empty server name and a context option of the wrong size fail as on the host (WINHTTP-ARG-CHECKS) #2383

Closed
syfyra wants to merge 1 commit from upstream-pr/2383 into main
syfyra commented 2026-11-26 16:43:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by syfyra on 2026-11-26T16:43:26Z.


Claimed in the coordination issue as: WINHTTP-ARG-CHECKS

What and why

I compared the offline WinHTTP shim with the host's winhttp.dll on the calls that need no network: handles, options, timeouts and the argument checks. A small ctypes probe ran on Windows 11 against .invalid names, with no request sent. Two answers differ:

call host winhttp.dll shim on main
WinHttpConnect(session, L"", 80, 0) ERROR_WINHTTP_INVALID_URL (12005) ERROR_INVALID_PARAMETER (87)
WinHttpConnect(session, nullptr, 80, 0) ERROR_INVALID_PARAMETER ERROR_INVALID_PARAMETER
WinHttpSetOption(h, WINHTTP_OPTION_CONTEXT_VALUE, buf, 4) ERROR_INSUFFICIENT_BUFFER ERROR_INSUFFICIENT_BUFFER
WinHttpSetOption(h, WINHTTP_OPTION_CONTEXT_VALUE, buf, 16) ERROR_INSUFFICIENT_BUFFER succeeds and takes the first 8 bytes

Everything else in the probe already matched:

  • the context value's query and its size answer;
  • WinHttpConnect on a connect handle and WinHttpOpenRequest on a session (ERROR_WINHTTP_INCORRECT_HANDLE_TYPE);
  • a negative timeout;
  • WinHttpCloseHandle of NULL and of a closed handle;
  • the context option on a NULL handle.

Both are fixed: an empty server name now fails with ERROR_WINHTTP_INVALID_URL, and the context option takes exactly sizeof(DWORD_PTR) and leaves the handle's context as it was otherwise.

Not changed: the shim still accepts options it does not know (the host refuses an unknown option number with ERROR_WINHTTP_INVALID_OPTION). The file's header says options are accepted on purpose, and matching the host there would need the host's list of options per handle type.

Tested

Windows 11, MSVC 14.44 (Build Tools), RelWithDebInfo:

  • winhttp_offline_test gets three checks: a 16-byte context value fails with ERROR_INSUFFICIENT_BUFFER, the context set before it stays, and an empty server name fails with ERROR_WINHTTP_INVALID_URL.
    • main: 3 of 86 checks fail.
    • this branch: 86 of 86 pass.
  • No other open pull request changes these two files (scripts/pr_overlap.py from #2349).
  • scripts/check_no_game_data.py on both files.

Not tested under Wine.

GPUs tested: n/a (CPU tests)

AI-assisted: yes (Claude Code, Claude Opus 5.5)

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • 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: no translator change)

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5513884153 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2383). Originally posted by [syfyra](https://github.com/syfyra) on 2026-11-26T16:43:26Z. --- Claimed in the coordination issue as: WINHTTP-ARG-CHECKS ### What and why I compared the offline WinHTTP shim with the host's `winhttp.dll` on the calls that need no network: handles, options, timeouts and the argument checks. A small ctypes probe ran on Windows 11 against `.invalid` names, with no request sent. Two answers differ: | call | host `winhttp.dll` | shim on `main` | |---|---|---| | `WinHttpConnect(session, L"", 80, 0)` | `ERROR_WINHTTP_INVALID_URL` (12005) | `ERROR_INVALID_PARAMETER` (87) | | `WinHttpConnect(session, nullptr, 80, 0)` | `ERROR_INVALID_PARAMETER` | `ERROR_INVALID_PARAMETER` | | `WinHttpSetOption(h, WINHTTP_OPTION_CONTEXT_VALUE, buf, 4)` | `ERROR_INSUFFICIENT_BUFFER` | `ERROR_INSUFFICIENT_BUFFER` | | `WinHttpSetOption(h, WINHTTP_OPTION_CONTEXT_VALUE, buf, 16)` | `ERROR_INSUFFICIENT_BUFFER` | succeeds and takes the first 8 bytes | Everything else in the probe already matched: - the context value's query and its size answer; - `WinHttpConnect` on a connect handle and `WinHttpOpenRequest` on a session (`ERROR_WINHTTP_INCORRECT_HANDLE_TYPE`); - a negative timeout; - `WinHttpCloseHandle` of `NULL` and of a closed handle; - the context option on a `NULL` handle. Both are fixed: an empty server name now fails with `ERROR_WINHTTP_INVALID_URL`, and the context option takes exactly `sizeof(DWORD_PTR)` and leaves the handle's context as it was otherwise. Not changed: the shim still accepts options it does not know (the host refuses an unknown option number with `ERROR_WINHTTP_INVALID_OPTION`). The file's header says options are accepted on purpose, and matching the host there would need the host's list of options per handle type. ### Tested Windows 11, MSVC 14.44 (Build Tools), RelWithDebInfo: - `winhttp_offline_test` gets three checks: a 16-byte context value fails with `ERROR_INSUFFICIENT_BUFFER`, the context set before it stays, and an empty server name fails with `ERROR_WINHTTP_INVALID_URL`. - `main`: 3 of 86 checks fail. - this branch: 86 of 86 pass. - No other open pull request changes these two files (`scripts/pr_overlap.py` from #2349). - `scripts/check_no_game_data.py` on both files. Not tested under Wine. GPUs tested: n/a (CPU tests) AI-assisted: yes (Claude Code, Claude Opus 5.5) ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] 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: no translator change) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
fiestorra commented 2026-11-30 10:37:53 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-11-30T10:37:53Z.


Independent verification on this machine (Windows 11, MSVC 19.44.35226), with a negative control that bites on two assertions.

1. It applies. merge-tree clean; the commits cherry-pick onto main 012b79a67 without a conflict. Two files: runtime/shims/winhttp_offline.cpp and runtime/test/winhttp_offline_test.cpp.

2. With the branch its test passes:

ctest -R 'winhttp_offline'
100% tests passed, 0 tests failed out of 1

3. The control - revert only the shim, keep the test:

git checkout origin/main -- runtime/shims/winhttp_offline.cpp
cmake --build … --target winhttp_offline_test
ctest -R 'winhttp_offline' --output-on-failure
0% tests passed, 1 tests failed out of 1
FAIL a 16-byte WINHTTP_OPTION_CONTEXT_VALUE fails with ERROR_INSUFFICIENT_BUFFER too, as on the host
FAIL and the context set before stays

Both failures name the rule the change adds: querying WINHTTP_OPTION_CONTEXT_VALUE with a 16-byte buffer must fail with ERROR_INSUFFICIENT_BUFFER on the 64-bit path as well, and the context set before must survive the failed query. That second assertion is the one worth noting - the change is not only about the error code, it is about not losing state when the query is refused.

What I did not test: the rest of the offline WinHTTP surface, and whether the host (a real winhttp.dll) behaves the same way on the 32-bit path.

Why I am commenting: I verify open pull requests that replay onto current main, then revert only the source change and re-run. 22 controls so far: 15 bite.

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7275864592 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2383#issuecomment-7275864592). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-11-30T10:37:53Z. --- Independent verification on this machine (Windows 11, MSVC 19.44.35226), with a negative control that bites on two assertions. **1. It applies.** `merge-tree` clean; the commits cherry-pick onto `main` `012b79a67` without a conflict. Two files: `runtime/shims/winhttp_offline.cpp` and `runtime/test/winhttp_offline_test.cpp`. **2. With the branch its test passes:** ``` ctest -R 'winhttp_offline' 100% tests passed, 0 tests failed out of 1 ``` **3. The control - revert only the shim, keep the test:** ``` git checkout origin/main -- runtime/shims/winhttp_offline.cpp cmake --build … --target winhttp_offline_test ctest -R 'winhttp_offline' --output-on-failure 0% tests passed, 1 tests failed out of 1 FAIL a 16-byte WINHTTP_OPTION_CONTEXT_VALUE fails with ERROR_INSUFFICIENT_BUFFER too, as on the host FAIL and the context set before stays ``` **Both failures name the rule the change adds**: querying `WINHTTP_OPTION_CONTEXT_VALUE` with a 16-byte buffer must fail with `ERROR_INSUFFICIENT_BUFFER` **on the 64-bit path as well**, and **the context set before must survive the failed query**. That second assertion is the one worth noting - the change is not only about the error code, it is about not losing state when the query is refused. **What I did not test:** the rest of the offline WinHTTP surface, and whether the host (a real `winhttp.dll`) behaves the same way on the 32-bit path. **Why I am commenting:** I verify open pull requests that replay onto current `main`, then revert **only** the source change and re-run. **22 controls so far: 15 bite.** Written with an AI assistant.
aslan2142 commented 2026-12-01 12:34:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T12:34:32Z.


Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review.

(AI-assisted triage.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7311337779 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2383#issuecomment-7311337779). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T12:34:32Z. --- Marking Ready for Review since no WIP/blocker reason for draft status is specified on this PR, so it can enter normal CI and review. *(AI-assisted triage.)*
aslan2142 commented 2026-12-01 16:44:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T16:44:26Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7318137498 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2383#issuecomment-7318137498). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T16:44:26Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2383
No description provided.