Skip to content

transformers.image.magick fails a .jfif upload with MiniMagick::Error "unable to open image 'jfif:...'" #84

Closed

Description

@flavorjones

transformers.image.magick fails to transform a JPEG uploaded as .jfif, .jfi or .jif, and the failure is permanent. The Vips transformer and stock Rails are unaffected. The bug started with #82, which moved hotcell to image_processing 2.2.0.

Error

The application gets HotCell::PermanentFailure, or the cell's configured permanent: class, with this message:

unreadable: MiniMagick::Error: `magick /dev/fd/7[0] -auto-orient jfif:/tmp/…/output-0` failed with status: 1 and error:
magick: unable to open image 'jfif:/tmp/…/output-0': No such file or directory @ error/blob.c/OpenBlob/3638.

Cause

  1. For a web image, Rails uses the upload's extension as the variant format when Marcel maps that extension to the blob's content type (representable.rb#L172-L185). So a photo.jfif upload with content type image/jpeg gets format jfif.
  2. The transform operation saves to the output's scratch path, which has no extension (transforming.rb#L18). For a destination like that, image_processing 2.2.0 (janko/image_processing#150) names the format as an ImageMagick prefix, jfif:/path (mini_magick.rb#L87).
  3. ImageMagick has no coder named JFIF, so it reads jfif:/path as a filename rather than a format and a path. Opening that filename fails.

Before #82, the operation saved to output-0.jfif. ImageMagick ignored the extension it did not recognise, wrote the source's format, JPEG, and the variant rendered.

The formats jpg, jpeg, jpe, png, gif and webp work in any letter case. An explicit svgz variant fails on the same path. Stock Rails calls image_processing without a destination, so image_processing names its own tempfile with the extension, and this failure does not occur there.

Reproduce

Add this to activestorage-hotcell-server/test/magick_transform_image_test.rb. It passes on 6c775e26, the commit before #82, and fails on 1ff4726f with the error above.

def test_a_jfif_upload
  Cell.boot do |cell|
    with_output(".jfif") do |destination|
      response = cell.call "active_storage.transformers.image.magick",
                           inputs: [ fixture("colour.jpg") ], outputs: [ destination ],
                           payload: { format: "jfif" }

      assert_ok response
      assert_equal "JPEG", identify(destination)[:format]
    end
  end
end

Possible fixes

  1. In hotcell, have the ImageMagick toolchain save to destination.path(extension: format) and adopt it, as it did before Require image_processing 2.2.0 and drop the transform rename #82. ImageMagick then chooses the format by extension, as it does under stock Rails. The Vips toolchain keeps saving to the scratch path directly.
  2. In image_processing, have the MiniMagick saver fall back to the unprefixed path when ImageMagick does not recognise the format.

Activity

  1. flavorjones commented on Sep 30, 2026

    @flavorjones
    MemberAuthor

    Since I don't have this problem currently (personally) I'm waiting to see if it's actually a problem. Please post a comment if you run into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions