Received: from [140.186.70.92] (port=60573 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OORH8-00063j-2h for qemu-devel@nongnu.org; Tue, 15 Jun 2010 04:13:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OORH6-0000lk-Js for qemu-devel@nongnu.org; Tue, 15 Jun 2010 04:13:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:17490) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OORH6-0000lW-D7 for qemu-devel@nongnu.org; Tue, 15 Jun 2010 04:13:36 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o5F8DYjj003447 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 15 Jun 2010 04:13:34 -0400 From: Markus Armbruster Subject: Re: [Qemu-devel] [RfC PATCH] Fix vnc memory corruption with width = 1400 References: <1276529747-22891-1-git-send-email-kraxel@redhat.com> Date: Tue, 15 Jun 2010 10:13:31 +0200 In-Reply-To: <1276529747-22891-1-git-send-email-kraxel@redhat.com> (Gerd Hoffmann's message of "Mon, 14 Jun 2010 17:35:47 +0200") Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gerd Hoffmann Cc: qemu-devel@nongnu.org Gerd Hoffmann writes: > vnc assumes that the screen width is a multiple of 16 in several places. > If this is not the case vnc will overrun buffers, corrupt memory, make > qemu crash. > > This is the minimum fix for this bug. It makes sure we don't overrun the > scanline, thereby fixing the segfault. The rendering is *not* correct > though, there is a black border at the right side of the screen, 8 > pixels wide because 1400 % 16 == 8. > > > Not sure what the best way to fix that for real is. qemu allways sends > updates which are 16 (or a multiple of 16) pixels wide. I'm not sure > whenever this is something specified in the protocol or just in the qemu > implementation. > > jpeg encodes 16x16 blocks too. How does vnc+jpeg-encoding handle odd > screen sizes? > > > Signed-off-by: Gerd Hoffmann > --- > vnc.c | 2 +- > 1 files changed, 1 insertions(+), 1 deletions(-) > > diff --git a/vnc.c b/vnc.c > index 142e769..a4187a1 100644 > --- a/vnc.c > +++ b/vnc.c > @@ -2205,7 +2205,7 @@ static int vnc_refresh_server_surface(VncDisplay *vd) > guest_ptr = guest_row; > server_ptr = server_row; > > - for (x = 0; x < vd->guest.ds->width; > + for (x = 0; x + 15 < vd->guest.ds->width; > x += 16, guest_ptr += cmp_bytes, server_ptr += cmp_bytes) { > if (!vnc_get_bit(vd->guest.dirty[y], (x / 16))) > continue; vnc_clear_bit(vd->guest.dirty[y], (x / 16)); read overrun ---> if (memcmp(server_ptr, guest_ptr, cmp_bytes) == 0) continue; write overrun ---> memcpy(server_ptr, guest_ptr, cmp_bytes); QTAILQ_FOREACH(vs, &vd->clients, next) { vnc_set_bit(vs->dirty[y], (x / 16)); } has_dirty++; } }