Description
There is a bug in UnrestrictedFallbackResolver (an embedded class in AbstractImageSessionContext) which causes it to open an input stream for the wrong resource (the Source) instead of the uri of the image passed to createSource(...).
This happens whenever the systemId in the Source starts with file:. Instead of opening a FileInputStream for the image referenced by uri, a stream for the URI in the Source's systemId is opened.
I discovered this because FOP is unable to include images in a PDF in one of our applications. Instead of reading the image file, it tries to use the FOP document as an image. I was able to avoid this problem on the FOP level by using EnvironmentalProfileFactory.createRestrictedIO(...), which switches to the RestricedFallbackResolver which does not have the problem.
A patch for AbstractImageSessionContext.java is attached (xmlgraphics-commons-patch-1.txt).
Also attached is a Zip file countaining a Maven project (test-unrestricted-fallback-resolver.zip). Running mvn test on this project will run 6 unit tests, repeating the same tests 3 times to show the different behaviour between
- UnrestrictedFallbackResolver (where the test recreating the conditions described above fails)
- RestricedFallbackResolver
- a class containing the patched version of UnrestrictedFallbackResolver