fix: eliminate TOCTOU race in IndexCache::save (closes #5)
spawn_indexer builds LineIndex from mmap snapshot but IndexCache::save() re-opened the file to compute the hash. If the file changed between those two steps, the cached index would be stored under the wrong hash. - Add IndexCache::save_with_hash() that computes hash from in-memory data - Add compute_data_hash() public function (same algorithm as compute_file_hash) - Update spawn_indexer, FileReader::save_cache, and test callers
This commit is contained in:
@@ -314,7 +314,7 @@ pub fn spawn_indexer(
|
||||
|
||||
let line_index = LineIndex::from_bytes(data);
|
||||
|
||||
let _ = IndexCache::save(&path, &line_index);
|
||||
let _ = IndexCache::save_with_hash(&path, &line_index, data);
|
||||
|
||||
let reader = FileReader::from_parts(path, mmap, line_index);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user