[client] spice: fix clipboard transfer accounting

This commit is contained in:
Geoffrey McRae
2026-07-28 13:00:38 +10:00
parent 49b7f50c6b
commit 67e2675afa

View File

@@ -279,11 +279,19 @@ void app_clipboardNotifySize(const LG_ClipboardData type, size_t size)
return; return;
} }
g_state.cbType = cb_lgTypeToSpiceType(type); const PSDataType spiceType = cb_lgTypeToSpiceType(type);
g_state.cbChunked = size > 0; if (spiceType == SPICE_DATA_NONE)
g_state.cbXfer = size; return;
purespice_clipboardDataStart(g_state.cbType, size); if (!purespice_clipboardDataStart(spiceType, size))
{
DEBUG_ERROR("Failed to start a %zu-byte SPICE clipboard transfer", size);
return;
}
g_state.cbType = spiceType;
g_state.cbChunked = true;
g_state.cbXfer = size;
} }
void app_clipboardData(const LG_ClipboardData type, uint8_t * data, size_t size) void app_clipboardData(const LG_ClipboardData type, uint8_t * data, size_t size)
@@ -291,17 +299,53 @@ void app_clipboardData(const LG_ClipboardData type, uint8_t * data, size_t size)
if (!g_params.clipboardToVM) if (!g_params.clipboardToVM)
return; return;
if (g_state.cbChunked && size > g_state.cbXfer) const PSDataType spiceType = cb_lgTypeToSpiceType(type);
if (spiceType == SPICE_DATA_NONE)
return;
if (size && !data)
{ {
DEBUG_ERROR("refusing to send more then cbXfer bytes for chunked xfer"); DEBUG_ERROR("SPICE clipboard data is NULL");
size = g_state.cbXfer; return;
} }
if (!g_state.cbChunked) if (g_state.cbChunked)
purespice_clipboardDataStart(g_state.cbType, size); {
if (spiceType != g_state.cbType)
{
DEBUG_ERROR("SPICE clipboard transfer type changed");
return;
}
if (size > g_state.cbXfer)
{
DEBUG_ERROR("SPICE clipboard chunk exceeds the remaining transfer size");
return;
}
if (size && !purespice_clipboardData(spiceType, data, size))
{
DEBUG_ERROR("Failed to send SPICE clipboard data");
return;
}
purespice_clipboardData(g_state.cbType, data, (uint32_t)size);
g_state.cbXfer -= size; g_state.cbXfer -= size;
if (g_state.cbXfer == 0)
{
g_state.cbType = SPICE_DATA_NONE;
g_state.cbChunked = false;
}
return;
}
if (!purespice_clipboardDataStart(spiceType, size))
{
DEBUG_ERROR("Failed to start a %zu-byte SPICE clipboard transfer", size);
return;
}
if (size && !purespice_clipboardData(spiceType, data, size))
DEBUG_ERROR("Failed to send SPICE clipboard data");
} }
void app_clipboardRequest(const LG_ClipboardReplyFn replyFn, void * opaque) void app_clipboardRequest(const LG_ClipboardReplyFn replyFn, void * opaque)