From 5df29e0ce99484278ce9f32d33996c9d2c511dbc Mon Sep 17 00:00:00 2001 From: Remko Lodder Date: Mon, 11 Jun 2007 20:14:44 +0000 Subject: [PATCH] Correct corrupt read when the read starts at a non-aligned offset. PR: kern/77234 MFC After: 1 week Approved by: imp (mentor) Requested by: many many people Submitted by: Andriy Gapon --- sys/fs/udf/udf_vnops.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/sys/fs/udf/udf_vnops.c b/sys/fs/udf/udf_vnops.c index 850547344b81..b77e571969cf 100644 --- a/sys/fs/udf/udf_vnops.c +++ b/sys/fs/udf/udf_vnops.c @@ -1080,20 +1080,22 @@ udf_readatoffset(struct udf_node *node, int *size, off_t offset, *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); /* note: *bp may be non-NULL */ 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, rather than beginning of calculated sector number */ static int udf_bmap_internal(struct udf_node *node, off_t offset, daddr_t *sector, @@ -1148,7 +1150,7 @@ udf_bmap_internal(struct udf_node *node, off_t offset, daddr_t *sector, lsector = (offset >> udfmp->bshift) + le32toh(((struct short_ad *)(icb))->pos); - *max_size = GETICBLEN(short_ad, icb); + *max_size = icblen - offset; break; case 1: @@ -1173,7 +1175,7 @@ udf_bmap_internal(struct udf_node *node, off_t offset, daddr_t *sector, lsector = (offset >> udfmp->bshift) + le32toh(((struct long_ad *)(icb))->loc.lb_num); - *max_size = GETICBLEN(long_ad, icb); + *max_size = icblen - offset; break; case 3: