mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-11-07 04:36:52 -10:00
tarfs: Fix length calculation for file read
When the offset is within a block rather than at its beginning, the length should be clamped to the remaining length of the block, not its total length. Reported by: n0ps1ed MFC after: 1 week Reviewed by: markj, emaste Differential Revision: https://reviews.freebsd.org/D60904
This commit is contained in:
1 parent
a380332346
commit
18bce6e65c
1 file changed
+3
-2
@@ -428,7 +428,7 @@ tarfs_read_file(struct tarfs_node *tnp, size_t len, struct uio *uiop)
|
||||
TARFS_DPF(VNODE, "%s(%s, %zu, %zu)\n", __func__,
|
||||
tnp->name, uiop->uio_offset, resid);
|
||||
for (i = 0; i < tnp->nblk && resid > 0; ++i) {
|
||||
if (uiop->uio_offset > tnp->blk[i].o + tnp->blk[i].l) {
|
||||
if (uiop->uio_offset >= tnp->blk[i].o + tnp->blk[i].l) {
|
||||
/* skip this block */
|
||||
continue;
|
||||
}
|
||||
@@ -456,7 +456,8 @@ tarfs_read_file(struct tarfs_node *tnp, size_t len, struct uio *uiop)
|
||||
while (resid > 0 &&
|
||||
uiop->uio_offset < tnp->blk[i].o + tnp->blk[i].l) {
|
||||
/* now actual data */
|
||||
copylen = tnp->blk[i].l;
|
||||
copylen = tnp->blk[i].l -
|
||||
(uiop->uio_offset - tnp->blk[i].o);
|
||||
if (copylen > resid)
|
||||
copylen = resid;
|
||||
auio = *uiop;
|
||||
|
||||
Reference in new issue
Block a user