From 300ac95fdc1729f14ae40c5dfe78d9f8a332bece Mon Sep 17 00:00:00 2001 From: Vincent Hennebert Date: Tue, 29 May 2007 07:51:52 +0000 Subject: [PATCH] Bug #42476: - fix NPE in XMLReader when no handler is found for the image - prevent SVGReader from closing the input stream if the image actually isn't SVG - reduce log level in SVGReader and XMLReader to avoid "false positive" (read error reported whereas the image format actually isn't recognized). This may hide regular I/O errors to the end-user, but I assume this will be rare enough compared to the annoyance of such messages when third-party plugins are used. Patch submitted by Max Berger (max.at.berger.name) git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@542447 13f79535-47bb-0310-9956-ffa450edef68 --- .../image/analyser/ImageReaderFactory.java | 2 + .../apache/fop/image/analyser/SVGReader.java | 58 ++----------------- .../apache/fop/image/analyser/XMLReader.java | 19 ++++-- .../fop/util/UnclosableInputStream.java | 46 +++++++++++++++ 4 files changed, 66 insertions(+), 59 deletions(-) create mode 100644 src/java/org/apache/fop/util/UnclosableInputStream.java diff --git a/src/java/org/apache/fop/image/analyser/ImageReaderFactory.java b/src/java/org/apache/fop/image/analyser/ImageReaderFactory.java index 4e4c4bce7..b9621474f 100644 --- a/src/java/org/apache/fop/image/analyser/ImageReaderFactory.java +++ b/src/java/org/apache/fop/image/analyser/ImageReaderFactory.java @@ -87,6 +87,8 @@ public class ImageReaderFactory { return info; } } + log.warn("No ImageReader found for " + uri); + in.close(); } catch (IOException ex) { log.error("Error while recovering Image Informations (" + uri + ")", ex); diff --git a/src/java/org/apache/fop/image/analyser/SVGReader.java b/src/java/org/apache/fop/image/analyser/SVGReader.java index b487572a5..da702d0c1 100644 --- a/src/java/org/apache/fop/image/analyser/SVGReader.java +++ b/src/java/org/apache/fop/image/analyser/SVGReader.java @@ -43,6 +43,7 @@ import org.apache.fop.image.XMLImage; import org.apache.fop.image.FopImage; import org.apache.fop.apps.FOUserAgent; import org.apache.fop.svg.SVGUserAgent; +import org.apache.fop.util.UnclosableInputStream; /** * ImageReader object for SVG document image type. @@ -112,58 +113,7 @@ public class SVGReader implements ImageReader { // parse document and get the size attributes of the svg element try { - int length = 5; - fis.mark(length); - byte[] b = new byte[length]; - fis.read(b); - String start = new String(b); - fis.reset(); - - //TODO "true ||" here is a hack to improve SVG detection rate. Please improve. - if (true || start.equals("not close the original stream. + */ + public void close() { + // ignore + } + +} -- 2.39.5