This is an automated email from the ASF dual-hosted git repository.

markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/master by this push:
     new 3e03cee  Fix HTTP/2 window updates with zero padding. Found via CI 
tests
3e03cee is described below

commit 3e03ceefd549684ba26b4af0e6cf738b2a1dd42e
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Oct 8 14:20:53 2020 +0100

    Fix HTTP/2 window updates with zero padding. Found via CI tests
---
 java/org/apache/coyote/http2/Http2AsyncUpgradeHandler.java |  5 +++--
 java/org/apache/coyote/http2/Http2UpgradeHandler.java      | 11 +++++------
 webapps/docs/changelog.xml                                 |  9 +++++++++
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/java/org/apache/coyote/http2/Http2AsyncUpgradeHandler.java 
b/java/org/apache/coyote/http2/Http2AsyncUpgradeHandler.java
index defbb1c..b77fee6 100644
--- a/java/org/apache/coyote/http2/Http2AsyncUpgradeHandler.java
+++ b/java/org/apache/coyote/http2/Http2AsyncUpgradeHandler.java
@@ -229,14 +229,15 @@ public class Http2AsyncUpgradeHandler extends 
Http2UpgradeHandler {
 
 
     @Override
-    void writeWindowUpdate(Stream stream, int increment, boolean 
applicationInitiated)
+    void writeWindowUpdate(AbstractNonZeroStream stream, int increment, 
boolean applicationInitiated)
             throws IOException {
         // Build window update frame for stream 0
         byte[] frame = new byte[13];
         ByteUtil.setThreeBytes(frame, 0,  4);
         frame[3] = FrameType.WINDOW_UPDATE.getIdByte();
         ByteUtil.set31Bits(frame, 9, increment);
-        if (stream.canWrite()) {
+        // No need to send update from closed stream
+        if  (stream instanceof Stream && ((Stream) stream).canWrite()) {
             // Change stream Id
             byte[] frame2 = new byte[13];
             ByteUtil.setThreeBytes(frame2, 0,  4);
diff --git a/java/org/apache/coyote/http2/Http2UpgradeHandler.java 
b/java/org/apache/coyote/http2/Http2UpgradeHandler.java
index 972a709..0307ece 100644
--- a/java/org/apache/coyote/http2/Http2UpgradeHandler.java
+++ b/java/org/apache/coyote/http2/Http2UpgradeHandler.java
@@ -802,7 +802,7 @@ class Http2UpgradeHandler extends AbstractStream implements 
InternalHttpUpgradeH
      * Needs to know if this was application initiated since that affects the
      * error handling.
      */
-    void writeWindowUpdate(Stream stream, int increment, boolean 
applicationInitiated)
+    void writeWindowUpdate(AbstractNonZeroStream stream, int increment, 
boolean applicationInitiated)
             throws IOException {
         synchronized (socketWrapper) {
             // Build window update frame for stream 0
@@ -811,7 +811,8 @@ class Http2UpgradeHandler extends AbstractStream implements 
InternalHttpUpgradeH
             frame[3] = FrameType.WINDOW_UPDATE.getIdByte();
             ByteUtil.set31Bits(frame, 9, increment);
             socketWrapper.write(true, frame, 0, frame.length);
-            if  (stream.canWrite()) {
+            // No need to send update from closed stream
+            if  (stream instanceof Stream && ((Stream) stream).canWrite()) {
                 // Change stream Id and re-use
                 ByteUtil.set31Bits(frame, 5, stream.getIdAsInt());
                 try {
@@ -1488,10 +1489,8 @@ class Http2UpgradeHandler extends AbstractStream 
implements InternalHttpUpgradeH
     public void swallowedPadding(int streamId, int paddingLength) throws
             ConnectionException, IOException {
         AbstractNonZeroStream abstractNonZeroStream = 
getStreamMayBeClosed(streamId, true);
-        if (abstractNonZeroStream instanceof Stream) {
-            // +1 is for the payload byte used to define the padding length
-            writeWindowUpdate((Stream) abstractNonZeroStream, paddingLength + 
1, false);
-        }
+        // +1 is for the payload byte used to define the padding length
+        writeWindowUpdate(abstractNonZeroStream, paddingLength + 1, false);
     }
 
 
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 043506d..ec41058 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -56,6 +56,15 @@
       </fix>
     </changelog>
   </subsection>
+  <subseciton name="Coyote">
+    <changelog>
+      <fix>
+        Refactor the HTTP/2 window update handling for padding in data frames 
to
+        ensure that the connection window is correctly updated after a data
+        frame with zero lngth padding is received. (markt)
+      </fix>
+    </changelog>
+  </subseciton>
   <subsection name="Jasper">
     <changelog>
       <fix>


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to