Skip to contentSkip to conversation

erofs-utils: refuse block sizes larger than EROFS_MAX_BLOCK_SIZE

PATCH New Gao Xiang 1 participant 2 messages Jun 3, 2023 Library code

lore
Share & tools
lore

Gao Xiang

author
#0 lore raw

PATCH 1/2 erofs-utils: refuse block sizes larger than EROFS_MAX_BLOCK_SIZE

The maximum supported block size is EROFS_MAX_BLOCK_SIZE.

---
 lib/super.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
lib/super.c +4 -5
index 17f849e..5f70686 100644
@@ -88,15 +88,14 @@ int erofs_read_superblock(void)
 	sbi.feature_compat = le32_to_cpu(dsb->feature_compat);
 
 	sbi.blkszbits = dsb->blkszbits;
-	/* 9(512 bytes) + LOG_SECTORS_PER_BLOCK == LOG_BLOCK_SIZE */
-	if (sbi.blkszbits < 9) {
+	if (sbi.blkszbits < 9 ||
+	    (1 << sbi.blkszbits) > EROFS_MAX_BLOCK_SIZE) {
 		erofs_err("blksize %d isn't supported on this platform",
 			  erofs_blksiz());
 		return ret;
-	}
-
-	if (!check_layout_compatibility(&sbi, dsb))
+	} else if (!check_layout_compatibility(&sbi, dsb)) {
 		return ret;
+	}
 
 	sbi.primarydevice_blocks = le32_to_cpu(dsb->blocks);
 	sbi.meta_blkaddr = le32_to_cpu(dsb->meta_blkaddr);
Signature · 1 line
2.24.4
author
#1 lore raw

PATCH 2/2 erofs-utils: fix EOD behavior when len is too large

Otherwise, read_count could be overflow and causes unexpected behaviors.

---
 lib/io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/io.c +1 -1
index 9e30b7e..9d718ab 100644
@@ -289,7 +289,7 @@ int dev_read(int device_id, void *buf, u64 offset, size_t len)
 				erofs_info("Reach EOF of device - %s:[%" PRIu64 ", %zd].",
 					   erofs_devname, offset, len);
 				memset(buf, 0, len);
-				read_count = len;
+				return 0;
 			} else if (errno != EINTR) {
 				erofs_err("Failed to read data from device - %s:[%" PRIu64 ", %zd].",
 					  erofs_devname, offset, len);
Signature · 1 line
2.24.4