You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2026/10/13 18:40:56 UTC
(tomcat) 01/09: Validate the initial flow control window size provided by the administrator
This is an automated email from the ASF dual-hosted git repository.
rmaucher pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 68184082116d209ce1ab22abb31b394975999ed5
Author: opencode <re...@apache.org>
AuthorDate: Tue Oct 13 14:40:53 2026 +0200
Validate the initial flow control window size provided by the administrator
validateInitialWindowSize() only rejected values above the
specification maximum (2^31-1). Negative values, which can only come
from the (trusted) initialWindowSize connector attribute, passed
validation and were silently truncated to 32 bits when serialized in
the SETTINGS frame (e.g. -1 was advertised as 4294967295, which a
conformant client must treat as a connection error of type
FLOW_CONTROL_ERROR). They also caused an IllegalArgumentException from
ByteBuffer.allocate()/new byte[] when the stream input buffers were
first created.
Reject negative values in validateInitialWindowSize() so the invalid
configuration is reported when the HTTP/2 connection is opened,
document the permitted range (0 to 2^31-1) on the Http2Protocol setter
and in the HTTP/2 connector documentation, and add unit tests for the
local settings validation paths. The remote path is unaffected:
settings values read from the wire via ByteUtil.getFourBytes() are
always in the unsigned 32-bit range 0 to 2^32-1.
---
.../coyote/http2/ConnectionSettingsBase.java | 5 +++
java/org/apache/coyote/http2/Http2Protocol.java | 4 +-
.../apache/coyote/http2/LocalStrings.properties | 1 +
.../coyote/http2/TestConnectionSettingsLocal.java | 45 ++++++++++++++++++++++
webapps/docs/config/http2.xml | 5 ++-
5 files changed, 58 insertions(+), 2 deletions(-)
diff --git a/java/org/apache/coyote/http2/ConnectionSettingsBase.java b/java/org/apache/coyote/http2/ConnectionSettingsBase.java
index 1d5fd9c687..38fd20648c 100644
--- a/java/org/apache/coyote/http2/ConnectionSettingsBase.java
+++ b/java/org/apache/coyote/http2/ConnectionSettingsBase.java
@@ -210,6 +210,11 @@ abstract class ConnectionSettingsBase<T extends Throwable> {
private void validateInitialWindowSize(long initialWindowSize) throws T {
+ if (initialWindowSize < 0) {
+ String msg = sm.getString("connectionSettings.windowSizeTooSmall", connectionId,
+ Long.toString(initialWindowSize));
+ throwException(msg, Http2Error.FLOW_CONTROL_ERROR);
+ }
if (initialWindowSize > MAX_WINDOW_SIZE) {
String msg = sm.getString("connectionSettings.windowSizeTooBig", connectionId,
Long.toString(initialWindowSize), Long.toString(MAX_WINDOW_SIZE));
diff --git a/java/org/apache/coyote/http2/Http2Protocol.java b/java/org/apache/coyote/http2/Http2Protocol.java
index b384e69dd6..e146aa7ebe 100644
--- a/java/org/apache/coyote/http2/Http2Protocol.java
+++ b/java/org/apache/coyote/http2/Http2Protocol.java
@@ -367,7 +367,9 @@ public class Http2Protocol implements UpgradeProtocol {
/**
- * Sets the initial window size advertised to the client.
+ * Sets the initial window size advertised to the client. The value must be in the range {@code 0} to
+ * {@code 2^31-1} (both inclusive) as defined by the HTTP/2 specification. Values outside of this range will cause
+ * HTTP/2 connections to be rejected.
*
* @param initialWindowSize the initial window size
*/
diff --git a/java/org/apache/coyote/http2/LocalStrings.properties b/java/org/apache/coyote/http2/LocalStrings.properties
index f2fbd522b8..f9b902592b 100644
--- a/java/org/apache/coyote/http2/LocalStrings.properties
+++ b/java/org/apache/coyote/http2/LocalStrings.properties
@@ -29,6 +29,7 @@ connectionSettings.maxFrameSizeInvalid=Connection [{0}], The requested maximum f
connectionSettings.noRfc7540PrioritiesInvalid=Connection [{0}], The requested no RFC 7540 priorities setting [{1}] was not zero or one
connectionSettings.unknown=Connection [{0}], An unknown setting with identifier [{1}] and value [{2}] was ignored
connectionSettings.windowSizeTooBig=Connection [{0}], The requested window size of [{1}] is bigger than the maximum permitted value of [{2}]
+connectionSettings.windowSizeTooSmall=Connection [{0}], The requested window size of [{1}] is smaller than the minimum permitted value of [0]
frameType.checkPayloadSize=Payload size of [{0}] is not valid for frame type [{1}]
frameType.checkStream=Invalid frame type [{0}]
diff --git a/test/org/apache/coyote/http2/TestConnectionSettingsLocal.java b/test/org/apache/coyote/http2/TestConnectionSettingsLocal.java
new file mode 100644
index 0000000000..dc48a5ee48
--- /dev/null
+++ b/test/org/apache/coyote/http2/TestConnectionSettingsLocal.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.coyote.http2;
+
+import org.junit.Test;
+
+public class TestConnectionSettingsLocal {
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInitialWindowSizeNegative() {
+ // Use of a negative value is not permitted by the specification and
+ // can not be represented in a SETTINGS frame
+ ConnectionSettingsLocal settings = new ConnectionSettingsLocal("0");
+ settings.set(Setting.INITIAL_WINDOW_SIZE, -1);
+ }
+
+
+ @Test
+ public void testInitialWindowSizeZero() {
+ // A value of zero is permitted by the specification
+ ConnectionSettingsLocal settings = new ConnectionSettingsLocal("0");
+ settings.set(Setting.INITIAL_WINDOW_SIZE, 0);
+ }
+
+
+ @Test(expected = IllegalArgumentException.class)
+ public void testInitialWindowSizeTooBig() {
+ ConnectionSettingsLocal settings = new ConnectionSettingsLocal("0");
+ settings.set(Setting.INITIAL_WINDOW_SIZE, ConnectionSettingsBase.MAX_WINDOW_SIZE + 1L);
+ }
+}
diff --git a/webapps/docs/config/http2.xml b/webapps/docs/config/http2.xml
index e152b71902..940a01f53d 100644
--- a/webapps/docs/config/http2.xml
+++ b/webapps/docs/config/http2.xml
@@ -101,7 +101,10 @@
<attribute name="initialWindowSize" required="false">
<p>Controls the initial size of the flow control window for streams that
- Tomcat advertises to clients. If not specified, the default value of
+ Tomcat advertises to clients. The value must be in the range <code>0</code>
+ to <code>2^31-1</code> (both inclusive) as defined by the HTTP/2
+ specification. Values outside of this range will cause HTTP/2 connections
+ to be rejected. If not specified, the default value of
<code>65535</code> is used.</p>
</attribute>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org