toolong icon indicating copy to clipboard operation
toolong copied to clipboard

SIGBUS when viewing a file that is truncated while loading

Open tstack opened this issue 5 months ago • 0 comments

Description

When opening a file that is then truncated, the program crashes with a SIGBUS.

Platform

MacOS 14.3

tl v1.0.0

How to reproduce

The easiest way is to create a large file with a bunch of lines, run tl bigfile.txt. Then, while tl is scanning for new lines, run truncate -s 0 bigfile.txt in another terminal.

Details

Using mmap() on a file the app doesn't own/control is problematic since changes to the file can mess up your process. It would probably be best to avoid mmap() and use regular file I/O instead.

While this may seem unlikely, it can happen in practice because of things like logrotate's copytruncate option which will copy the file contents and then truncate it.

tstack avatar Feb 12 '24 04:02 tstack