This is an automated email from the ASF dual-hosted git repository.
rmaucher pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/10.1.x by this push:
new 30da9c3b1d Avoid exceptions on invalid content-length
30da9c3b1d is described below
commit 30da9c3b1d162e4452ad737e6d504b7c1a5b9b81
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 e7cee14070..028f26fb25 100644
--- a/java/org/apache/coyote/http2/LocalStrings.properties
+++ b/java/org/apache/coyote/http2/LocalStrings.properties
@@ -101,6 +101,7 @@ stream.clientResetRequest=Client reset the stream before
the request was fully r
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 bad1e40817..33b223333d 100644
--- a/java/org/apache/coyote/http2/Stream.java
+++ b/java/org/apache/coyote/http2/Stream.java
@@ -744,7 +744,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(),
@@ -758,16 +758,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 12b74fdb1c..b92f7522d0 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 663b76a6cd..b537198180 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -178,6 +178,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]