`use binder` asset `vscode.svg` has mismatched mask units, causing macOS thumbnailing to allocate terabytes of RAM

未关闭 适合新手
#14,907 3 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1 小时以内
新手友好度
92/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
desktop

调研方向

编辑 src/resources/use/binder/vscode.svg 并检查 mask-2 元素。使用 macOS sips 将资源栅格化,或使用 issue 中设置上限的复现方式,然后比较内存使用量和外观。完成的标准是 SVG 能在不发生失控分配的情况下生成缩略图,同时保留 artwork 和 stroke。

由索引模型根据 Issue 内容生成。

描述

binder bug
I have:
  • searched the issue tracker for similar issues
  • installed the latest version of Quarto CLI (reproduced on 1.10.18, and confirmed the file is unchanged on main)
  • formatted my issue following the Bug Reports guide
Bug description

src/resources/use/binder/vscode.svg contains a <mask> whose units and values disagree:

<mask id="mask-2" maskContentUnits="userSpaceOnUse" maskUnits="objectBoundingBox"
      x="-15" y="-15" width="1009.27778" height="1006.4">

maskUnits="objectBoundingBox" means x/y/width/height are fractions of the object bounding box, but the values are plainly user-space pixel values (they match the <rect> on the next line, which is correctly declared userSpaceOnUse). This looks like a Sketch export artifact.

Taken literally, against the ~980x980 bounding box, the mask region is:

~989,000 x ~986,000 px  =  ~9.8e11 pixels  =  ~3.5 TiB at 4 bytes/px

Browsers clamp this, so web output is unaffected and the bug is invisible in normal Quarto use. macOS ImageIO does not clamp. It allocates the region in 128 MiB tiles, so any macOS process that thumbnails or rasterizes this file (Finder, Spotlight, QuickLook, sips) balloons until the kernel kills it.

Because QuickLook treats the kill as a transient failure, it respawns and retries indefinitely. On my machine this pinned load average above 400 and drove the system into swap thrash until I tracked it down. vmmap on one extension instance:

Physical footprint: 162.1G
REGION TYPE           VIRTUAL  RESIDENT   DIRTY   SWAPPED  COUNT
CG Image               162.1G     14.6G   14.6G    147.5G   1297

1,297 regions of exactly 128 MiB, which is the tiled allocation of that mask surface.

Steps to reproduce

No Quarto invocation is needed. The shipped asset alone reproduces it on macOS:

# fetch the file exactly as shipped
curl -sO https://raw.githubusercontent.com/quarto-dev/quarto-cli/main/src/resources/use/binder/vscode.svg

# rasterize it with any macOS ImageIO consumer.
# NOTE: this is capped at 3 GB on purpose. Without the watchdog it will
# consume all available RAM and drive the machine into swap thrash.
sips -s format png --out out.png vscode.svg & P=$!
while R=$(ps -o rss= -p $P 2>/dev/null | tr -d ' '); [ -n "$R" ]; do
  echo "RSS: $((R/1024)) MB"
  [ "$R" -gt 3145728 ] && { kill -9 $P; echo "runaway, killed"; break; }
  sleep 1
done

A 2,380 byte file reaches 12.6 GB RSS within 2 seconds if left uncapped.

In normal use the trigger is simply having Quarto installed and letting Finder or Spotlight touch share/use/binder/, which is what happened here.

Actual behavior

Rasterizing the shipped vscode.svg allocates unbounded memory (observed 162 GB physical footprint) until the process is killed. Under QuickLook this becomes an infinite respawn loop that degrades the whole machine.

Expected behavior

The asset rasterizes in a few MB, like every other SVG Quarto ships.

Suggested fix

Delete the incorrect maskUnits and its associated values, and let the SVG defaults apply (objectBoundingBox with -10%/-10%/120%/120%), which comfortably covers the artwork plus its 30 unit stroke:

-        <mask id="mask-2" maskContentUnits="userSpaceOnUse" maskUnits="objectBoundingBox" x="-15" y="-15" width="1009.27778" height="1006.4">
+        <mask id="mask-2" maskContentUnits="userSpaceOnUse">

Verification I ran on this change:

  • Visually lossless. Headless Chrome renders of the original and the patched file are byte-for-byte identical: 0 differing pixels out of 1,028,180.
  • Memory safe. Peak RSS drops from >12 GB to 1-2 MB, tested at 32, 128, 512 and 2048 px output.
  • I also tested explicit maskUnits="userSpaceOnUse" with a widened region; it is equally correct, but the above needs no magic numbers. Note that keeping userSpaceOnUse with the existing width/height is subtly wrong: it clips the outer white stroke by a few pixels at the edges.

The file has been unchanged since it was added in 411ebc3d ("Baseline implementation of re-entrant quarto use binder command", 2023-09-06), so this affects all releases since.

Happy to open a PR if useful.

Your environment
  • IDE: n/a (reproduced from the shell)
  • OS: macOS 27.0 (build 26A428), Apple Silicon (arm64)
Quarto check output
Quarto 1.10.18
[✓] Checking environment information...
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.10.0: OK
      Dart Sass version 1.101.0: OK
      Deno version 2.7.14: OK
      Typst version 0.15.1: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.10.18
      Path: /Applications/quarto/bin
[✓] Checking tools....................OK
      TinyTeX: (not installed)
      Chrome Headless Shell: (not installed)
      VeraPDF: (not installed)
[✓] Checking LaTeX....................OK
      Using: Installation From Path
[✓] Checking Chrome Headless....................OK
[✓] Checking basic markdown render....OK
[✓] Checking R installation...........(None)
[✓] Checking Python 3 installation....OK
      Version: 3.14.7
      Jupyter: 5.9.1

Investigation was AI-assisted and the findings above (repro, render comparison, memory measurements) were reviewed and verified by me before filing.

主要语言
JavaScript
星标
6k
派生
458
平均合并
1 天 8 小时
30 天内合并 PR
42

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

quarto-dev/quarto-cli 的其他 Issue

查看 quarto-dev/quarto-cli 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。