0

I've deployed my app to fly.io and found an interesting error that only affects production. The same gif doesn't cause this issue using local storage. The gif is uploaded to AWS S3

First I get the VIPs-Warning ** error in tile 0 x 1104 Followed by ActionView::Template::Error (gifload: Image EOF detected before image complete

Here's the code I'm using to load the image:

<% if post.images.attached? %>
    <% post.images.each do |image| %>
    <%= image_tag image.representation(loader: { n: -1 }, resize_to_fit: [400, nil]).processed, class: "img-fluid" %>
<% end %>

Here's the gif in question, I don't see anything particularly special or weird about it and my other gifs that are larger, wider, and taller, don't cause the app to crash. Is there a way to rescue a failed gif load with Active Storage? The evil gif

I've tried adding these lines:

<% if post.images.attached? %>
  <% post.images.each do |image| %>
  <%= image_tag image.representation(loader: { n: -1 }, resize_to_fit: [400, nil]).processed, class: "img-fluid", onerror: "this.style.display='none'" %>
<% end %>

This didn't fix anything when I redeployed the site

<% if post.images.attached? %>
  <% post.images.each do |image| %>
  <%= image_tag image.representation(loader: { n: -1 }, resize_to_fit: [400, nil]).processed, class: "img-fluid", rescue nil %>
<% end %>

This causes a syntax error. Clearly there's an issue with vips and I found an old thread about it, but no solution on how to deal with it: https://github.com/libvips/libvips/issues/1701

I've tested uploading and loading the gif with AWS in development and there hasn't been an issue.

  • What libvips version are you using? Is it the same in dev and production? I'd use 8.14.1 (current stable) everywhere. – jcupitt Mar 17 '23 at 23:11
  • I'm realizing now that I never specified which to use in my config files. I'm just using the image processing gem, 1.2. I've tried a few gifs since and no issues uploading and retrieving. I've also refactored the code so the image sizing takes place in the model instead of in the view, which solved the crashing, but the gif simply doesn't display, despite being attached and deletable. – AndyDaMandy Mar 18 '23 at 16:04
  • I'd guess your libvips needs updating, I posted an answer. – jcupitt Mar 18 '23 at 16:57

1 Answers1

0

You might have a very old libvips binary on your server. I'd find out what version it is.

For example:

$ irb
irb(main):001:0> require 'vips'
=> true
irb(main):002:0> Vips::LIBRARY_VERSION
=> "8.14.0"
irb(main):003:0> 

ruby-vips is a thin skin over the libvips library binary. It has almost no functionality itself, it just presents the features available in the libvips binary on your platform in a ruby-like way.

libvips GIF handling has improved a lot over the last few years and it sounds like your production machine might need updating.

jcupitt
  • 10,213
  • 2
  • 23
  • 39
  • On my personal machine it's 8.12.1 and on the rails console for my production version (via fly.io) it's 8.10.5. I'll look into updating and let you know if that fixes the issue. – AndyDaMandy Mar 19 '23 at 01:09
  • 1
    Yes, that's probably the problem. libvips used to use giflib for loading GIFs, but switched to the (much better) nsgif loader in 8.11. – jcupitt Mar 19 '23 at 12:09