From a8ef7ea415b04e10da5654c9e50c620f32896110 Mon Sep 17 00:00:00 2001 From: Jiang Liu Date: Fri, 24 Feb 2023 15:26:49 +0800 Subject: [PATCH] rafs: fix a bug in calculate offset for dirent name There's a bug in calculate offset and size for RAFS v6 Dirent name, it will be treat as 0 instead of 4096 if the last block is 4096 bytes. Fixes: https://github.com/dragonflyoss/image-service/issues/1098 Signed-off-by: Jiang Liu --- rafs/src/metadata/direct_v6.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rafs/src/metadata/direct_v6.rs b/rafs/src/metadata/direct_v6.rs index f3ee2d46003..c940cc0e640 100644 --- a/rafs/src/metadata/direct_v6.rs +++ b/rafs/src/metadata/direct_v6.rs @@ -534,7 +534,11 @@ impl OndiskInodeWrapper { // Because the other blocks should be fully used, while the last may not. let len = if div_round_up(self.size(), EROFS_BLOCK_SIZE) as usize == block_index + 1 { - (self.size() % EROFS_BLOCK_SIZE - s) as usize + if self.size() % EROFS_BLOCK_SIZE == 0 { + EROFS_BLOCK_SIZE as usize + } else { + (self.size() % EROFS_BLOCK_SIZE - s) as usize + } } else { (EROFS_BLOCK_SIZE - s) as usize };