You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by je...@apache.org on 2013/09/03 11:43:40 UTC
svn commit: r1519620 -
/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/JPEGFile.java
Author: jeremias
Date: Tue Sep 3 09:43:39 2013
New Revision: 1519620
URL: http://svn.apache.org/r1519620
Log:
XGC-85: Make JPEGFile more resilient against potentially malformed JPEGs.
Modified:
xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/JPEGFile.java
Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/JPEGFile.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/JPEGFile.java?rev=1519620&r1=1519619&r2=1519620&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/JPEGFile.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/JPEGFile.java Tue Sep 3 09:43:39 2013
@@ -65,20 +65,20 @@ public class JPEGFile implements JPEGCon
/**
* Reads the next marker segment identifier and returns it.
* @return the marker segment identifier
- * @throws IOException if an I/O error occurs while reading from the image file or if
- * the stream is not positioned at a marker segment header
+ * @throws IOException if an I/O error occurs while reading from the image file
*/
public int readMarkerSegment() throws IOException {
int marker;
- int count = 0;
do {
marker = in.readByte() & 0xFF;
- count++;
+ //Skip any non-0xFF bytes (useful for JPEG files with bad record lengths)
} while (marker != MARK);
- if (count > 1) {
- throw new IOException("Stream not positioned at a marker segment header");
- }
- int segID = in.readByte() & 0xFF;
+
+ int segID;
+ do {
+ segID = in.readByte() & 0xFF;
+ //Skip any pad bytes (0xFF) which are legal here.
+ } while (segID == 0xFF);
return segID;
}
@@ -86,7 +86,7 @@ public class JPEGFile implements JPEGCon
* Reads the segment length of the current marker segment and returns it.
* The method assumes the file cursor is right after the segment header.
* @return the segment length
- * @throws IOException
+ * @throws IOException if an I/O error occurs while reading from the image file
*/
public int readSegmentLength() throws IOException {
int reclen = in.readUnsignedShort();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org