From 8895361e5b5e1189412f1e545ff0318268ee1e19 Mon Sep 17 00:00:00 2001 From: RoyHuang Date: Sun, 14 Jun 2026 22:51:07 +0800 Subject: [PATCH] Fix lookup and overflow in simplefs_ext_search The final hit check used 'iblock < end_len' instead of 'iblock < end_block + end_len', so a block in any extent not starting at block 0 was missed and returned as the unused 'boundary' slot (read as a hole, or overwritten on write). Also return -1 when the extent array is full, instead of the out-of-bounds 'boundary' == SIMPLEFS_MAX_EXTENTS. Close #76 --- extent.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/extent.c b/extent.c index 00c80fa..8da6d5c 100644 --- a/extent.c +++ b/extent.c @@ -64,9 +64,10 @@ uint32_t simplefs_ext_search(struct simplefs_file_ei_block *index, */ end_block = index->extents[end].ee_block; end_len = index->extents[end].ee_len; - if (iblock >= end_block && iblock < end_len) + + if (iblock >= end_block && iblock < end_block + end_len) return end; if (boundary < SIMPLEFS_MAX_EXTENTS) return boundary; - return boundary; + return -1; }