Skip to content

Fix JPEG variants uploaded as .jfif, .jif or .jfi - #103

Merged
flavorjones merged 3 commits into
masterfrom
card-5287-canonical-format
Oct 7, 2026
Merged

flavorjones merged 3 commits into
masterfrom
card-5287-canonical-format

Conversation

@flavorjones

Copy link
Copy Markdown
Member

Motivation

Rails names a web image's variant format after the upload's extension when Marcel maps that extension to the blob's content type (representable.rb#L180-L186). So a JPEG uploaded as photo.jfif asks the cell for format jfif, and the transformers fail on some of these formats:

Fixes #84

Details

Transforming#process in activestorage-hotcell-client now sends the cell the canonical extension of the format's content type, Marcel::Magic.new(content_type).extensions.first. Rails falls back to the same extension when the upload's extension does not match. The change applies only to formats whose content type is in ActiveStorage.web_image_content_types, because Rails takes a format from the filename only for those types. Every other format crosses unchanged.

The variant's format in Rails is unchanged, so variation keys and variant URLs stay the same.

Additional information

This is an alternative to #101, which stages the ImageMagick output under the format's extension and renames it into place. Here, #82's direct write and image_processing's format check stay, and the Vips transformer is fixed too.

An application that calls active_storage.transformers.image.magick directly with jfif, without this gem's client, still gets unreadable.

Since #82, the ImageMagick transformer failed a JPEG uploaded as .jfif,
.jif or .jfi permanently as `unreadable`. The Vips transformer has
always failed .jif and .jfi the same way. Send the cell the canonical
extension of a web image format's content type, which is the extension
Rails falls back to when an upload's extension does not match.

[Fix #84]
Copilot AI balanced review requested due to automatic review settings October 7, 2026 20:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The non-web-image pass-through branch lacks regression coverage.

1 open finding
What changed in this PR

Canonicalizes Rails web-image format aliases before sending transformations to the cell.

Changes:

  • Maps JPEG aliases such as jfif, jif, and jfi to jpg.
  • Adds ImageMagick and Vips regression tests.
  • Documents the fix in the changelog.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

File Description
CHANGELOG.md Records the JPEG alias fix.
activestorage-hotcell-client/​lib/​active_storage/​hot_cell/​client/​transformers/​transforming.rb Canonicalizes web-image formats.
activestorage-hotcell-client/​test/​transformers/​image_magick_test.rb Tests JPEG aliases with ImageMagick.
activestorage-hotcell-client/​test/​transformers/​vips_test.rb Tests JPEG aliases with Vips.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

The pass-through for a format outside `web_image_content_types` had no
test, so removing the guard would have left the suite green.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The Vips operation’s contract comment now contradicts the canonicalized format behavior.

0 open findings

1 resolved since last review
Previously missed (1)

In code that hasn't changed since last review

Low severity Document format canonicalization exception in Vips transformer comment

activestorage-hotcell-client/​lib/​active_storage/​hot_cell/​client/​transformers/​transforming.rb:37

This changes the wire format before the Vips operation receives it, so the existing contract comment in activestorage-hotcell-server/lib/active_storage/hot_cell/server/transformers/image/vips.rb:11-13 is now false: the format no longer reaches ImageProcessing exactly as Rails supplied it. Please update that comment to document the canonicalization exception.

🧠 Review effort: Balanced

The comment said the format reached ImageProcessing exactly as Rails
handed it over, which stopped being true when the client began sending
a web image's canonical extension.
@flavorjones
flavorjones merged commit 00dfd86 into master Oct 7, 2026
17 checks passed
@flavorjones
flavorjones deleted the card-5287-canonical-format branch October 7, 2026 20:51
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

Successfully merging this pull request may close these issues.

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

2 participants