diff --git a/windows/defwnd.c b/windows/defwnd.c
index b12c75681afef9045b44875e386eead6212b48e1..d56404c8c7d317f331c2ef36877f9abd6b0905ce 100644
--- a/windows/defwnd.c
+++ b/windows/defwnd.c
@@ -75,13 +75,15 @@ static void DEFWND_SetTextA( HWND hwnd, LPCSTR text )
     if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
     if ((textW = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
     {
+        size_t len = min( REQUEST_MAX_VAR_SIZE, (count-1) * sizeof(WCHAR) );
+
         if (wndPtr->text) HeapFree(GetProcessHeap(), 0, wndPtr->text);
         wndPtr->text = textW;
         MultiByteToWideChar( CP_ACP, 0, text, -1, textW, count );
-        SERVER_START_VAR_REQ( set_window_text, (count-1) * sizeof(WCHAR) )
+        SERVER_START_VAR_REQ( set_window_text, len )
         {
             req->handle = hwnd;
-            memcpy( server_data_ptr(req), textW, (count-1) * sizeof(WCHAR) );
+            memcpy( server_data_ptr(req), textW, len );
             SERVER_CALL();
         }
         SERVER_END_VAR_REQ;
@@ -111,11 +113,13 @@ static void DEFWND_SetTextW( HWND hwnd, LPCWSTR text )
     if (wndPtr->text) HeapFree(GetProcessHeap(), 0, wndPtr->text);
     if ((wndPtr->text = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
     {
+        size_t len = min( REQUEST_MAX_VAR_SIZE, (count-1) * sizeof(WCHAR) );
+
         strcpyW( wndPtr->text, text );
-        SERVER_START_VAR_REQ( set_window_text, (count-1) * sizeof(WCHAR) )
+        SERVER_START_VAR_REQ( set_window_text, len )
         {
             req->handle = hwnd;
-            memcpy( server_data_ptr(req), wndPtr->text, (count-1) * sizeof(WCHAR) );
+            memcpy( server_data_ptr(req), wndPtr->text, len );
             SERVER_CALL();
         }
         SERVER_END_VAR_REQ;