Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot convert JPEG file: improper call to JPEG library in state 201 #6475

Open
JanMiddelkoop opened this issue Jul 10, 2023 · 7 comments
Open

Comments

@JanMiddelkoop
Copy link

JanMiddelkoop commented Jul 10, 2023

ImageMagick version

7.1.1.12-1.el9

Operating system

Linux

Operating system, version and so on

AlmaLinux 9.2

Description

Hi!

There seems be a regression in the latest version. With 7.1.1.11 I am able to convert the attached image without any issues, warnings, whatsover. With 7.1.1.12 I get errors from ImageMagick while converting this JPEG image about premature end and the convert seems to fail. Although it does produce some images.

Thanks in advance. :-)

Steps to Reproduce

$ convert -verbose bestand_2720_anton_64a9b50996023.jpg bestand_2720_anton_64a9b50996023.png
bestand_2720_anton_64a9b50996023.jpg[0] JPEG 4608x3456 4608x3456+0+0 8-bit sRGB 5.53477MiB 0.280u 0:00.295
bestand_2720_anton_64a9b50996023.jpg[0] JPEG 4608x3456 4608x3456+0+0 8-bit sRGB 4.95703MiB 0.150u 0:00.155
writing raw profile: type=mpf, length=82
writing raw profile: type=xmp, length=3965
bestand_2720_anton_64a9b50996023.jpg=>bestand_2720_anton_64a9b50996023.png[0] JPEG 4608x3456 4608x3456+0+0 8-bit sRGB 5.53477MiB 7.770u 0:07.247
writing raw profile: type=mpf, length=82
writing raw profile: type=xmp, length=3965
bestand_2720_anton_64a9b50996023.jpg=>bestand_2720_anton_64a9b50996023.png[1] JPEG 4608x3456 4608x3456+0+0 8-bit sRGB 4.95703MiB 14.630u 0:13.590
convert: Premature end of JPEG file `/tmp/magick-fYqNZLmEg0tGfuorQxH9WmUioCepE1iw' @ warning/jpeg.c/JPEGWarningHandler/403.
convert: insufficient image data in file `/tmp/magick-fYqNZLmEg0tGfuorQxH9WmUioCepE1iw' @ error/jpeg.c/ReadProfileData/478.
convert: Improper call to JPEG library in state 201 `/tmp/magick-fYqNZLmEg0tGfuorQxH9WmUioCepE1iw' @ error/jpeg.c/JPEGErrorHandler/348.

Images

bestand_2720_anton_64a9b50996023

@snibgo
Copy link

snibgo commented Jul 10, 2023

The file is MPF (Multi-Picture Format), with two images. IM has only recently acquired to ability to read the images after the first, and I suspect a problem in that area.

The file is unusual in that it has 434 extra bytes (0xFF) between the EOI of the first image and the SOI of the second image. These extra bytes are legal, but may be causing problems to IM.

A developer may comment.

@dlemstra
Copy link
Member

I can reproduce this issue and it looks like we made a mistake when adding support for MPF. I am working on a fix and it looks like this file contains three images. I will continue working on this tomorrow (het is nu wat laat) and try to get this resolved before the next release.

@JanMiddelkoop
Copy link
Author

Much appreciated! Welterusten. ;-)

@fmw42
Copy link

fmw42 commented Jul 11, 2023

Dirk, it does not convert for me either on my Mac OSX Ventura (M1).

magick 252267836-6d4d0a89-510d-4fa0-8b73-d96ea8144908.jpg x.png

magick: Premature end of JPEG file `/tmp/magick-V-8Hv7XgOWtznp2TO2Ro_TS2bLmAyIAO' @ warning/jpeg.c/JPEGWarningHandler/403.
magick: insufficient image data in file `/tmp/magick-V-8Hv7XgOWtznp2TO2Ro_TS2bLmAyIAO' @ error/jpeg.c/ReadProfileData/478.
magick: Improper call to JPEG library in state 201 `/tmp/magick-V-8Hv7XgOWtznp2TO2Ro_TS2bLmAyIAO' @ error/jpeg.c/JPEGErrorHandler/348.

Prefacing with MPO: also does not work

magick MPO:252267836-6d4d0a89-510d-4fa0-8b73-d96ea8144908.jpg x.png

magick: Premature end of JPEG file /tmp/magick-N3yK6_WvgXocx4JXRlsjRE-ZyxIuttLE' @ warning/jpeg.c/JPEGWarningHandler/403. magick: insufficient image data in file /tmp/magick-N3yK6_WvgXocx4JXRlsjRE-ZyxIuttLE' @ error/jpeg.c/ReadProfileData/478.
magick: Improper call to JPEG library in state 201 `/tmp/magick-N3yK6_WvgXocx4JXRlsjRE-ZyxIuttLE' @ error/jpeg.c/JPEGErrorHandler/348.

Nor does changing the suffix to mpo

magick 252267836-6d4d0a89-510d-4fa0-8b73-d96ea8144908.mpo x.png

magick: Premature end of JPEG file /tmp/magick-ZxDUEkeSRJYWMjYSQsPqK9O6WxjnNwbH' @ warning/jpeg.c/JPEGWarningHandler/403. magick: insufficient image data in file /tmp/magick-ZxDUEkeSRJYWMjYSQsPqK9O6WxjnNwbH' @ error/jpeg.c/ReadProfileData/478.
magick: Improper call to JPEG library in state 201 `/tmp/magick-ZxDUEkeSRJYWMjYSQsPqK9O6WxjnNwbH' @ error/jpeg.c/JPEGErrorHandler/348.

@snibgo
Copy link

snibgo commented Jul 12, 2023

@dlemstra wrote:

I am working on a fix and it looks like this file contains three images.

exiftool agrees with my analysis, that there are 2 MPF images. The first of these also contains an embedded thumbnail.

@dlemstra
Copy link
Member

Yeah that embedded thumbnail is causing ImageMagick to think that there are 3 images instead of two. I will need to redesign how we are attempting to read the MPF image(s).

dlemstra added a commit that referenced this issue Jul 13, 2023
@dlemstra
Copy link
Member

This issue should be fixed in the next release. We will no longer try to read the MPF image. We will only do that if the extension of the image is .mpo or if is provided explicitly mpo:file.jpeg.

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

No branches or pull requests

4 participants