From owner-freebsd-bugs@FreeBSD.ORG Mon Feb 7 21:31:35 2005 Return-Path: Delivered-To: freebsd-bugs@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3049716A4CE; Mon, 7 Feb 2005 21:31:35 +0000 (GMT) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.FreeBSD.org (Postfix) with ESMTP id 85A7043D41; Mon, 7 Feb 2005 21:31:33 +0000 (GMT) (envelope-from avg@icyb.net.ua) Received: from oddity (oddity.topspin.kiev.ua [212.40.38.87]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id XAA11141; Mon, 07 Feb 2005 23:31:31 +0200 (EET) (envelope-from avg@icyb.net.ua) Date: Mon, 7 Feb 2005 23:31:30 +0200 (EET) From: Andriy Gapon X-X-Sender: avg@oddity.topspin.kiev.ua To: FreeBSD-gnats-submit@FreeBSD.org, freebsd-bugs@FreeBSD.org In-Reply-To: <200502072010.j17KAOST029784@freefall.freebsd.org> Message-ID: <20050207232259.F16960@oddity.topspin.kiev.ua> References: <200502072010.j17KAOST029784@freefall.freebsd.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Subject: Re: kern/77234: corrupted data is read from UDF filesystem if read starts at non-aligned offset X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Feb 2005 21:31:35 -0000 If meaning of max_size is interpreted as maximum number of contiguous bytes that can be read starting from a given offset rather than starting from a beginning of a calculated sector number then a patch could be like the following. (Please note that currently max_size contains number of bytes in an extent to which current offset belongs, which is total nonsense since any code that calls udf_bmap_internal() has no notion of extents) --- udf_vnops.c.orig Mon Feb 7 22:59:34 2005 +++ udf_vnops.c Mon Feb 7 23:18:06 2005 @@ -1107,19 +1107,21 @@ *size = max_size; *size = min(*size, MAXBSIZE); - if ((error = udf_readlblks(udfmp, sector, *size, bp))) { + if ((error = udf_readlblks(udfmp, sector, *size + (offset & udfmp->bmask), bp))) { printf("warning: udf_readlblks returned error %d\n", error); return (error); } bp1 = *bp; - *data = (uint8_t *)&bp1->b_data[offset % udfmp->bsize]; + *data = (uint8_t *)&bp1->b_data[offset & udfmp->bmask]; return (0); } /* * Translate a file offset into a logical block and then into a physical * block. + * max_size - maximum number of bytes that can be read starting from given + * offset, not beginning of calculated sector number */ static int udf_bmap_internal(struct udf_node *node, off_t offset, daddr_t *sector, uint32_t *max_size) @@ -1172,7 +1174,7 @@ lsector = (offset >> udfmp->bshift) + ((struct short_ad *)(icb))->pos; - *max_size = GETICBLEN(short_ad, icb); + *max_size = icblen - offset; break; case 1: @@ -1196,7 +1198,7 @@ lsector = (offset >> udfmp->bshift) + ((struct long_ad *)(icb))->loc.lb_num; - *max_size = GETICBLEN(long_ad, icb); + *max_size = icblen - offset; break; case 3: