From c156e77c46ed51a378dd55493c42fd914a70ba4d Mon Sep 17 00:00:00 2001 From: c4k3ss <77441265+c4k3ss@users.noreply.github.com> Date: Mon, 23 Nov 2026 19:54:38 +0200 Subject: [PATCH 1/2] xgameruntime: XPersistentLocalStorageGetPath reports the required size on a short buffer (RT-712) The (size, buffer, used) convention of the XSystem id getters: a short buffer learns the path length with its NUL in *path_used, the buffer stays untouched, the HRESULT is unchanged. Co-Authored-By: Claude Mythos 5.2 --- runtime/shims/xgameruntime.cpp | 6 +++++- runtime/test/xgameruntime_test.cpp | 9 +++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/runtime/shims/xgameruntime.cpp b/runtime/shims/xgameruntime.cpp index 2b44229be4..eeff9e6e13 100644 --- a/runtime/shims/xgameruntime.cpp +++ b/runtime/shims/xgameruntime.cpp @@ -522,7 +522,11 @@ HRESULT STDMETHODCALLTYPE pls_get_path(void*, size_t path_size, char* path, size if (!path) return E_POINTER; const std::string folder = utf8_of(persistent_storage_dir().native()); if (folder.empty()) return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND); - if (path_size < folder.size() + 1) return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); + if (path_size < folder.size() + 1) { + // The (size, buffer, used) convention of the XSystem id getters: a short buffer learns the size it needs. + if (path_used) *path_used = folder.size() + 1; + return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); + } std::memcpy(path, folder.c_str(), folder.size() + 1); if (path_used) *path_used = folder.size() + 1; return S_OK; diff --git a/runtime/test/xgameruntime_test.cpp b/runtime/test/xgameruntime_test.cpp index af67045d42..0cba9ebd4c 100644 --- a/runtime/test/xgameruntime_test.cpp +++ b/runtime/test/xgameruntime_test.cpp @@ -579,8 +579,13 @@ void check_run_time_load() { char tiny[2] = {'x', 'x'}; used = 99; check(reinterpret_cast(slot(pls, 4))(pls, 2, tiny, &used) == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) && - used == 0, - "slot 4 refuses a buffer that is too small"); + used == size && tiny[0] == 'x' && tiny[1] == 'x', + "slot 4 refuses a buffer that is too small, reports the size it needs and leaves the buffer alone"); + check(reinterpret_cast(slot(pls, 4))(pls, size - 1, path.data(), &used) == + HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER) && used == size, + "slot 4 reports the size for a buffer one byte short"); + check(reinterpret_cast(slot(pls, 4))(pls, 2, tiny, nullptr) == HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER), + "slot 4 tolerates a null used pointer on a short buffer"); { std::ofstream cache_file(folder / L"cache.bin", std::ios::binary); From d72a0c9f50419c80da626afb7fd8f2bccdf7992c Mon Sep 17 00:00:00 2001 From: c4k3ss <77441265+c4k3ss@users.noreply.github.com> Date: Tue, 24 Nov 2026 19:53:39 +0200 Subject: [PATCH 2/2] xgameruntime: correct the pls_get_path short-buffer comment The XSystem id getters (XSystemGetConsoleId, copy_id) return ERROR_INSUFFICIENT_BUFFER without setting *used, so they are not the precedent the comment named. Say what the code does instead: the buffer is untouched and *path_used gets the path length with its NUL, the value slot 3 (pls_get_path_size) reports. Comment only, no behavior change. Noted by moffington in review. Co-Authored-By: Claude Opus 5.5 --- runtime/shims/xgameruntime.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/shims/xgameruntime.cpp b/runtime/shims/xgameruntime.cpp index eeff9e6e13..d79021afa1 100644 --- a/runtime/shims/xgameruntime.cpp +++ b/runtime/shims/xgameruntime.cpp @@ -523,7 +523,7 @@ HRESULT STDMETHODCALLTYPE pls_get_path(void*, size_t path_size, char* path, size const std::string folder = utf8_of(persistent_storage_dir().native()); if (folder.empty()) return HRESULT_FROM_WIN32(ERROR_PATH_NOT_FOUND); if (path_size < folder.size() + 1) { - // The (size, buffer, used) convention of the XSystem id getters: a short buffer learns the size it needs. + // A short buffer is left untouched but learns the size it needs: the path with its NUL, as slot 3 reports. if (path_used) *path_used = folder.size() + 1; return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); }