diff --git a/libs/clipboard/src/windows/wf_cliprdr.c b/libs/clipboard/src/windows/wf_cliprdr.c
index 497cafa5b..2cd099545 100644
--- a/libs/clipboard/src/windows/wf_cliprdr.c
+++ b/libs/clipboard/src/windows/wf_cliprdr.c
@@ -57,8 +57,9 @@
/* File lists kept after they were sent, so a transfer still in flight keeps reading its own
* files after a later copy or paste replaces them. */
#define WF_CLIPRDR_SERVED_FILE_LISTS 4u
-/* Largest range the unix file server serves in one request (MAX_RANGE_READ in
- * serv_files.rs); larger IStream reads are split into requests of this size. */
+/* Largest range served in one request: by the unix file server (MAX_RANGE_READ in
+ * serv_files.rs) and by the served-list path here. Larger IStream reads are split into
+ * requests of this size. */
#define WF_CLIPRDR_MAX_RANGE_READ (16u * 1024u * 1024u)
static const WCHAR WF_CLIPRDR_SUPERSCRIPT_DIGITS[] = L"\x00B9\x00B2\x00B3";
static const WCHAR WF_CLIPRDR_INVALID_FILE_NAME_CHARS[] = L"<>:\"|?*";
@@ -3658,6 +3659,12 @@ wf_cliprdr_server_file_contents_request(CliprdrClientContext *context,
is_set_by_instance(clipboard) || is_file_descriptor_from_remote()))
{
ZeroMemory(&vStgMedium, sizeof(STGMEDIUM)); // read at exit
+ // Clients that send an id split reads to WF_CLIPRDR_MAX_RANGE_READ; refuse anything
+ // else before allocating what the peer asked for.
+ if (fileContentsRequest->dwFlags != FILECONTENTS_SIZE &&
+ (fileContentsRequest->dwFlags != FILECONTENTS_RANGE ||
+ fileContentsRequest->cbRequested > WF_CLIPRDR_MAX_RANGE_READ))
+ goto exit;
cbRequested = fileContentsRequest->dwFlags == FILECONTENTS_SIZE
? sizeof(UINT64)
: fileContentsRequest->cbRequested;
diff --git a/libs/enigo/src/win/win_impl.rs b/libs/enigo/src/win/win_impl.rs
index da31e7005..5506b4c95 100644
--- a/libs/enigo/src/win/win_impl.rs
+++ b/libs/enigo/src/win/win_impl.rs
@@ -39,14 +39,15 @@ fn mouse_event(flags: u32, data: u32, dx: i32, dy: i32) -> DWORD {
unsafe { SendInput(1, &mut input as LPINPUT, size_of::() as c_int) }
}
-// `v` comes from the remote peer unchecked, so scale in i64 to avoid overflow.
+// `v` comes from the remote peer unchecked, so scale in i64 to avoid overflow, and clamp to
+// the 0..=65535 range MOUSEEVENTF_ABSOLUTE takes.
// `extent` is 0 when the virtual screen metrics are unavailable.
fn to_absolute(v: i32, origin: i32, extent: i32) -> Option {
if extent <= 0 {
return None;
}
let abs = (v as i64 - origin as i64) * 65535 / extent as i64;
- Some(abs.clamp(i32::MIN as i64, i32::MAX as i64) as i32)
+ Some(abs.clamp(0, 65535) as i32)
}
fn keybd_event(mut flags: u32, vk: u16, scan: u16) -> DWORD {