From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NYJY5-0003zE-Ls for qemu-devel@nongnu.org; Fri, 22 Jan 2010 08:27:41 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NYJY0-0003vz-Vy for qemu-devel@nongnu.org; Fri, 22 Jan 2010 08:27:41 -0500 Received: from [199.232.76.173] (port=44143 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NYJY0-0003vp-MP for qemu-devel@nongnu.org; Fri, 22 Jan 2010 08:27:36 -0500 Received: from mx1.redhat.com ([209.132.183.28]:64614) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NYJY0-0007yD-8b for qemu-devel@nongnu.org; Fri, 22 Jan 2010 08:27:36 -0500 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o0MDRX2D012500 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 22 Jan 2010 08:27:34 -0500 From: Kevin Wolf Date: Fri, 22 Jan 2010 14:26:38 +0100 Message-Id: <1264166798-27422-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH] block/raw-posix: Abort on pread beyond end of non-growable file List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf This shouldn't happen under any normal circumstances. However, it looks like it's possible to achieve this with corrupted images. Without this patch raw_pread is hanging in an endless loop in such cases. The patch is not affecting growable files, for which such reads happen in normal use cases. raw_pread_aligned already handles these cases and won't return zero in the first place. Signed-off-by: Kevin Wolf --- block/raw-posix.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index 4d79881..6ef1cff 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -403,8 +403,12 @@ static int raw_pread(BlockDriverState *bs, int64_t offset, size = ALIGNED_BUFFER_SIZE; ret = raw_pread_aligned(bs, offset, s->aligned_buf, size); - if (ret < 0) + if (ret < 0) { return ret; + } else if (ret == 0) { + fprintf(stderr, "raw_pread: read beyond end of file\n"); + abort(); + } size = ret; if (size > count) -- 1.6.5.2