This is an automated email from the ASF dual-hosted git repository.
rmaucher pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new 5f1ed60eb8 Avoid exceptions on invalid content-length
5f1ed60eb8 is described below
commit 5f1ed60eb8e6a9ade0af2e950678c09cf2491571
Author: remm <[email protected]>
AuthorDate: Mon Aug 31 15:25:38 2026 +0200
Avoid exceptions on invalid content-length
---
java/org/apache/coyote/http2/LocalStrings.properties | 1 +
java/org/apache/coyote/http2/Stream.java | 17 +++++++++++++----
.../org/apache/tomcat/util/http/LocalStrings.properties | 1 +
java/org/apache/tomcat/util/http/MimeHeaders.java | 2 +-
webapps/docs/changelog.xml | 4 ++++
5 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/java/org/apache/coyote/http2/LocalStrings.properties
b/java/org/apache/coyote/http2/LocalStrings.properties
index 441e1053a2..e72e067ba1 100644
--- a/java/org/apache/coyote/http2/LocalStrings.properties
+++ b/java/org/apache/coyote/http2/LocalStrings.properties
@@ -100,6 +100,7 @@ pingManager.roundTripTime=Connection [{0}] Round trip time
measured as [{1}]ns
stream.closed=Connection [{0}], Stream [{1}], Unable to write to stream once
it has been closed
stream.header.connection=Connection [{0}], Stream [{1}], HTTP header [{2}] is
not permitted in an HTTP/2 request
stream.header.contentLength=Connection [{0}], Stream [{1}], The content length
header value [{2}] does not agree with the size of the data received [{3}]
+stream.header.contentLength.invalid=Connection [{0}], Stream [{1}], The
content length header was invalid
stream.header.debug=Connection [{0}], Stream [{1}], HTTP header [{2}], Value
[{3}]
stream.header.duplicate=Connection [{0}], Stream [{1}], received multiple
[{2}] headers
stream.header.empty=Connection [{0}], Stream [{1}], Invalid empty header name
diff --git a/java/org/apache/coyote/http2/Stream.java
b/java/org/apache/coyote/http2/Stream.java
index b504a835b7..4314e72432 100644
--- a/java/org/apache/coyote/http2/Stream.java
+++ b/java/org/apache/coyote/http2/Stream.java
@@ -743,7 +743,7 @@ class Stream extends AbstractNonZeroStream implements
HeaderEmitter {
@Override
final void receivedData(int dataLength) throws Http2Exception {
contentLengthReceived += dataLength;
- long contentLengthHeader = coyoteRequest.getContentLengthLong();
+ long contentLengthHeader = getContentLengthLong();
if (contentLengthHeader > -1 && contentLengthReceived >
contentLengthHeader) {
throw new StreamException(
sm.getString("stream.header.contentLength",
getConnectionId(), getIdAsString(),
@@ -757,16 +757,25 @@ class Stream extends AbstractNonZeroStream implements
HeaderEmitter {
if (isContentLengthInconsistent()) {
throw new StreamException(
sm.getString("stream.header.contentLength",
getConnectionId(), getIdAsString(),
-
Long.valueOf(coyoteRequest.getContentLengthLong()),
Long.valueOf(contentLengthReceived)),
+ Long.valueOf(getContentLengthLong()),
Long.valueOf(contentLengthReceived)),
Http2Error.PROTOCOL_ERROR, getIdAsInt());
}
state.receivedEndOfStream();
inputBuffer.notifyEof();
}
+ final long getContentLengthLong() throws Http2Exception {
+ try {
+ return coyoteRequest.getContentLengthLong();
+ } catch (Exception e) {
+ throw new StreamException(
+ sm.getString("stream.header.contentLength.invalid",
getConnectionId(), getIdAsString()),
+ Http2Error.PROTOCOL_ERROR, getIdAsInt(), e);
+ }
+ }
- final boolean isContentLengthInconsistent() {
- long contentLengthHeader = coyoteRequest.getContentLengthLong();
+ final boolean isContentLengthInconsistent() throws Http2Exception {
+ long contentLengthHeader = getContentLengthLong();
return contentLengthHeader > -1 && contentLengthReceived !=
contentLengthHeader;
}
diff --git a/java/org/apache/tomcat/util/http/LocalStrings.properties
b/java/org/apache/tomcat/util/http/LocalStrings.properties
index bb6d3afa6c..e2cc646a0f 100644
--- a/java/org/apache/tomcat/util/http/LocalStrings.properties
+++ b/java/org/apache/tomcat/util/http/LocalStrings.properties
@@ -25,6 +25,7 @@ cookies.maxCountFail=More than the maximum allowed number of
cookies, [{0}], wer
cookiesWithoutEquals.invalid=The value [{0}] is not recognised
+headers.duplicateUniqueHeader=Duplicate unique header [{0}] found
headers.maxCountFail=More than the maximum allowed number of headers, [{0}],
were detected.
parameters.bytes=Start processing with input [{0}]
diff --git a/java/org/apache/tomcat/util/http/MimeHeaders.java
b/java/org/apache/tomcat/util/http/MimeHeaders.java
index 7d8a1ad524..6f8b879ec3 100644
--- a/java/org/apache/tomcat/util/http/MimeHeaders.java
+++ b/java/org/apache/tomcat/util/http/MimeHeaders.java
@@ -393,7 +393,7 @@ public class MimeHeaders {
if (result == null) {
result = headers[i].getValue();
} else {
- throw new IllegalArgumentException();
+ throw new
IllegalArgumentException(sm.getString("headers.duplicateUniqueHeader", name));
}
}
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index ec598af863..d46ec0ee09 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -202,6 +202,10 @@
Fix incorrect initial window size calculation when upgrading to HTTP/2.
(remm)
</fix>
+ <fix>
+ Avoid HTTP/2 exceptions with invalid <code>content-length</code>
+ values. (remm)
+ </fix>
</changelog>
</subsection>
<subsection name="Cluster">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]