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

Converting a jpeg through png to pdf produces a broken pdf. `PDF14 device push/pop out of sync` #463

Closed
d-ph opened this Issue Apr 28, 2017 · 2 comments

Comments

Projects
None yet
1 participant
@d-ph

d-ph commented Apr 28, 2017

Hello,

> convert -version       
Version: ImageMagick 7.0.5-5 Q16 x86_64 2017-04-25 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules 
Delegates (built-in): bzlib freetype jng jpeg ltdl lzma png tiff xml zlib

MacOS, imagemagick installed via homebrew.

Steps to reproduce:

  1. Download 1.jpeg
  2. Run convert 1.jpeg -thumbnail 100x100 1.png
  3. Run convert 1.png 1.pdf
  4. Run identify -verbose 1.pdf

Result:

> identify -verbose 1.pdf 
   **** Error reading a content stream. The page may be incomplete.
               Output may be incorrect.
   **** Error: File did not complete the page properly and may be damaged.
               Output may be incorrect.
+ ./base/gdevp14.c:1860: pdf14_put_image(): PDF14 device push/pop out of sync
Error: /unknownerror in --run--
Operand stack:

Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   1983   1   3   %oparray_pop   1982   1   3   %oparray_pop   1966   1   3   %oparray_pop   --nostringval--   --nostringval--   2   1   1   --nostringval--   %for_pos_int_continue   --nostringval--   --nostringval--
Dictionary stack:
   --dict:1210/1684(ro)(G)--   --dict:1/20(G)--   --dict:83/200(L)--   --dict:83/200(L)--   --dict:137/256(ro)(G)--   --dict:298/300(ro)(G)--   --dict:34/64(L)--   --dict:6/9(L)--   --dict:24/40(L)--   --dict:1/1(ro)(G)--   --dict:9/18(L)--   --dict:4/5(L)--   --dict:0/6(L)--
Current allocation mode is local
GPL Ghostscript 9.21: Unrecoverable error, exit code 1

The file also can't be open with Adobe Reader.

Expected result:

1.pdf can be opened in Adobe Reader.

More info:

In stock Ubuntu 14.04 imagemagick, the following is output for the 1.pdf:

$ identify -verbose 1.pdf 
   **** Error reading a content stream. The page may be incomplete.
   **** File did not complete the page properly and may be damaged.
   **** Warning: File has unbalanced q/Q operators (too many q's)

The problem doesn't happen, when step 2 is run without -thumbnail 100x100

Thanks.

@d-ph

This comment has been minimized.

Show comment
Hide comment
@d-ph

d-ph May 3, 2017

The issue is caused by wrong object references/pointers in the output pdf after the feature introduced by #417 . Every raster file with icc profile is affected. It's just this particular jpeg->png->pdf procedure produces a pdf, that actually can't be opened.

The pdf produced by the steps to reproduce (binary data omitted) (mind the 3 places, that have wrong object references):

%PDF-1.7
1 0 obj
<<
/Pages 2 0 R
/Type /Catalog
>>
endobj
2 0 obj
<<
/Type /Pages
/Kids [ 3 0 R ]
/Count 1
>>
endobj
3 0 obj
<<
/Type /Page
/Parent 2 0 R
/Resources <<
/XObject << /Im0 8 0 R >>
/ProcSet 6 0 R >>
/MediaBox [0 0 100.028 75.0208]
/CropBox [0 0 100.028 75.0208]
/Contents 4 0 R
/Thumb 11 0 R <---------------------- THIS SHOULD SAY 13 0 R
>>
endobj
4 0 obj
<<
/Length 5 0 R
>>
stream
q
100.028 0 0 75.0208 0 0 cm
/Im0 Do
Q

endstream
endobj
5 0 obj
39
endobj
6 0 obj
[ /PDF /Text /ImageC ]
endobj
7 0 obj
<<
>>
endobj
8 0 obj
<<
/Type /XObject
/Subtype /Image
/Name /Im0
/Filter [ /FlateDecode ]
/Width 100
/Height 75
/ColorSpace 10 0 R
/BitsPerComponent 8
/SMask 15 0 R <---------------------- THIS SHOULD SAY 17 0 R
/Length 9 0 R
>>
stream
(binary)
endstream
endobj
9 0 obj
10055
endobj
10 0 obj
[/ICCBased 11 0 R]
endobj
11 0 obj
<<
/N 3
/Filter /ASCII85Decode
/Length 12 0 R
/Alternate /DeviceRGB
>>
stream
(binary)
endstream
endobj
12 0 obj
902
endobj
13 0 obj
<<
/Filter [ /FlateDecode ]
/Width 100
/Height 75
/ColorSpace 12 0 R <---------------------- THIS SHOULD SAY 10 0 R
/BitsPerComponent 8
/Length 14 0 R
>>
stream
(binary)
endstream
endobj
14 0 obj
10055
endobj
15 0 obj
<<
>>
endobj
16 0 obj
10055
endobj
17 0 obj
<<
/Type /XObject
/Subtype /Image
/Name /Ma0
/Filter [ /FlateDecode ]
/Width 100
/Height 75
/ColorSpace /DeviceGray
/BitsPerComponent 8
/Length 18 0 R
>>
stream
(binary)
endstream
endobj
18 0 obj
30
endobj

(the rest is irrelevant)
  1. /Thumb line is generated here
  2. /SMask here
  3. /ColorSpace for the thumbnail here

@dlemstra Object references need to be tracked in such a way, that they take into account the fact, that there might be an icc profile occupying 11 0 obj and 12 0 obj.

It's probably worth double checking, whether all other object references take that into account.

d-ph commented May 3, 2017

The issue is caused by wrong object references/pointers in the output pdf after the feature introduced by #417 . Every raster file with icc profile is affected. It's just this particular jpeg->png->pdf procedure produces a pdf, that actually can't be opened.

The pdf produced by the steps to reproduce (binary data omitted) (mind the 3 places, that have wrong object references):

%PDF-1.7
1 0 obj
<<
/Pages 2 0 R
/Type /Catalog
>>
endobj
2 0 obj
<<
/Type /Pages
/Kids [ 3 0 R ]
/Count 1
>>
endobj
3 0 obj
<<
/Type /Page
/Parent 2 0 R
/Resources <<
/XObject << /Im0 8 0 R >>
/ProcSet 6 0 R >>
/MediaBox [0 0 100.028 75.0208]
/CropBox [0 0 100.028 75.0208]
/Contents 4 0 R
/Thumb 11 0 R <---------------------- THIS SHOULD SAY 13 0 R
>>
endobj
4 0 obj
<<
/Length 5 0 R
>>
stream
q
100.028 0 0 75.0208 0 0 cm
/Im0 Do
Q

endstream
endobj
5 0 obj
39
endobj
6 0 obj
[ /PDF /Text /ImageC ]
endobj
7 0 obj
<<
>>
endobj
8 0 obj
<<
/Type /XObject
/Subtype /Image
/Name /Im0
/Filter [ /FlateDecode ]
/Width 100
/Height 75
/ColorSpace 10 0 R
/BitsPerComponent 8
/SMask 15 0 R <---------------------- THIS SHOULD SAY 17 0 R
/Length 9 0 R
>>
stream
(binary)
endstream
endobj
9 0 obj
10055
endobj
10 0 obj
[/ICCBased 11 0 R]
endobj
11 0 obj
<<
/N 3
/Filter /ASCII85Decode
/Length 12 0 R
/Alternate /DeviceRGB
>>
stream
(binary)
endstream
endobj
12 0 obj
902
endobj
13 0 obj
<<
/Filter [ /FlateDecode ]
/Width 100
/Height 75
/ColorSpace 12 0 R <---------------------- THIS SHOULD SAY 10 0 R
/BitsPerComponent 8
/Length 14 0 R
>>
stream
(binary)
endstream
endobj
14 0 obj
10055
endobj
15 0 obj
<<
>>
endobj
16 0 obj
10055
endobj
17 0 obj
<<
/Type /XObject
/Subtype /Image
/Name /Ma0
/Filter [ /FlateDecode ]
/Width 100
/Height 75
/ColorSpace /DeviceGray
/BitsPerComponent 8
/Length 18 0 R
>>
stream
(binary)
endstream
endobj
18 0 obj
30
endobj

(the rest is irrelevant)
  1. /Thumb line is generated here
  2. /SMask here
  3. /ColorSpace for the thumbnail here

@dlemstra Object references need to be tracked in such a way, that they take into account the fact, that there might be an icc profile occupying 11 0 obj and 12 0 obj.

It's probably worth double checking, whether all other object references take that into account.

dlemstra pushed a commit that referenced this issue May 7, 2017

dlemstra pushed a commit that referenced this issue May 7, 2017

@d-ph

This comment has been minimized.

Show comment
Hide comment
@d-ph

d-ph May 8, 2017

@dlemstra

The issue is fixed on both master and ImageMagick-6 branch. Thank you very much. I'm closing this ticket now.

d-ph commented May 8, 2017

@dlemstra

The issue is fixed on both master and ImageMagick-6 branch. Thank you very much. I'm closing this ticket now.

@d-ph d-ph closed this May 8, 2017

jsonn pushed a commit to jsonn/pkgsrc that referenced this issue May 14, 2017

he
Upgrade to ImageMagick version 7.0.5-6.
Upstream changes:
2017-05-12  7.0.5-6 Cristy  <quetzlzacatenango@image...>
  * Release ImageMagick version 7.0.5-6, GIT revision 20039:9371904:20170512.

2017-05-10  7.0.5-6 John Cupitt <jcupitt@gmail.com>
  * Revise DICOM window and rescale handling (reference
    ImageMagick/ImageMagick#484)

2017-05-06  7.0.5-6 Cristy  <quetzlzacatenango@image...>
  * Restore the -alpha Shape option (reference
    https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=31879).
  * Fix transient PDF bug (reference
    ImageMagick/ImageMagick#463).
  * The +opaque option now works on all channels (reference
    https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=31862).
  * Ensure backwards compatibility for the -combine option (reference
    https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=31855).
  * Check for EOF conditions for RLE image format.
  * Reset histogram page geometry (reference
    https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=31920).

jsonn pushed a commit to jsonn/pkgsrc that referenced this issue May 17, 2017

he
Upgrade ImageMagick6 from 6.9.7.9 to 6.9.8.5.
Pkgsrc changes:
Adapt to new version, PLIST (2 new files).

Upstream changes:
2017-05-12  6.9.8-5 Cristy  <quetzlzacatenango@image...>
  * Release ImageMagick version 6.9.8-5, GIT revision 11575:186b15d:20170512.

2017-05-10  6.9.8-5 John Cupitt <jcupitt@gmail.com>
  * Revise DICOM window and rescale handling (reference
    ImageMagick/ImageMagick#484)

2017-05-08  6.9.8-5 Cristy  <quetzlzacatenango@image...>
  * Fix transient PDF bug (reference
    ImageMagick/ImageMagick#463).
  * Check for EOF conditions for RLE image format.
  * Reset histogram page geometry (reference
    https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=31920).

2017-04-24  6.9.8-4 Cristy  <quetzlzacatenango@image...>
  * Release ImageMagick version 6.9.8-4, GIT revision 11521:d7433aa:20170424.

2017-03-26  6.9.8-4 Cristy  <quetzlzacatenango@image...>
  * Minimize buffer copies to improve OpenCL performance.
  * Patch a PCD writer problem, dark pixels (reference
    https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=3164).
  * Support ICC based PDF's (reference
    ImageMagick/ImageMagick#417).

2017-03-24  6.9.8-3 Cristy  <quetzlzacatenango@image...>
  * Release ImageMagick version 6.9.8-3, GIT revision 11444:3f523e5:20170324.

2017-03-20  6.9.8-3 Cristy  <quetzlzacatenango@image...>
  * MagickWand-config, use --cflags, not --clags (reference
    https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=31602).
  * Respect -loop option for animate -window (reference
    https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=31619).

2017-03-18  6.9.8-2 Cristy  <quetzlzacatenango@image...>
  * Release ImageMagick version 6.9.8-2, GIT revision 11436:a912791:20170318.

2017-03-14  6.9.8-2 Cristy  <quetzlzacatenango@image...>
  * Support namespaces for the security policy.

2017-03-11  6.9.8-1 Cristy  <quetzlzacatenango@image...>
  * Release ImageMagick version 6.9.8-1.

2017-03-03  6.9.8-0 Cristy  <quetzlzacatenango@image...>
  * Release ImageMagick version 6.9.8-0, GIT revision 11408:da91a7c:20170311.

2017-03-06  6.9.8-0 Cristy  <quetzlzacatenango@image...>
  * Respect throttle policy (reference
    ImageMagick/ImageMagick#393).
  * Support the -authenticate option for PDF (reference
    https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=31530).

2017-03-03  6.9.7-10 Cristy  <quetzlzacatenango@image...>
  * Release ImageMagick version 6.9.7-10, GIT revision 11396:44b1bc6:20170303.

2017-02-21  6.9.7-10 Cristy  <quetzlzacatenango@image...>
  * Fix Spurious memory allocation message (reference
    https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=31438).
  * Identical images should return inf for PSNR (reference
    https://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=31487).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment