🔴 [H4] 缓存指纹太弱 → 中间修改检测不到 #4

Closed
opened 2026-06-03 13:52:51 +08:00 by dailz · 1 comment
Owner

文件: core/io/index_cache.rs:63
分类: 缓存一致性

问题: 文件指纹仅 hash 前 4KB + 后 4KB + 文件大小。文件中间部分被修改但大小/head/tail 不变时,会命中过期缓存。

hasher_state.update(&head);   // 前 4KB
hasher_state.update(&tail);   // 后 4KB
hasher_state.update(&file_size.to_le_bytes());
// ← 中间区域变化完全检测不到

建议修复: 加入 mtime/inode,小文件全文件 hash,大文件分块 rolling hash。

**文件**: `core/io/index_cache.rs:63` **分类**: 缓存一致性 **问题**: 文件指纹仅 hash 前 4KB + 后 4KB + 文件大小。文件**中间部分**被修改但大小/head/tail 不变时,会命中过期缓存。 ```rust hasher_state.update(&head); // 前 4KB hasher_state.update(&tail); // 后 4KB hasher_state.update(&file_size.to_le_bytes()); // ← 中间区域变化完全检测不到 ``` **建议修复**: 加入 mtime/inode,小文件全文件 hash,大文件分块 rolling hash。
dailz added the bugseverity/higharea/io labels 2026-06-03 13:52:51 +08:00
Author
Owner

审核结论:关闭(风险极低)

技术缺陷确认属实compute_file_hashcore/io/index_cache.rs:63)确实只采样 head 4KB + tail 4KB + file_size,中间区域不参与指纹计算。

但实际风险极低

  • 日志文件的写入模式为 append-only,生产环境中不存在中间原地修改的场景
  • head+tail+size 指纹对 append 日志已足够覆盖:追加改 tail+size,文件开头改 head
  • 正常日志轮转(logrotate)会创建新文件而非原地修改中间内容

如需加强:加 mtime 即可,无需 rolling hash。

Close as wontfix / low-risk.

## 审核结论:关闭(风险极低) **技术缺陷确认属实**:`compute_file_hash`(`core/io/index_cache.rs:63`)确实只采样 head 4KB + tail 4KB + file_size,中间区域不参与指纹计算。 **但实际风险极低**: - 日志文件的写入模式为 **append-only**,生产环境中不存在中间原地修改的场景 - head+tail+size 指纹对 append 日志已足够覆盖:追加改 tail+size,文件开头改 head - 正常日志轮转(logrotate)会创建新文件而非原地修改中间内容 **如需加强**:加 mtime 即可,无需 rolling hash。 Close as wontfix / low-risk.
dailz closed this issue 2026-06-04 13:15:22 +08:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dailz/logViewer#4