3 Commits
Author SHA1 Message Date
Storm Dragon 17052c5147 More fixes discovered based on Deedra's work. 2026-10-23 16:08:58 -04:00
deedra e962fd0a78 Avoid callback stack overflow when snapshotting large Edit controls
Reading a large ANSI Edit control through GetWindowTextW sends a
WM_GETTEXT buffer through WH_CALLWNDPROC. Wine copies that UTF-16 buffer
onto the application's callback stack, exhausting a 1 MiB stack at about
516,000 code units and potentially leaving an exception status in the
cached snapshot length.

Query WM_GETTEXTLENGTH and WM_GETTEXT through the current window procedure
with CallWindowProcW instead. This avoids the message-hook buffer copy
while preserving ANSI/Unicode conversion and the application's subclass
chain. Reenter the busy accessibility subclass rather than calling
DefSubclassProc directly, which can consume callbacks needed to forward
the original edit message. Reject negative or oversized copy results and
discard the unusable buffer before its length can be used for indexing.

Extend the native hook-safety fixture for both 32-bit and 64-bit DLLs:
- Reserve a 1 MiB PE stack and install a real WH_CALLWNDPROC hook.
- Replace ANSI text with 516,000, 600,000 and 1,040,000 characters and
  verify the complete UTF-16 snapshot, its length and its terminator.
- Use short lines to avoid excessive paragraph-layout time.
- Keep a lower subclass installed and verify that the original text
  replacement still reaches it exactly once during the reentrant probe.

Document the reproduction, why direct hook invocation alone misses it,
and the remaining distinction between fixture coverage and live
MUSHclient acceptance.

Validation:
- Synchronized deedra with its upstream and origin/master; both were
  already up to date.
- cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=winelib-toolchain.cmake
- cmake --build build --parallel: passed.
- git diff --check: passed.
- xvfb-run -a ctest --test-dir build --output-on-failure: interrupted
  at the user's request to skip tests. Foreground-focus, msaa-states,
  review-capture64 and review-capture32 passed before interruption;
  hook-safety had started but has no completed result from this run.
- Further integration tests were skipped at the user's request.

Live MUSHclient behavior, audible speech and physical braille remain
unverified by this commit session. Human review and submission remain
the contributor's responsibility under the README policy.
2026-10-23 09:24:36 -07:00
deedra 3474bb39c7 Bound native hook stack use and scope hooks to foreground threads
Ignored and reentrant Edit messages previously entered a callback whose
large text buffers increased stack use on every nested call. Menu hook
forwarding also reserved payload buffers for unrelated messages. The
64-bit helper additionally installed desktop-wide hooks, allowing
background UI threads to acquire subclasses and introducing synchronous
traffic through Wine's mixed-architecture global hook chain.

Move Edit processing and menu payload construction into non-inlined
handlers. Keep the forwarding callbacks small, retain the busy-state and
destruction guards, and preserve application subclass chaining and ANSI/
Unicode text handling.

Share foreground hook ownership between the Winelib helper and 32-bit
host. Attach both hooks only to the matching foreground UI thread,
release them when that thread changes, and retry incomplete attachment
as a pair. Preserve existing Edit subclasses across foreground changes
and release host hooks during shutdown.

Add native 32-bit and 64-bit stack-budget fixtures covering ignored and
busy reentrant messages, menu forwarding, nested text queries, application
subclasses before and after attachment, text input, and destruction during
a text change. Add a foreground-scope integration fixture that verifies
background exclusion, thread switching, detachment, and reattachment.
Keep hook debug symbols and frame pointers for native crash diagnosis,
and document installation and live acceptance requirements.

Validation:
- CMake configure and parallel build; git diff --check.
- Hook-safety CTest and foreground-scope fixtures for both architectures.
- Existing menu fixtures and Edit late-attachment/restart checks for both
  architectures, plus the 32-bit list fixture and reader-timeout test.

These checks exercise specific stack and hook-scope defects; they do not
establish the cause of the live MUSHclient stack overflow. Audible speech,
physical braille, and live MUSHclient acceptance remain separate checks.
2026-10-19 18:35:57 -07:00