Sharp: VipsJpeg: Invalid SOS parameters for sequential JPEG

Created on 15 Feb 2019  路  15Comments  路  Source: lovell/sharp

Repro example: https://gist.github.com/asilvas/773b902b2d175d452c6472a4ed128762

This is an issue that recently came up that seems related to a recent change. At first I brushed it off as a corrupt image, but quite a few of these cases have come up since. Every other image editor I try the image in works fine. Presumably this is a Jpeg decoder bug, but wanted to post it here since it may require an update to sharp builds.

enhancement

Most helpful comment

@sachinB94 Probably before Samsung, who make ~US$60bn/year in profit, fix their buggy firmware.

All 15 comments

Looks like this might have been when it was introduced: https://github.com/lovell/sharp-libvips/commit/fad8f99e709b56b53fa78aeab7ecd2934d29008c#diff-9bb9cf79fcf14a477f1dd3bdc15d0917L26

And judging from changelog: https://github.com/libjpeg-turbo/libjpeg-turbo/blob/master/ChangeLog.md#202
Your latest build may resolve: https://github.com/lovell/sharp-libvips/commit/d020125bbad373b0bfd296bfa18d60c24fc7ddf4#diff-9bb9cf79fcf14a477f1dd3bdc15d0917L26

There's a bug in Samsung firmware (this is from an S9) that prevents it producing valid JPEG files. The forthcoming v0.22.0 release of sharp will include a more recent version of libvips that can allow these.

For anyone struggling with this issue like we did, you can suppress this error by setting the failOnError option in the sharp constructor to false.

@lovell Hey, when can we expect v0.22.0 ?

@sachinB94 Probably before Samsung, who make ~US$60bn/year in profit, fix their buggy firmware.

sharp v0.22.0 with libvips v8.7.4 now available.

You'll need to explicitly set failOnError: false to read these buggy Samsung images. You must use libvips v8.7.4+ to safely set this option.

Anyone looking for how to set failOnError: false (like I had to do), just give the options object as a second argument. The constructor docs are bit vague about how to give options when input is already given.

sharp(filepath, { failOnError: false })
    .rotate()
    .resize(...)
    etc

Had this error with HDR and panorama images produced with Samsung Galaxy A3. Normal images worked fine.

How do I install libvips v8.7.4+?

@ccorcos npm install sharp should do it for you, unless your system already has libvips (which may cause compability problems)

I have this exact Invalid SOS parameters for sequential JPEG error, and failOnError:false is still not allowing me to read Samsung Gear 360 images with v0.22.1

I then get Input file is missing if I just do a simple .jpeg({ quality: 80 }) .toFile('output.jpg', function(err) { ....
Which I'm assuming is because the decoding failed. Is there something else I could try, or is this more likely caused by Samsung throwing in yet more invalid jpeg info?

@timothyallan Please can you open a new issue with sample code and image that is failing.

@lovell yep will do. Just trying to get a repo case going now. Seems to work if read directly from a file, but piping from a stream fails.

Edit: ping @lovell
https://github.com/lovell/sharp/issues/1691

failOnError: false })

How to set failOnError in stream?

const file = fs.createWriteStream(path);
const thumbnail = fs.createWriteStream(thumb);
const createThumbnail = sharp()
.rotate()
.resize(200, 200);
fields.myimage.pipe(file);
fields.myimage.pipe(createThumbnail).pipe(thumbnail);

@kennethmervin01 Please see #1691

Was this page helpful?
0 / 5 - 0 ratings

Related issues

terbooter picture terbooter  路  3Comments

jaekunchoi picture jaekunchoi  路  3Comments

OleVik picture OleVik  路  3Comments

janaz picture janaz  路  3Comments

genifycom picture genifycom  路  3Comments