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

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

commit d07c82194edb69d99b438828fe2cbfadbb207843
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Jan 25 12:13:55 2024 +0000

    Report HTTP/2 header parsing errors earlier
---
 java/org/apache/coyote/http2/Http2Parser.java | 11 ++++++-----
 webapps/docs/changelog.xml                    |  5 +++++
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/java/org/apache/coyote/http2/Http2Parser.java 
b/java/org/apache/coyote/http2/Http2Parser.java
index 614ebbaaf9..b9f95e3cd7 100644
--- a/java/org/apache/coyote/http2/Http2Parser.java
+++ b/java/org/apache/coyote/http2/Http2Parser.java
@@ -283,6 +283,9 @@ class Http2Parser {
 
         swallowPayload(streamId, FrameType.HEADERS.getId(), padLength, true, 
buffer);
 
+        // Validate the headers so far
+        hpackDecoder.getHeaderEmitter().validateHeaders();
+
         if (Flags.isEndOfHeaders(flags)) {
             onHeadersComplete(streamId);
         } else {
@@ -446,6 +449,9 @@ class Http2Parser {
 
         readHeaderPayload(streamId, payloadSize, buffer);
 
+        // Validate the headers so far
+        hpackDecoder.getHeaderEmitter().validateHeaders();
+
         if (endOfHeaders) {
             headersCurrentStream = -1;
             onHeadersComplete(streamId);
@@ -637,11 +643,6 @@ class Http2Parser {
                     Http2Error.COMPRESSION_ERROR);
         }
 
-        // Delay validation (and triggering any exception) until this point
-        // since all the headers still have to be read if a StreamException is
-        // going to be thrown.
-        hpackDecoder.getHeaderEmitter().validateHeaders();
-
         synchronized (output) {
             output.headersEnd(streamId, headersEndStream);
 
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 10faaf173f..e7840832d4 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -171,6 +171,11 @@
         <code>Content-Type</code> value to improve performance by reducing
         repeated <code>byte[]</code> to <code>String</code> conversions. 
(markt)
       </fix>
+      <fix>
+        Improve error reporting to HTTP/2 clients for header processing errors
+        by reporting problems at the end of the frame where the error was
+        detected rather than at the end of the headers. (markt)
+      </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

Reply via email to