erofs-utils: mkfs: fix integer overflow in erofs_blob_remap
PATCH 1/1 erofs-utils: mkfs: fix integer overflow in erofs_blob_remap
When using --chunksize, partitions greater than 2GiB can fail to build due to integer overflow in erofs_blob_remap.
Signed-off-by David Anderson <[email protected]>
--- include/erofs/io.h | 6 +++--- lib/blobchunk.c | 2 +- lib/io.c | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-)
include/erofs/io.h +3 -3
@@ -27,9 +27,9 @@ u64 dev_length(void);extern int erofs_devfd; -int erofs_copy_file_range (int fd_in,erofs_off_t *off_in, -int fd_out,erofs_off_t *off_out, -size_t length); +ssize_t erofs_copy_file_range (int fd_in,erofs_off_t *off_in, +int fd_out,erofs_off_t *off_out, +size_t length);static inline int blk_write (const void *buf,erofs_blk_t blkaddr,u32 nblocks)
lib/blobchunk.c +1 -1
@@ -179,7 +179,7 @@ int erofs_blob_remap(void)struct erofs_buffer_head *bh;ssize_t length;erofs_off_t pos_in, pos_out; -int ret; +ssize_t ret;fflush (blobfile); length =ftell (blobfile);
lib/io.c +6 -6
@@ -259,9 +259,9 @@ int dev_read(void *buf, u64 offset, size_t len)return 0 ; } -static int __erofs_copy_file_range (int fd_in,erofs_off_t *off_in, -int fd_out,erofs_off_t *off_out, -size_t length) +static ssize_t __erofs_copy_file_range (int fd_in,erofs_off_t *off_in, +int fd_out,erofs_off_t *off_out, +size_t length) {size_t copied =0 ;char buf[8192 ];
@@ -331,9 +331,9 @@ static int __erofs_copy_file_range(int fd_in, erofs_off_t *off_in,return copied; } -int erofs_copy_file_range (int fd_in,erofs_off_t *off_in, -int fd_out,erofs_off_t *off_out, -size_t length) +ssize_t erofs_copy_file_range (int fd_in,erofs_off_t *off_in, +int fd_out,erofs_off_t *off_out, +size_t length) {#ifdef HAVE_COPY_FILE_RANGE off64_t off64_in = *off_in, off64_out = *off_out;
Signature · 1 line
2.34.0.rc0.344.g81b53c2807-goog
Hi David,
Quoted 4 lines · David Anderson via Linux-erofs
When using --chunksize, partitions greater than 2GiB can fail to build due to integer overflow in
erofs_blob_remap.Signed-off-by David Anderson <[email protected]>
Thanks for the report! good catch! Will apply this later.
Reviewed-by Gao Xiang <[email protected]>
(however, I think it needs several loops for 32-bit platforms.
I will fix it later...)
Thanks,
Gao Xiang
Quoted 68 lines
--- include/erofs/io.h | 6 +++--- lib/blobchunk.c | 2 +- lib/io.c | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-)include/erofs/io.h +3
-3@@ -27,9 +27,9 @@ u64 dev_length(void);extern int erofs_devfd; -int erofs_copy_file_range (int fd_in,erofs_off_t *off_in, -int fd_out,erofs_off_t *off_out, -size_t length); +ssize_t erofs_copy_file_range (int fd_in,erofs_off_t *off_in, +int fd_out,erofs_off_t *off_out, +size_t length);static inline int blk_write (const void *buf,erofs_blk_t blkaddr,u32 nblocks)lib/blobchunk.c +1
-1@@ -179,7 +179,7 @@ int erofs_blob_remap(void)struct erofs_buffer_head *bh;ssize_t length;erofs_off_t pos_in, pos_out; -int ret; +ssize_t ret;fflush (blobfile); length =ftell (blobfile);lib/io.c +6
-6@@ -259,9 +259,9 @@ int dev_read(void *buf, u64 offset, size_t len)return 0 ; } -static int __erofs_copy_file_range (int fd_in,erofs_off_t *off_in, -int fd_out,erofs_off_t *off_out, -size_t length) +static ssize_t __erofs_copy_file_range (int fd_in,erofs_off_t *off_in, +int fd_out,erofs_off_t *off_out, +size_t length) {size_t copied =0 ;char buf[8192 ];@@ -331,9 +331,9 @@ static int __erofs_copy_file_range(int fd_in, erofs_off_t *off_in,return copied; } -int erofs_copy_file_range (int fd_in,erofs_off_t *off_in, -int fd_out,erofs_off_t *off_out, -size_t length) +ssize_t erofs_copy_file_range (int fd_in,erofs_off_t *off_in, +int fd_out,erofs_off_t *off_out, +size_t length) {#ifdef HAVE_COPY_FILE_RANGE off64_t off64_in = *off_in, off64_out = *off_out;Signature · 1 line
2.34.0.rc0.344.g81b53c2807-goog