From patchwork Fri Mar 4 00:57:45 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roland Dreier X-Patchwork-Id: 85359 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 99F29B70CD for ; Fri, 4 Mar 2011 11:59:25 +1100 (EST) Received: from localhost ([127.0.0.1]:46392 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PvJMY-0006ts-Uk for incoming@patchwork.ozlabs.org; Thu, 03 Mar 2011 19:59:22 -0500 Received: from [140.186.70.92] (port=53984 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PvJL9-000680-HR for qemu-devel@nongnu.org; Thu, 03 Mar 2011 19:57:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PvJL8-0003Qi-Dr for qemu-devel@nongnu.org; Thu, 03 Mar 2011 19:57:55 -0500 Received: from na3sys010aog104.obsmtp.com ([74.125.245.76]:43143) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1PvJL8-0003QQ-34 for qemu-devel@nongnu.org; Thu, 03 Mar 2011 19:57:54 -0500 Received: from source ([209.85.213.49]) (using TLSv1) by na3sys010aob104.postini.com ([74.125.244.12]) with SMTP ID DSNKTXA5Dhz7av6uNb44mG5Hto96ykOhbtRH@postini.com; Thu, 03 Mar 2011 16:57:53 PST Received: by mail-yw0-f49.google.com with SMTP id 8so623819ywa.36 for ; Thu, 03 Mar 2011 16:57:50 -0800 (PST) Received: by 10.236.184.197 with SMTP id s45mr5143yhm.17.1299200270648; Thu, 03 Mar 2011 16:57:50 -0800 (PST) Received: from localhost.localdomain ([209.118.183.82]) by mx.google.com with ESMTPS id i10sm1190839yhd.10.2011.03.03.16.57.49 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 03 Mar 2011 16:57:50 -0800 (PST) From: Roland Dreier To: Anthony Liguori Date: Thu, 3 Mar 2011 16:57:45 -0800 Message-Id: <1299200265-32685-1-git-send-email-roland@kernel.org> X-Mailer: git-send-email 1.7.4.1 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 74.125.245.76 Cc: Roland Dreier , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH] vnc: tight: Fix crash after 2GB of output X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Roland Dreier If one leaves a VNC session with tight compression running for long enough, Qemu crashes. This is because of the computation bytes = zstream->total_out - previous_out; in tight_compress_data, where zstream->total_out is a uLong but previous_out is an int. As soon as zstream->total_out gets past INT_MAX (ie 2GB), previous_out becomes negative and therefore the result of the subtraction, bytes, becomes a huge positive number that causes havoc for obvious reasons when passed as a length to vnc_write(). The fix for this is simple: keep previous_out as a uLong too, which avoids any problems with sign conversion or truncation. Signed-off-by: Roland Dreier --- ui/vnc-enc-tight.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/ui/vnc-enc-tight.c b/ui/vnc-enc-tight.c index af45edd..59ec0e3 100644 --- a/ui/vnc-enc-tight.c +++ b/ui/vnc-enc-tight.c @@ -829,7 +829,7 @@ static int tight_compress_data(VncState *vs, int stream_id, size_t bytes, int level, int strategy) { z_streamp zstream = &vs->tight.stream[stream_id]; - int previous_out; + uLong previous_out; if (bytes < VNC_TIGHT_MIN_TO_COMPRESS) { vnc_write(vs, vs->tight.tight.buffer, vs->tight.tight.offset);