Author: markt Date: Thu Oct 4 16:08:35 2012 New Revision: 1394127 URL: http://svn.apache.org/viewvc?rev=1394127&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53725 Fix possible corruption of GZIP'd output.
Modified: tomcat/tc6.0.x/trunk/STATUS.txt tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/FlushableGZIPOutputStream.java tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Modified: tomcat/tc6.0.x/trunk/STATUS.txt URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=1394127&r1=1394126&r2=1394127&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/STATUS.txt (original) +++ tomcat/tc6.0.x/trunk/STATUS.txt Thu Oct 4 16:08:35 2012 @@ -89,13 +89,6 @@ PATCHES PROPOSED TO BACKPORT: +1: schultz, kkolinko, jfclere -1: -* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53725 - Fix possible corruption of GZIP'd output. - http://svn.apache.org/viewvc?rev=1378403&view=rev - http://svn.apache.org/viewvc?rev=1378408&view=rev - +1: kkolinko, jfclere, markt - -1: - * Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53793 Change links on the list of applications in the Manager to point to '/appname/' instead of '/appname'. Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/FlushableGZIPOutputStream.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/FlushableGZIPOutputStream.java?rev=1394127&r1=1394126&r2=1394127&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/FlushableGZIPOutputStream.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/filters/FlushableGZIPOutputStream.java Thu Oct 4 16:08:35 2012 @@ -42,6 +42,12 @@ public class FlushableGZIPOutputStream e private byte[] lastByte = new byte[1]; private boolean hasLastByte = false; + /** + * Flag that compression has to be re-enabled before the next write + * operation. + */ + private boolean flagReenableCompression = false; + @Override public void write(byte[] bytes) throws IOException { write(bytes, 0, bytes.length); @@ -53,6 +59,7 @@ public class FlushableGZIPOutputStream e if (length > 0) { flushLastByte(); if (length > 1) { + reenableCompression(); super.write(bytes, offset, length - 1); } rememberLastByte(bytes[offset + length - 1]); @@ -89,6 +96,13 @@ public class FlushableGZIPOutputStream e super.close(); } + private void reenableCompression() { + if (flagReenableCompression && !def.finished()) { + flagReenableCompression = false; + def.setLevel(Deflater.DEFAULT_COMPRESSION); + } + } + private void rememberLastByte(byte b) { lastByte[0] = b; hasLastByte = true; @@ -96,6 +110,7 @@ public class FlushableGZIPOutputStream e private void flushLastByte() throws IOException { if (hasLastByte) { + reenableCompression(); // Clear the flag first, because write() may fail hasLastByte = false; super.write(lastByte, 0, 1); @@ -118,7 +133,7 @@ public class FlushableGZIPOutputStream e if (!def.finished()) { def.setLevel(Deflater.NO_COMPRESSION); flushLastByte(); - def.setLevel(Deflater.DEFAULT_COMPRESSION); + flagReenableCompression = true; } } out.flush(); @@ -139,5 +154,4 @@ public class FlushableGZIPOutputStream e } } while (len != 0); } - } Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=1394127&r1=1394126&r2=1394127&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Thu Oct 4 16:08:35 2012 @@ -254,6 +254,9 @@ <code>maxHeaderCount</code> attribute on Connector MBean via JMX. (kkolinko) </fix> + <fix> + <bug>53725</bug>: Fix possible corruption of GZIP'd output. (kkolinko) + </fix> </changelog> </subsection> <subsection name="Jasper"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org