erofs-utils: lib: fix buffer overrun after short positional reads
PATCH 1/1 erofs-utils: lib: fix buffer overrun after short positional reads
After a positive short read, erofs_io_pread() advances the buffer and file offset but retries with the original length. This can write past the end of the caller's buffer and return more bytes than requested.
Limit each read to the remaining number of bytes.
Assisted-by ChatGPT:gpt-6.1-sol
Fixes 97f48b3c37f5 ("erofs-utils: fix erofs_io_p{read,write} and erofs_dev_close")
Signed-off-by Gao Xiang <[email protected]>
--- lib/io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/io.c +1 -1
@@ -230,7 +230,7 @@ ssize_t erofs_io_pread(struct erofs_vfile *vf, void *buf, size_t len, u64 pos) pos += vf->offset; do { - ret = erofs_os_pread(vf->fd, buf, len, (off_t)pos); + ret = erofs_os_pread(vf->fd, buf, len - read, (off_t)pos); if (ret <= 0) { if (!ret) break;
Signature · 1 line
2.54.0 (Apple Git-157)