Repository navigation
Description
The two ImageMagick operations copy their input onto scratch before using it. Every other shipped operation reads the descriptor in place.
transformers/image/magick.rb:34 returns source.path from source_path, and analyzers/image/magick.rb:28 passes source.path to identify. Both vips operations, both PDF previewers and the ffmpeg previewer read source.fd_path.
MagickOperation records why: mini_magick spawns its own magick, which does not inherit this worker's descriptors, so the input cannot be handed over as /dev/fd/N.
What it costs. Staging is a write, so RLIMIT_FSIZE bounds it, and an input larger than the operation's file_size dies as a permanent fsize verdict — a ceiling Rails does not have and the vips operations shed. It also consumes scratch: file_size × concurrency has to fit the tmpfs, and a staged input counts against that budget alongside the output.
The fix named in MagickOperation is to drive magick directly through run_tool's pass:, which is what every other exec'd operation already does.
The trade to weigh. Both operations reach magick through ImageProcessing::MiniMagick, which supplies the saver and its option handling. Driving the tool directly means restating that by hand — the same argument transforming.rb makes for keeping ImageProcessing on the vips path, so it deserves the same scrutiny here.
Scope note: this is about the input only. The output side of these operations cannot be improved the same way. ImageProcessing picks its saver from the destination's extension, and a /dev/fd path has none — verified, it fails with VipsForeignSave: "/dev/fd/5" is not a known file format even with convert("png") set. Of the five operations with outputs, only the ffmpeg previewer writes its destination by name, and the other four are each blocked for a tool-specific reason.
Found auditing which Active Storage operations re-open a descriptor by name, after the shared-group work. Previously tracked as Fizzy card #380.
Activity
flavorjones commentedon Aug 18, 2026
A second reason for the same change, from the pre-release security review.
Invariant 9 gives a tool only the environment its operation wrote. These two operations do not use
run_tool, so mini_magick spawnsmagickitself.MiniMagick.restricted_envdefaults tofalse, and with it false the child inherited the worker's whole environment. 95aa6b3 setsrestricted_envandcli_env, which closes it.That fix uses mini_magick's own mechanism, which filters the environment it was given.
run_toolwrites a fresh one withunsetenv_others: true. Drivingmagickdirectly would make the environment ours rather than the library's, on the code path this issue already proposes.[-]The two magick operations stage their input, restoring the file_size ceiling[/-][+]Consider removing dependency on mini_magick[/+]flavorjones commentedon Aug 18, 2026
A third reason, also from the pre-release security review.
Operation#run_toolbounds what it reads from a tool at 64KB and discards the rest as it arrives. Its comment says why: an input that makes a tool print gigabytes of diagnostics costs the worker gigabytes of address space, takesRLIMIT_DATAwith it, and arrives as amemoryverdict — permanent — for a document whose only crime was being noisy.These two operations do not use
run_tool.MiniMagick::Shell#executerunsThread.new { stdout_io.read }per stream and accumulates both in full. mini_magick has no setting that bounds either;graphicsmagick,cli_prefix,cli_env,restricted_env,timeout,logger,tmpdir,errorsandwarningsare the whole list.So a hostile image that makes
identifynoisy enough is recorded against the blob as a permanent memory verdict and never retried, where the same input on anyrun_tooloperation is bounded and answered normally.Marked as an accepted risk in
MagickOperationfor now, pointing here. That makes three reasons for this change: input staging, environment ownership, and output bounding.Mark mini_magick's unbounded output as accepted
flavorjones commentedon Aug 20, 2026
I think we should probably also consider sending a PR to minimagick adding support for file descriptor sharing, similar to what
run_toolalready does.flavorjones commentedon Aug 25, 2026
🤖 A concrete case for this issue.
What we saw
Analyzing a large layered PSD was killed.
Analyzers::Image::Magickreadssource.path, andInput#pathcopies the descriptor onto worker scratch beforemagickruns. That copy is a write,RLIMIT_FSIZEbounds writes, and the operation setsfile_size: 48MB— so any input over 48MB dies during the copy, beforemagickis ever started.Why that belongs on this issue
The copy exists only because
mini_magickcannot be handed an open descriptor. Giveimage_processing/mini_magickfd support and there is no copy, and therefore no ceiling. PSD is just the format that hits it first; the ceiling applies to every inputMagickOperationstages.Evidence
The fd route already works at the command line —
magick identify psd:/dev/fd/3on a 1GB 13-layer 6000x6000 PSD returned 6000x6000 in 0.19s.The blocker is the handoff:
mini_magickspawnsmagickthroughOpen3.popen3, Ruby marks our descriptors close-on-exec, so/dev/fd/Ndoes not exist in that child.Don't bother retrying this
Staging only a prefix of the input, on the theory that a small write fits under
file_size.identifywalks the PSD layer records and will not fall back to the header dimensions it has already read: 8KB, 64KB and 1MB prefixes of that 1GB file all exit 1 inReadPSDLayersInternal. A 50KB fixture succeeds at 4KB, which is why it looks viable until it is tried at size.Full record: https://app.basecamp.com/2914079/buckets/1666/card_tables/cards/10236340587
Read the ImageMagick operations' input through its descriptor
Read the ImageMagick operations' input through its descriptor
Read the ImageMagick operations' input through its descriptor
Read the ImageMagick operations' input through its descriptor
Read the ImageMagick operations' input through its descriptor (#54)