Bug 59564

Summary: HttpServletRequest.getPart() always returns null with HTTP/2
Product: Tomcat 8 Reporter: Thad Humphries <thad.humphries>
Component: ConnectorsAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: major    
Priority: P2    
Version: 8.5.x-trunk   
Target Milestone: ----   
Hardware: Macintosh   
OS: All   

Description Thad Humphries 2016-05-17 17:11:10 UTC
If I enable HTTP/2 via UpgradeProtocol, HttpServletRequest.getPart() always returns null. This occurs in my own code as well as in org.apache.catalina.manager.HTMLManagerServlet (so, a *.WAR cannot be deployed if HTTP/2 is enabled). When <UpgradeProtocol...> is commented out, upload works.

My connector is

<!-- NIO connector with OpenSSL -->
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
           maxThreads="200" SSLEnabled="true" compression="on"
           scheme="https" secure="true">
  <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
  <SSLHostConfig honorCipherOrder="false">
    <Certificate certificateKeyFile="conf/foo-nopp.pem"
                 certificateFile="conf/foo.pem"
                 type="RSA" />
  </SSLHostConfig>
</Connector>

The failure occurs with either Http11NioProtocol or Http11Nio2Protocol.

I'm am running Tomcat 8.5, Java 1.8.0_91, MacOS 10.10.5, and both Chrome 50 and Firefox 46.
Comment 1 Remy Maucherat 2016-05-20 13:27:04 UTC
This works for me (can't sat anything else really).
Comment 2 Thad Humphries 2016-05-21 02:28:48 UTC
Rats. I was afraid that's what I'd be told. Is something wrong with my connector? The cert is self-signed. Does that matter?
Comment 3 Remy Maucherat 2016-05-23 14:24:06 UTC
No idea at this point. I guess it will be explained eventually.
Comment 4 Violeta Georgieva 2016-05-25 21:54:45 UTC
Hi,

I was able to reproduce this issue.

I think that we should invoke 'data.arrayOffset() + data.position()' when we fill the data:


Index: Http2Parser.java
===================================================================
--- Http2Parser.java	(revision 1745545)
+++ Http2Parser.java	(working copy)
@@ -561,7 +561,7 @@
         }
 
         default boolean fill(boolean block, ByteBuffer data, int len) throws IOException {
-            boolean result = fill(block, data.array(), data.arrayOffset(), len);
+            boolean result = fill(block, data.array(), data.arrayOffset() + data.position(), len);
             if (result) {
                 data.position(data.position() + len);
             }

What do you think?

Regards,
Violeta
Comment 5 Mark Thomas 2016-05-26 08:46:36 UTC
Reproducible with:
- Clean 9.0.x build
- NIO + OpenSSL + HTTP/2
- ~40MB WAR (Spring Pet Clinic)

Violeta's patch fixes this so I have applied it to 9.0.x for 9.0.0.M7 onwards and 8.5.x for 8.5.3 onwards.