yazi: Crash previewing SVG with large dimensions

What system are you running Yazi on?

Linux Wayland

What terminal are you running Yazi in?

kitty 0.36.4

yazi --debug output


Yazi
    Version: 25.3.7 (1765aba 2025-03-30)
    Debug  : false
    Triple : x86_64-unknown-linux-gnu (linux-x86_64)
    Rustc  : 1.85.1 (4eb16125 2025-03-15)

Ya
    Version: 25.3.7 (1765aba 2025-03-30)

Emulator
    TERM                : Some("xterm-256color")
    TERM_PROGRAM        : None
    TERM_PROGRAM_VERSION: None
    Brand.from_env      : None
    Emulator.detect     : Emulator { kind: Right(Unknown { kgp: false, sixel: false }), light: false, cell_size: None }

Adapter
    Adapter.matches    : Wayland
    Dimension.available: WindowSize { rows: 51, columns: 237, width: 0, height: 0 }

Desktop
    XDG_SESSION_TYPE           : Some("wayland")
    WAYLAND_DISPLAY            : Some("wayland-1")
    DISPLAY                    : Some(":0")
    SWAYSOCK                   : Some("/run/user/1000/sway-ipc.1000.458567.sock")
    HYPRLAND_INSTANCE_SIGNATURE: None
    WAYFIRE_SOCKET             : None

SSH
    shared.in_ssh_connection: false

WSL
    WSL: false

Variables
    SHELL           : Some("/bin/bash")
    EDITOR          : Some("nvim")
    VISUAL          : Some("nvim")
    YAZI_FILE_ONE   : None
    YAZI_CONFIG_HOME: None
    YAZI_ZOXIDE_OPTS: None
    FZF_DEFAULT_OPTS: None

Text Opener
    default     : Some(OpenerRule { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
    block-create: Some(OpenerRule { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })
    block-rename: Some(OpenerRule { run: "${EDITOR:-vi} \"$@\"", block: true, orphan: false, desc: "$EDITOR", for_: None, spread: true })

Multiplexers
    TMUX               : false
    tmux version       : tmux 3.5a
    tmux build flags   : enable-sixel=Unknown
    ZELLIJ_SESSION_NAME: None
    Zellij version     : No such file or directory (os error 2)

Dependencies
    file          : 5.45
    ueberzugpp    : No such file or directory (os error 2)
    ffmpeg/ffprobe: 7.0.2 / 7.0.2
    pdftoppm      : 24.08.0
    magick        : 7.1.1-41
    fzf           : 0.54.3
    fd/fdfind     : 10.1.0 / No such file or directory (os error 2)
    rg            : 14.1.1
    chafa         : 1.14.2
    zoxide        : No such file or directory (os error 2)
    7zz/7z        : No such file or directory (os error 2) / 16.02
    jq            : 1.7.1

Clipboard
    wl-copy/paste: 2.2.1 / 2.2.1
    xclip        : 0.13
    xsel         : 1.2.1

Routine
    `file -bL --mime-type`: text/plain


See https://yazi-rs.github.io/docs/plugins/overview#debugging on how to enable logging or debug runtime errors.

Describe the bug

While previewing a large (in dimensions, the file size can be tiny) SVG, (1) memory usage grows rapidly and (2) the / directory starts becoming filled, causing the system to crash. With all preloaders and previewers disabled, no crash occurs.

Minimal reproducer

(Note that this might crash the entire and system and potentially cause data loss)

  1. Save brick_system.svg to a local folder
  2. Monitor memory/disk usage (eg. using btop)
  3. Open yazi and try to preview the attached file

Anything else?

This is a partial duplicate of https://github.com/sxyazi/yazi/issues/2345. The memory issue is obviously on IM’s side:

magick -density 200 brick_system.svg -flatten -resize 200x200 -auto-orient out.jpg takes ~13 GB of RAM on my system. Interestingly, setting MAGICK_MEMORY_LIMIT=10000 has no effect on this - and as a result, setting image_alloc doesn’t help either. In both cases, magick produces a broken JPEG file but ‘works’.

When yazi previews the file, something causes systemd-coredump to write >0.5 GBs (!) of core dumps to / every second (see attached video), crashing the entire session in ~10-20 seconds. This might be due to a crash in magick which doesn’t happen when run directly.

Screencast of disk usage

https://github.com/user-attachments/assets/14d48e04-4a0d-49b7-a57e-d34d30405803

TBH I expect none of this to be yazi’s fault - and the attached SVG file is a bit extreme (although it is a info-stripped version of a real SVG file) - but it would be nice to prevent users from inadvertently running into this. I think using rsvg-convert over magick might be better (also for other reasons)… but that’s probably a feature request.

Checklist

  • I tried the latest nightly build, and the issue is still reproducible
  • I updated the debug information (yazi --debug) input box to the nightly that I tried
  • I can reproduce it after disabling all custom configs/plugins (mv ~/.config/yazi ~/.config/yazi-backup)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 22 (14 by maintainers)

Most upvoted comments

Please try https://github.com/sxyazi/yazi/commit/b725b86be13ffc127094dbb981d667d3d7d8c64a

On Thu, Apr 3, 2025 at 4:21 PM KrIr17 @.***> wrote:

After forcing ImageMagick to use rsvg via rsvg:, does the -density 200 option still lead to an OOM? How do different -density parameters perform with the rsvg backend?

Oh I just realized that the performance improvement observed in #2562 (comment) https://github.com/sxyazi/yazi/issues/2562#issuecomment-2774109466 comes not from removing the density parameter but from the use of -size 200x200 instead of -resize 200x200. With resize I still end up with the OOM issue (and both Inkscape and rsvg perform similarly w.r.t memory). However, it looks like -size works only with the rsvg backend, so the inkscape backend still leads to an OOM.

Some performance tests:

@.*** test_yazi]$ /usr/bin/time magick -size 200x200 rsvg:brick_sys.svg -density 200 -flatten out.jpg 0:00.02 real, 0.01 user, 0.01 sys, 0 amem, 19052 mmem @.*** test_yazi]$ /usr/bin/time magick -size 200x200 rsvg:image_10k.svg -density 200 -flatten out.jpg 0:00.03 real, 0.01 user, 0.01 sys, 0 amem, 19684 mmem @.*** test_yazi]$ /usr/bin/time magick -size 200x200 brick_sys.svg -density 200 -flatten out.jpg 0:10.29 real, 15.91 user, 8.43 sys, 0 amem, 3139204 mmem @.*** test_yazi]$ /usr/bin/time magick -size 200x200 image_10k.svg -density 200 -flatten out.jpg Command terminated by signal 9 (killed before OOM) 1:19.26 real, 41.30 user, 36.32 sys, 0 amem, 1178300 mmem

But with the size specified beforehand, a higher density isn’t be necessary since rsvg takes care of that. Density Tests

SVG file: circleBug.svg (view on web) https://github.com/user-attachments/assets/f43b5a21-9e74-4c9a-b144-057fbc2b50b3

magick -size 200x200 rsvg:circleBug.svg -flatten out.jpg

out_sized.jpg (view on web) https://github.com/user-attachments/assets/ea1fd94a-addc-47cc-b47b-a218d3ce4ba3

magick rsvg:circleBug.svg -flatten -resize 200x200 out_resized.jpg

out_resized.jpg (view on web) https://github.com/user-attachments/assets/f66d2f24-3859-4614-9319-b948260ca148

If you specify rsvg: but haven’t installed rsvg and only have inkscape installed, what will its behavior be? Will it fall back to ImageMagick’s default SVG backend or to inkscape?

Actually, not sure about this. I would expect it ‘falls back’ to inksape, but I can’t test it quickly (without recompiling magick and uninstalling rsvg)

— Reply to this email directly, view it on GitHub https://github.com/sxyazi/yazi/issues/2562#issuecomment-2774859274, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEFWFIB5Q5T4RCMWR6QTULL2XTVO5AVCNFSM6AAAAAB2KGEUUKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONZUHA2TSMRXGQ . You are receiving this because you modified the open/close state.Message ID: @.***> [image: krir17]krir17 left a comment (sxyazi/yazi#2562) https://github.com/sxyazi/yazi/issues/2562#issuecomment-2774859274

After forcing ImageMagick to use rsvg via rsvg:, does the -density 200 option still lead to an OOM? How do different -density parameters perform with the rsvg backend?

Oh I just realized that the performance improvement observed in #2562 (comment) https://github.com/sxyazi/yazi/issues/2562#issuecomment-2774109466 comes not from removing the density parameter but from the use of -size 200x200 instead of -resize 200x200. With resize I still end up with the OOM issue (and both Inkscape and rsvg perform similarly w.r.t memory). However, it looks like -size works only with the rsvg backend, so the inkscape backend still leads to an OOM.

Some performance tests:

@.*** test_yazi]$ /usr/bin/time magick -size 200x200 rsvg:brick_sys.svg -density 200 -flatten out.jpg 0:00.02 real, 0.01 user, 0.01 sys, 0 amem, 19052 mmem @.*** test_yazi]$ /usr/bin/time magick -size 200x200 rsvg:image_10k.svg -density 200 -flatten out.jpg 0:00.03 real, 0.01 user, 0.01 sys, 0 amem, 19684 mmem @.*** test_yazi]$ /usr/bin/time magick -size 200x200 brick_sys.svg -density 200 -flatten out.jpg 0:10.29 real, 15.91 user, 8.43 sys, 0 amem, 3139204 mmem @.*** test_yazi]$ /usr/bin/time magick -size 200x200 image_10k.svg -density 200 -flatten out.jpg Command terminated by signal 9 (killed before OOM) 1:19.26 real, 41.30 user, 36.32 sys, 0 amem, 1178300 mmem

But with the size specified beforehand, a higher density isn’t be necessary since rsvg takes care of that. Density Tests

SVG file: circleBug.svg (view on web) https://github.com/user-attachments/assets/f43b5a21-9e74-4c9a-b144-057fbc2b50b3

magick -size 200x200 rsvg:circleBug.svg -flatten out.jpg

out_sized.jpg (view on web) https://github.com/user-attachments/assets/ea1fd94a-addc-47cc-b47b-a218d3ce4ba3

magick rsvg:circleBug.svg -flatten -resize 200x200 out_resized.jpg

out_resized.jpg (view on web) https://github.com/user-attachments/assets/f66d2f24-3859-4614-9319-b948260ca148

If you specify rsvg: but haven’t installed rsvg and only have inkscape installed, what will its behavior be? Will it fall back to ImageMagick’s default SVG backend or to inkscape?

Actually, not sure about this. I would expect it ‘falls back’ to inksape, but I can’t test it quickly (without recompiling magick and uninstalling rsvg)

— Reply to this email directly, view it on GitHub https://github.com/sxyazi/yazi/issues/2562#issuecomment-2774859274, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEFWFIB5Q5T4RCMWR6QTULL2XTVO5AVCNFSM6AAAAAB2KGEUUKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDONZUHA2TSMRXGQ . You are receiving this because you modified the open/close state.Message ID: @.***>

After forcing ImageMagick to use rsvg via rsvg:, does the -density 200 option still lead to an OOM? How do different -density parameters perform with the rsvg backend?

Oh I just realized that the performance improvement observed in https://github.com/sxyazi/yazi/issues/2562#issuecomment-2774109466 comes not from removing the density parameter but from the use of -size 200x200 instead of -resize 200x200. With resize I still end up with the OOM issue (and both Inkscape and rsvg perform similarly w.r.t memory). However, it looks like -size works only with the rsvg backend, so the inkscape backend still leads to an OOM.

Some performance tests: (mmem is in KiB)

[krir17@fedora test_yazi]$ /usr/bin/time magick -size 200x200 rsvg:brick_sys.svg -density 200 -flatten out.jpg
	0:00.02 real,	0.01 user,	0.01 sys,	0 amem,	19052 mmem
[krir17@fedora test_yazi]$ /usr/bin/time magick -size 200x200 rsvg:image_10k.svg -density 200 -flatten out.jpg
	0:00.03 real,	0.01 user,	0.01 sys,	0 amem,	19684 mmem
[krir17@fedora test_yazi]$ /usr/bin/time magick -size 200x200 brick_sys.svg -density 200 -flatten out.jpg
	0:10.29 real,	15.91 user,	8.43 sys,	0 amem,	3139204 mmem
[krir17@fedora test_yazi]$ /usr/bin/time magick -size 200x200 image_10k.svg -density 200 -flatten out.jpg
Command terminated by signal 9 (killed before OOM)
	1:19.26 real,	41.30 user,	36.32 sys,	0 amem,	1178300 mmem

But with the size specified beforehand, a higher density isn’t necessary since rsvg takes care of that.

Density Tests

SVG file: Image

magick -size 200x200 rsvg:circleBug.svg -flatten out.jpg

Image

magick rsvg:circleBug.svg -flatten -resize 200x200 out_resized.jpg

Image

If you specify rsvg: but haven’t installed rsvg and only have inkscape installed, what will its behavior be? Will it fall back to ImageMagick’s default SVG backend or to inkscape?

Actually, not sure about this. I would expect it ‘falls back’ to inksape, but I can’t test it quickly (without recompiling magick and uninstalling rsvg)

Could you please test: magick -size 200x200 rsvg:brick_system.svg out.jpg if you have magick build with librsvg (magick --version | grep rsvg)? This should require about 25 MiB of RAM and a fraction of a second.

That takes about 26 ms and 20 MB of RAM; with inkscape it’s a little over 6 seconds and >2 GBs.