[ 
https://issues.apache.org/jira/browse/FOP-3022?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17499365#comment-17499365
 ] 

Johannes commented on FOP-3022:
-------------------------------

Yes, in my comment on 22/Jul/21 11:39 I already wrote that the invalid PNG 
turned out to be the root cause.

What was nevertheless incorrect was the error handling and fallback: In case of 
an invalid PNG I would expect an error message like "Invalid PNG" instead of a 
mysterious "No ImagePreloader found" pointing me to a completely wrong 
direction, so I was looking for configuration issues or PNG not being supported 
anymore at all. The behaviour changed between versions 2.3 and 2.6 and I was 
hunting for the reason.

As you can see in my analysis in the original error description (result of 
debugging my application with the sources of version 2.6 attached), this 
originated from the system ID being set to a questionable value so that 
fallback attempts reading the PNG led to unexpected execution paths attempting 
to read the config file as PNG and therefore to such a not understandable/very 
misleading error message.

> Embedded PNG and PNG with relative path: No ImagePreloader found
> ----------------------------------------------------------------
>
>                 Key: FOP-3022
>                 URL: https://issues.apache.org/jira/browse/FOP-3022
>             Project: FOP
>          Issue Type: Bug
>          Components: image/png
>    Affects Versions: 2.6
>            Reporter: Johannes
>            Priority: Major
>         Attachments: content.xml, fo.xsl
>
>
> A PDF with an embedded PNG and another PNG with a relative URL does not 
> contain either of these images (as it worked before in FOP version 2.3).
> This is the error reported in the debug trace:
> Image not available. URI: 
> data:image/png;base64,0000C3E449BA11000000000000000000F33319879C248B7149B918E031DA9E37336F93FA7DE2500F377C435E31F7DCE86730D41D33A8.
>  Reason: org.apache.xmlgraphics.image.loader.ImageException: The file format 
> is not supported. No ImagePreloader found for 
> data:image/png;base64,0000C3E449BA11000000000000000000F33319879C248B7149B918E031DA9E37336F93FA7DE2500F377C435E31F7DCE86730D41D33A8
>  (No context info available)
> org.apache.xmlgraphics.image.loader.ImageException: The file format is not 
> supported. No ImagePreloader found for 
> data:image/png;base64,0000C3E449BA11000000000000000000F33319879C248B7149B918E031DA9E37336F93FA7DE2500F377C435E31F7DCE86730D41D33A8
> Result of debugging (using FOP 2.6 sources):
>  * FOUserAgent.resolveURI creates a StreamSource from the PNG. The resource 
> URI is correctly resolved (i.e. the StreamSource has an InputStream on the 
> PNG) but the method sets an invalid systemId (the base URI of the resource 
> resolver, which points to the config file, cfg.xml in our case)
>  * AbstractImageSessionContext.newSource (from xmlgraphics-commons-2.6; 
> instantiated in the FOUserAgent constructor) uses the fallbackResolver for 
> any StreamSource.
>  * AbstractImageSessionContext.UnrestrictedFallbackResolver.createSource 
> quietly closes the InputStream of the StreamSource and requests the systemId 
> from ImageIO instead (code comment: "We let the OS' file system cache do the 
> caching for us --> lower Java memory consumption, probably no speed loss")
> Thus it opens a stream on the cfg.xml instead of the image
>  * Consequentually, PreloaderRawPNG doesn't feel responsible for the wrong 
> PNG because it doesn't start with the PNG signature 
> (PNGConstants.PNG_SIGNATURE) - which is caused by reading a completely 
> different file than the PNG
> Same behaviour also for another PNG included with a simple relative file URL 
> (<fo:external-graphic src="url('subdir/myimage.png')" /> hardcoded in the 
> XSL).
> The issue is reproducible as well when running the generation standalone from 
> the command line (using -xml, -xsl and -pdf options).
>  



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to