erofs-utils: tar: fix multi-chunk metadata reads
PATCH 1/1 erofs-utils: tar: fix multi-chunk metadata reads
Advance the destination buffer in erofs_iostream_bread() after each erofs_iostream_read() call.
Without that, metadata reads that span multiple stream chunks keep overwriting the start of the output buffer, which can corrupt PAX headers, GNU long names, long links, and other buffered metadata.
--- lib/tar.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/tar.c +3 -1
@@ -250,6 +250,7 @@ int erofs_iostream_read(struct erofs_iostream *ios, void **buf, u64 bytes)int erofs_iostream_bread (struct erofs_iostream *ios,void *buf,u64 bytes) {u64 rem = bytes; +u8 *dst = buf;void *src;int ret;
@@ -257,7 +258,8 @@ int erofs_iostream_bread(struct erofs_iostream *ios, void *buf, u64 bytes) ret =erofs_iostream_read (ios, &src, rem);if (ret <0 )return ret; -memcpy (buf, src, ret); +memcpy (dst, src, ret); + dst += ret; rem -= ret; }while (rem && ret);
Signature · 1 line
2.43.0
(Tested with long PAX headers via mkfs.erofs --tar)
Quoted 39 lines · Vansh Choudhary
Advance the destination buffer in
erofs_iostream_bread()after eacherofs_iostream_read()call.Without that, metadata reads that span multiple stream chunks keep overwriting the start of the output buffer, which can corrupt PAX headers, GNU long names, long links, and other buffered metadata.
Signed-off-by Vansh Choudhary <[email protected]>--- lib/tar.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)lib/tar.c +3
-2@@ -250,6 +250,7 @@ int erofs_iostream_read(struct erofs_iostream *ios, void **buf, u64 bytes)int erofs_iostream_bread (struct erofs_iostream *ios,void *buf,u64 bytes) {u64 rem = bytes; +u8 *dst = buf;void *src;int ret;@@ -257,7 +258,8 @@ int erofs_iostream_bread(struct erofs_iostream *ios, void *buf, u64 bytes) ret =erofs_iostream_read (ios, &src, rem);if (ret <0 )return ret; -memcpy (buf, src, ret); +memcpy (dst, src, ret); + dst += ret; rem -= ret; }while (rem && ret); --2.43.0
Hi Xiang,
The bug caused multi-chunk reads to overwrite the destination buffer because the pointer did not advance. To verify the fix was working correctly, we had to trigger a read larger than a standard 512-byte tar block without hitting macOS path limits.
I generated a custom tarball using Python with a PAX header containing an 800-character symlink target. This safely exceeded the 512-byte chunk size to force a multi-chunk read.
Applied the patch to lib/tar.c and rebuilt erofs-utils.
Built an EROFS image from the tarball using mkfs.erofs.
Extracted the image using fsck.erofs and verified that the extracted 800-character symlink was perfectly intact.
Without the patch, extraction failed entirely because the symlink target was corrupted in memory. With the patch, the pointer advanced correctly and the full string was preserved.