-
Notifications
You must be signed in to change notification settings - Fork 102
Open
Description
Bug Report: Incorrect boundary check in simplefs_ext_search()
Location
File: extent.c, Line: 67
Issue Description
There's a logical error in the final boundary check of the simplefs_ext_search() function.
Current code (incorrect):
if (iblock >= end_block && iblock < end_len)
return end;Should be:
if (iblock >= end_block && iblock < end_block + end_len)
return end;Problem Analysis
The current code incorrectly compares iblock with end_len (which is a count of blocks) instead of the actual end boundary of the extent.
end_blockrepresents the starting logical block number of an extent (e.g., 10)end_lenrepresents the number of consecutive blocks in the extent (e.g., 5)- An extent covering blocks [10, 11, 12, 13, 14] should have the range check:
iblock >= 10 && iblock < 15 - The current condition
iblock < end_lenbecomesiblock < 5, which is incorrect
Code Inconsistency
The binary search loop correctly implements the boundary check:
if (iblock >= block && iblock < block + len) {
return mid;
}However, the final verification check uses an inconsistent pattern:
if (iblock >= end_block && iblock < end_len) // Inconsistent!This creates a logical contradiction where a block might never be found even if it exists within a valid extent.
Metadata
Metadata
Assignees
Labels
No labels