More fixes discovered based on Deedra's work.

This commit is contained in:
Storm Dragon committed 2026-10-23 16:08:58 -04:00
1 parent de31e5b513
commit 17052c5147
22 files changed
+561 -76

No files matched your search

+60 -11
View File
@@ -4,6 +4,7 @@
#include "native_query.h"
#include "review_x11.h"
#include "review_query.h"
#include "edit_hook.h"
#include <commctrl.h>
#include <cstring>
#include <oleacc.h>
@@ -21,6 +22,7 @@ constexpr DWORD wine_virtual_desktop = 0x80000000;
// Wine's import libraries do not export this IID as a Unix data symbol.
constexpr GUID accessible_iid{0x618736e0,0x3c3d,0x11cf,{0x81,0x0c,0x00,0xaa,0x00,0x38,0x9b,0x71}};
constexpr size_t max_source = 1000000, max_text = 1048576, max_nodes = 4096;
constexpr size_t max_unhooked_text = 16384;
std::string utf8(const WCHAR *text, size_t length) {
if (!length) return {};
int size = WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, text,
@@ -56,8 +58,46 @@ bool remote_query(HWND window, UINT message, WPARAM wp, LPARAM lp,
return GetTickCount64() < deadline;
}
bool password(HWND window);
bool read_hooked_edit(HWND window, uint64_t deadline, size_t limit,
std::vector<WCHAR> &text, bool &limited) {
DWORD_PTR answer = 0;
const UINT message = RegisterWindowMessageW(EDIT_REVIEW_MESSAGE);
// The foreground thread's message hook can attach an output editor that
// has never received keyboard focus. First send a scalar attachment probe;
// the following query then enters the newly installed subclass reliably.
if (!GetPropW(window, EDIT_REVIEW_PROPERTY) &&
(!query(window, message, 0, 0, deadline, answer) ||
!GetPropW(window, EDIT_REVIEW_PROPERTY))) return false;
const size_t offset = offsetof(WineAccessEditText, text);
const size_t bytes = offset + (limit + 1) * sizeof(WCHAR);
native_control::RemoteBuffer remote(window, bytes);
if (!remote) return false;
WineAccessEditText request{};
request.capacity = limit + 1;
if (!remote.write(&request, offset) ||
!remote_query(window, message, 0,
remote.address(), deadline, answer) ||
!remote.read(&request, offset) || password(window)) return false;
if (request.status == 2) { limited = true; return false; }
if (request.status != 1 || request.copied > limit) return false;
text.assign(request.copied + 1, 0);
if (!remote.read(text.data(), text.size() * sizeof(WCHAR), offset) || text.back()) return false;
text.resize(request.copied);
return true;
}
bool read_text(HWND window, uint64_t deadline, size_t limit, std::vector<WCHAR> &text,
bool &limited) {
if (password(window)) return false;
if (GetPropW(window, EDIT_REVIEW_PROPERTY))
return read_hooked_edit(window, deadline, limit, text, limited);
WCHAR class_name[128]{};
if (GetClassNameW(window, class_name, 128) && wine_access_class_matches(class_name, L"Edit")) {
if (read_hooked_edit(window, deadline, limit, text, limited)) return true;
if (limited || GetPropW(window, EDIT_REVIEW_PROPERTY)) return false;
}
// Unhooked/older editors cannot service the safe native query. Keep their
// ordinary WM_GETTEXT requests far below Wine's callback-stack limit.
limit = std::min(limit, max_unhooked_text);
DWORD_PTR size = 0, copied = 0;
if (password(window) || !query(window, WM_GETTEXTLENGTH, 0, 0, deadline, size) || password(window)) return false;
if (size > limit) { limited = true; return false; }
@@ -69,6 +109,23 @@ bool read_text(HWND window, uint64_t deadline, size_t limit, std::vector<WCHAR>
text.resize(size);
return true;
}
bool reread_text(HWND window, uint64_t deadline, size_t size, std::vector<WCHAR> &text) {
if (password(window)) return false;
if (GetPropW(window, EDIT_REVIEW_PROPERTY)) {
bool limited = false;
return read_hooked_edit(window, deadline, size, text, limited);
}
if (size > max_unhooked_text) return false;
// The original source already supplies a safe capacity. Avoid another
// length/attachment round trip on frame-based applications.
text.assign(size + 1, 0);
DWORD_PTR copied = 0, after = 0;
if (!query(window, WM_GETTEXT, text.size(), reinterpret_cast<LPARAM>(text.data()), deadline, copied) ||
password(window) || !query(window, WM_GETTEXTLENGTH, 0, 0, deadline, after) ||
password(window) || copied != size || after != size) return false;
text.resize(size);
return true;
}
std::string caption(HWND window) {
// A foreign window's caption is held by USER32. Sending WM_GETTEXT here
// could deadlock against an editor hook currently sending WM_COPYDATA to
@@ -815,17 +872,9 @@ ReviewCapture capture_review_window(ReviewIdentityStore &store, const ReviewFocu
RECT bounds{};
if (password(read.window) || !IsWindowVisible(read.window) || !GetWindowRect(read.window, &bounds) ||
!EqualRect(&read.bounds, &bounds)) { capture.fail("stale"); break; }
if (read.text.size() > max_source - capture.source_units) { capture.fail("limited"); break; }
capture.source_units += read.text.size();
// The first read already supplies a bounded capacity. Copy once, then
// verify length, content and protection without another preliminary
// length round trip (growth must still reject a truncated old prefix).
current.assign(read.text.size()+1,0);
DWORD_PTR copied=0,length=0;
if(!query(read.window,WM_GETTEXT,current.size(),reinterpret_cast<LPARAM>(current.data()),deadline,copied) ||
password(read.window) || !query(read.window,WM_GETTEXTLENGTH,0,0,deadline,length) ||
password(read.window) || copied!=read.text.size() || length!=read.text.size())capture.fail("stale");
current.resize(read.text.size());
// This is a second copy of an already budgeted source, not another
// document. Charging it twice made large safe snapshots fail review.
if (!reread_text(read.window, deadline, read.text.size(), current)) capture.fail("stale");
if(current!=read.text)capture.fail("stale");
if (read.layout && !capture.failed) {
EditLayout layout{};