Author: markt Date: Mon Apr 23 18:46:04 2018 New Revision: 1829915 URL: http://svn.apache.org/viewvc?rev=1829915&view=rev Log: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=62301 Correct a regression in the fix for bz 61491 that didn't correctly handle a final empty message part in all circumstances when using PerMessageDeflate.
Modified: tomcat/trunk/java/org/apache/tomcat/websocket/PerMessageDeflate.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/java/org/apache/tomcat/websocket/PerMessageDeflate.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/websocket/PerMessageDeflate.java?rev=1829915&r1=1829914&r2=1829915&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/websocket/PerMessageDeflate.java (original) +++ tomcat/trunk/java/org/apache/tomcat/websocket/PerMessageDeflate.java Mon Apr 23 18:46:04 2018 @@ -58,6 +58,8 @@ public class PerMessageDeflate implement private volatile boolean skipDecompression = false; private volatile ByteBuffer writeBuffer = ByteBuffer.allocate(Constants.DEFAULT_BUFFER_SIZE); private volatile boolean firstCompressedFrameWritten = false; + // Flag to track if a message is completely empty + private volatile boolean emptyMessage = true; static PerMessageDeflate negotiate(List<List<Parameter>> preferences, boolean isServer) { // Accept the first preference that the endpoint is able to support @@ -315,9 +317,6 @@ public class PerMessageDeflate implement public List<MessagePart> sendMessagePart(List<MessagePart> uncompressedParts) { List<MessagePart> allCompressedParts = new ArrayList<>(); - // Flag to track if a message is completely empty - boolean emptyMessage = true; - for (MessagePart uncompressedPart : uncompressedParts) { byte opCode = uncompressedPart.getOpCode(); boolean emptyPart = uncompressedPart.getPayload().limit() == 0; @@ -343,7 +342,7 @@ public class PerMessageDeflate implement int flush = (uncompressedPart.isFin() ? Deflater.SYNC_FLUSH : Deflater.NO_FLUSH); boolean deflateRequired = true; - while(deflateRequired) { + while (deflateRequired) { ByteBuffer compressedPayload = writeBuffer; int written = deflater.deflate(compressedPayload.array(), @@ -450,6 +449,7 @@ public class PerMessageDeflate implement private void startNewMessage() { firstCompressedFrameWritten = false; + emptyMessage = true; if (isServer && !serverContextTakeover || !isServer && !clientContextTakeover) { deflater.reset(); } Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1829915&r1=1829914&r2=1829915&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Mon Apr 23 18:46:04 2018 @@ -109,6 +109,15 @@ </fix> </changelog> </subsection> + <subsection name="WebSocket"> + <changelog> + <fix> + <bug>62301</bug>: Correct a regression in the fix for <bug>61491</bug> + that didn't correctly handle a final empty message part in all + circumstances when using <code>PerMessageDeflate</code>. (markt) + </fix> + </changelog> + </subsection> </section> <section name="Tomcat 9.0.7 (markt)" rtext="2018-04-07"> <subsection name="Catalina"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org