Author: toad
Date: 2007-11-13 13:14:48 +0000 (Tue, 13 Nov 2007)
New Revision: 15774

Modified:
   trunk/freenet/src/freenet/clients/http/filter/JPEGFilter.java
Log:
If we are in scan-only mode, and there is data past EOI, switch to scan-copy 
mode to dump the excess data.
Will fix some perverse JPEGs.

Modified: trunk/freenet/src/freenet/clients/http/filter/JPEGFilter.java
===================================================================
--- trunk/freenet/src/freenet/clients/http/filter/JPEGFilter.java       
2007-11-12 23:53:28 UTC (rev 15773)
+++ trunk/freenet/src/freenet/clients/http/filter/JPEGFilter.java       
2007-11-13 13:14:48 UTC (rev 15774)
@@ -98,7 +98,7 @@

                        boolean finished = false;
                        int forceMarkerType = -1;
-                       while(!finished) {
+                       while(dos == null || !finished) {
                                if(baos != null)
                                        baos.reset();
                                int markerType;
@@ -110,9 +110,13 @@
                                        if(markerStart == -1) {
                                                // No more chunks to scan.
                                                break;
+                                       } else if(finished) {
+                                               if(logMINOR)
+                                                       Logger.minor(this, 
"More data after EOI, copying to truncate");
+                                               return null;
                                        }
                                        if(markerStart != 0xFF) {
-                                               throwError("Invalid marker", 
"The file includes an invalid marker "+Integer.toHexString(markerStart)+" and 
cannot be parsed further.");
+                                               throwError("Invalid marker", 
"The file includes an invalid marker start "+Integer.toHexString(markerStart)+" 
and cannot be parsed further.");
                                        }
                                        if(baos != null) baos.write(0xFF);
                                        markerType = dis.readUnsignedByte();
@@ -257,9 +261,7 @@
                                        skipRest(blockLength, countAtStart, 
cis, dis, dos, "comment");
                                } else if(markerType == 0xD9) {
                                        // End of image
-                                       if(dos != null) {
-                                               finished = true;
-                                       }
+                                       finished = true;
                                        if(logMINOR)
                                                Logger.minor(this, "End of 
image");
                                } else {


Reply via email to