question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible image data leak when resizing a transparent GIF

See original GitHub issue

Hi there, I’m seeing leaked image data when resizing a transparent GIF image.

I’m unsure if this is a issue with sharp/vips or the loader that handles GIF images. It looks like the content of resizes leak into the resize of transparent GIF images.

Here’s the output of resizing one png and a gif multiple times:

(with flatten): 20180813-130825

(without flatten): 20180813-130801

After transforming the png, each transformation of the transparent gif leaks leaks some information. In this minimal case, it’s pretty uncommon but we’ve seen worse in production.

Is this a known issue that once can possibly fix by using a different configuration? Trying to reproduce it with a transparent png, it doesn’t happen 🤔

Here’s the minimal setup for the above output (note it will result in slightly different images depending on your system).

const sharp = require("sharp");
const fs = require("fs");

const fA = "top-secret.png";
const fB = "transparent.gif";

let counter = 0;

function transform(fileName) {
  return new Promise(resolve => {
    const resizer = sharp()
      .flatten(true)
      .rotate()
      .toFormat("png")
      .resize(300, 400)
      .min()
      .crop(sharp.gravity.center);

    const writeStream = fs.createWriteStream(
      `./outputs/${fileName}.${counter}.png`
    );

    writeStream.on("close", () => {
      counter++;
      resolve();
    });

    fs.createReadStream(`./inputs/${fileName}`)
      .pipe(resizer)
      .pipe(writeStream);
  });
}

async function main() {
  await transform(fA);
  await transform(fB);
  await transform(fB);
  await transform(fB);
  await transform(fB);
  await transform(fB);
  await transform(fB);
  await transform(fB);
  await transform(fB);
  await transform(fB);
  await transform(fB);
  await transform(fB);
  await transform(fB);
  await transform(fB);
  await transform(fB);
}

main().catch(e => console.error(e));

Here are the given inputs: transparent top-secret

Do you have any ideas or suggestions on how to proceed with this?

Thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jcupittcommented, Aug 13, 2018

I added something to 0 pages before load, does that fix it?

1reaction
jcupittcommented, Aug 14, 2018

It’s just snuck under the wire, so yes, in 8.7.0. Assuming it works!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Memory leak when resizing animated gif with ImageMagick
I'm trying to resize animated gifs with ImageMagick MagickWand, but get some small memory leaks. ~3 Mb per 400 gifs.
Read more >
Animated GIF resize issue - General Support - ProcessWire
When I set the memory_limit to under 96M, it wasn't possible to resize a single image. WIth set to 96M, it was most...
Read more >
Tumblr Engineering — Resizing Gifs On-Demand
Resizing Gifs On-Demand Why dynamically resize images in the first place? Before the dawn of on-demand resizing at Tumblr, every posted ...
Read more >
Manage Animated Images - Cloudinary
You can upload animated images to Cloudinary, resize and crop them ... GIFs are lossless, and there is no loss of data when...
Read more >
JPEG vs PNG vs GIF — which image format to use and when?
JPEG images don't support transparency and are hence not usable for such cases. PNG images support transparency in two ways — inserting an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found