Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DjVu documents (and potentially other cases) cause chafa to consume a lot cpu and memory #179

Closed
xlucn opened this issue Nov 24, 2023 · 4 comments

Comments

@xlucn
Copy link

xlucn commented Nov 24, 2023

Summary:
Since chafa seems to try to display as many file formats as possible, sometimes it might just be inappropriate and should be prevented or optimized.

Example:
One such case is DjVu files, many-page djvu documents to be accurate.

In my exact case, I have set in my lf preview script to use chafa to preview any file of image/* type. Unfortunately, DjVu files are "image/vnd.djvu" type. However, I think the argument applies to more general use cases as well.

When I use chafa to (pre)view a several-hundred-page djvu document, it consumes all the available memory and the system just hangs.

Discussion:
Maybe chafa should at least check for potential memory consumption.

Maybe also optimize the preview, such as only preview the first page, which I believe will never cost many GBs of memory. This possibly applies to PDFs as well, which currently is very slow (a few seconds) to display.

@Zerogaku
Copy link

this has happened to me as well, when previewing a large pdf using lf, my window manager just froze

@hpjansson
Copy link
Owner

Hi, thanks for reporting this. This is happening because Chafa delegates to ImageMagick when there's no internal loader to handle the file format. ImageMagick gets very enthusiastic and sometimes trips on its own shoelaces.

The problem is fixed in master and will go away in the next release -- see #157.

In the meantime, you should be able to curb problematic formats in ImageMagick's configuration. On my distro, this lives in /etc/ImageMagick-7/. The best way is to list it in the security policy file:

  1. Find the format identifier by running magick -list format.
  2. Add it to the policy file (policy.xml), e.g:
    <policy domain="coder" rights="none" pattern="DJVU" />
    <policy domain="coder" rights="none" pattern="PDF" />

The default configuration varies between Linux distros; mine already has PDF on the do-not-load list, and it looks like DjVu support is not built in at all.

@xlucn
Copy link
Author

xlucn commented Nov 24, 2023

thanks, I look forward to the next release!

@hpjansson
Copy link
Owner

I just released version 1.14.0, where ImageMagick is no longer an option. That should fix the issue (but it will no longer produce previews for DjVu and PDF; maybe one day it will be possible to do so safely).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants