-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
files of infinite length cause bat to crash #636
Comments
Thank you for reporting this. I can reproduce this. I guess this is caused by the fact that we read every single line into a Lines 38 to 40 in 187a3b9
|
Hi,
Which solution is better? |
Sounds great.
I would have to experiment with this myself to answer your questions. I could imagine that this is not easy to fix. For example, we need to make sure to still support the non-buffering/"immediate-response" behavior of
Without having thought too much about it, I believe that would be my first try. Not sure if we can feed a non-finished line to the highlighter. |
Anyone looking to fix this issue should take a look at this PR which was an attempt at doing just that: #712 I am explicitly mentioning that so we can close the above PR to keep the PR inbox clean. |
I'd like to point out in case it has not yet been realized, this also affect when bat is piped into another program (ie """ |
Please assign this issue to me. |
Interesting... It looks like rust has expanded the max amount of memory that can fit inside a Vec since this was first reported (isn't this a Vec memory problem?). |
I don't think it's a Vec memory problem because a line in an infinitely long file might as well be infinitely long (which is definitely true for |
True. It looks like if you call std::fs::metadata("/dev/zero").unwrap().len(), the len value is zero. It might be a good fix to check the length of a (any) file and if it is 0 don't try to read it in. |
Hmm, well i have tried several different things. The latest being
But that breaks the test below bacause a zero length error is returned. But I test is the file exists and if it is a symlink
What I don't get is the file passed into Input::ordinary_file in that test seems to be a symlink... Any ideas? |
However, I'm not certain a zero-size check is sufficient since files under |
A different idea could be the following: Imagine line 52 being too long to read:
(the '!' would have the purpose of making clear that Pros:
Cons:
To not make bat hang forever, a second limit could be added. When that one is reached, bat would abort immediately. What is your opinion on that approach? |
Interseting. Right now I am looking at doing this, but that may be a better way, I'll see how your suggestion works. Because, just dont crash:
|
if you choose to go the hard coding route, would it be possible to use this would protect against files created using |
That should be reliable (https://www.kernel.org/doc/html/latest/admin-guide/devices.html), but this is a very specialized solution. There are other such files, To my understanding, the title of this issue and the author's initial comment just point out a very extreme case of the actual problem. In fact, you don't need an infinite file to let bat run out of memory, it's enough to use a regular file that is bigger than the available memory. Therefore, this problem is not limited to Linux and not to just a handful of special files. That's why I think this issue should be tackled with a more general and platform independent solution. |
It would be better to have the fix based on the actual memory problem rather than special cases. I'll keep poking at it. |
Is there a requirement or is it the desired behaviour to page binary data? If not this is a possible fix:
|
Actually, I think I can make an improvement on the code above. |
I am seeing an issue with with the idea of creating the InputReader from any "OrdinaryFile", just read in a "first line" and expect everything will be OK. More analysis on the files attributes and its content type need to happen before reading in a first line. For example, some files do not have a "line" in the text file sort of context. |
The text was updated successfully, but these errors were encountered: