xmlgraphics-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Carsten Pfeiffer (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (XGC-99) PNGFile.getImageRawPNG() returns broken image data
Date Fri, 31 Jul 2015 08:37:05 GMT

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

Carsten Pfeiffer commented on XGC-99:
-------------------------------------

Yes, the image is valid. It happens with any PNG though. The reason is that that the streamVec
only holds parts of the actual bytes of the png file. Specifically, the magic header is missing.

Here's a stacktrace of how it's used in FOP:

{code}
Thread [ModalContext] (Suspended (breakpoint at line 71 in PNGFile))	
	PNGFile.<init>(InputStream) line: 71	
	ImageLoaderRawPNG.loadImage(ImageInfo, Map, ImageSessionContext) line: 73	
	CompositeImageLoader.loadImage(ImageInfo, Map, ImageSessionContext) line: 84	
	ImageProviderPipeline.execute(ImageInfo, Image, Map, ImageSessionContext) line: 154	
	ImageProviderPipeline.execute(ImageInfo, Map, ImageSessionContext) line: 99	
	ImageManager.getImage(ImageInfo, ImageFlavor[], Map, ImageSessionContext) line: 269	
	RTFHandler.putGraphic(AbstractGraphics, ImageInfo) line: 1192	
	RTFHandler.image(ExternalGraphic) line: 1108	
	RTFHandler.invokeDeferredEvent(FONode, boolean) line: 1561	
	RTFHandler.recurseFONode(FONode) line: 1728	
	RTFHandler.recurseFONode(FONode) line: 1803	
	RTFHandler.recurseFONode(FONode) line: 1803	
	RTFHandler.recurseFONode(FONode) line: 1803	
	RTFHandler.recurseFONode(FONode) line: 1803	
	RTFHandler.recurseFONode(FONode) line: 1751	
	RTFHandler.endPageSequence(PageSequence) line: 270	
	PageSequence.endOfNode() line: 130	
	FOTreeBuilder$MainFOHandler.endElement(String, String, String) line: 360	
	FOTreeBuilder.endElement(String, String, String) line: 190	
{code}

This is where it reads the PNG contents from the ImageRawPNG in RTFHandler.putGraphic():
{code}
        if (image instanceof ImageRawStream) {
            ImageRawStream rawImage = (ImageRawStream)image;
            InputStream in = rawImage.createInputStream();
            try {
                rawData = IOUtils.toByteArray(in);
            } finally {
                IOUtils.closeQuietly(in);
            }
        }

Thread [ModalContext] (Suspended (breakpoint at line 1260 in RTFHandler))	
	RTFHandler.putGraphic(AbstractGraphics, Image) line: 1260	
	RTFHandler.putGraphic(AbstractGraphics, ImageInfo) line: 1194	
	RTFHandler.image(ExternalGraphic) line: 1108	
	RTFHandler.invokeDeferredEvent(FONode, boolean) line: 1561	
	RTFHandler.recurseFONode(FONode) line: 1728	
{code}

And eventually it fails when checking for the PNG magic header:
{code}
Thread [ModalContext] (Suspended (breakpoint at line 207 in RtfExternalGraphic$FormatPNG))

	owns: RtfFile  (id=713)	
	RtfExternalGraphic$FormatPNG.isFormat(byte[]) line: 207	
	RtfExternalGraphic$FormatBase.determineFormat(byte[]) line: 111	
	RtfExternalGraphic.writeRtfContentWithException() line: 379	
	RtfExternalGraphic.writeRtfContent() line: 322	
	RtfExternalGraphic(RtfElement).writeRtf() line: 87	
	RtfTextrun.writeRtfContent() line: 483	
{code}


> PNGFile.getImageRawPNG() returns broken image data
> --------------------------------------------------
>
>                 Key: XGC-99
>                 URL: https://issues.apache.org/jira/browse/XGC-99
>             Project: XMLGraphicsCommons
>          Issue Type: Bug
>          Components: image codecs
>    Affects Versions: 2.0.1, trunk
>            Reporter: Carsten Pfeiffer
>
> The ImageRawPNG returned by PNGFile.getImageRawPNG() is broken because the provided InputStream
(streamVec) contains only part of the raw image data. For a start the magic header is missing,
but it's not enough to add it.
> To fix this, I copied the entire stream in the PNGFile constructor like this:
> {code}
>         stream.mark(Integer.MAX_VALUE);
>         ByteArrayOutputStream out = new ByteArrayOutputStream();
>         IOUtils.copy(stream, out);
>         rawStream = new ByteArrayInputStream(out.toByteArray());
>         out = null;
>         stream.reset();
> {code}
> and use the rawStream in favor of streamVec, which can be removed then.
> Testcases still run successful. This fixes RTF output not working with PNG files in FOP
because it checks for (missing) the PNG magic header.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: general-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: general-help@xmlgraphics.apache.org


Mime
View raw message