erofs-utils: tar: fix overly large size in tar header
PATCH 1/1 erofs-utils: tar: fix overly large size in tar header
As @oscarjhk reported:
When tar-index mode is used, the inode chunk count will be calculated as 0 if a crafted GNU base-256 size is UINT64_MAX, which will cause a heap out-of-bounds write.
Fixes 95d315fd7958 ("erofs-utils: introduce tarerofs")
Signed-off-by Gao Xiang <[email protected]>
--- lib/blobchunk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/blobchunk.c +3 -1
@@ -507,7 +507,9 @@ int tarerofs_write_chunkes(struct erofs_inode *inode, erofs_off_t data_offset) datablob_size +=round_up (inode->i_size,erofs_blksiz (sbi)); } chunksize =1ULL << chunkbits; - count =DIV_ROUND_UP (inode->i_size, chunksize); +/* e.g. DIV_ROUND_UP(UINT64_MAX, 1 TiB) can overflow */ + count = (inode->i_size >> chunkbits) + + !!(inode->i_size & (chunksize -1 )); inode->extent_isize = count * unit; idx =calloc (count,max (sizeof (*idx),sizeof (void *)));
Signature · 1 line
2.43.5
PATCH 1/1 erofs-utils: tar: refuse negative size in tar header
As @oscarjhk reported:
When tar-index mode is used, the inode chunk count will be calculated as 0 if a crafted GNU base-256 size is UINT64_MAX, which will cause a heap out-of-bounds write.
Fixes 95d315fd7958 ("erofs-utils: introduce tarerofs")
Signed-off-by Gao Xiang <[email protected]>
--- lib/tar.c | 7 +++++++ 1 file changed, 7 insertions(+)
lib/tar.c +7 -0
@@ -886,6 +886,13 @@ out_eot: goto invalid_tar; } +if ((s64 )st.st_size <0 ) { +erofs_err ("invalid negative size=%lld @ %lld" , + (s64 )st.st_size, tar_offset); + ret = -EFSCORRUPTED ; + goto out; + } +if (th->typeflag <='7' && !eh.path) { eh.path = path; j =0 ;
Signature · 1 line
2.43.5