🔴 [H1] 文件缩小后 mmap 未处理 → SIGBUS 崩溃 #1
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
文件:
core/io/file_reader.rs:116分类: 内存安全
问题:
update_for_append()检测到new_size <= old_size时直接返回Ok(0),不重新 mmap。如果文件被截断/轮转,后续访问旧 mmap 范围会触发 SIGBUS 进程崩溃。影响: log viewer 场景下文件经常被外部轮转/截断,但代码假设文件在 mmap 期间不变。
建议修复: 检测
new_size < old_size时强制reload()或返回错误要求重新映射/索引。Fixed in
b6e655b.Root cause:
update_for_append()returnedOk(0)whennew_size <= old_size, leaving a stale mmap that would SIGBUS on access.Fix: Introduced
AppendStatusenum (Unchanged/Appended/Reloaded). When file shrinks,reload()rebuilds the mmap and line index. TUI layer clamps cursor and invalidates viewport onReloaded, matching existinghandle_file_truncated()behavior.