Skip to content

Commit fd2d1cb

Browse files
committed
Accept SETTINGS_HEADER_TABLE_SIZE values above the implementation limit
RFC 7540, section 6.5.2 defines no upper bound for SETTINGS_HEADER_TABLE_SIZE. The encoder is free to select any table size equal to or less than the advertised value. Tomcat was treating a value above its internal cap of 16k as a connection error (PROTOCOL_ERROR), which incorrectly terminated valid connections. The fix caps the stored value at the implementation limit rather than rejecting the setting. The HPACK encoder receives at most MAX_HEADER_TABLE_SIZE, which is always within the bound advertised by the client.
1 parent 17aa176 commit fd2d1cb

10 files changed

Lines changed: 21 additions & 18 deletions

‎java/org/apache/coyote/http2/ConnectionSettingsBase.java‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ final void set(Setting setting, long value, boolean force) throws T {
7777
}
7878

7979
switch (setting) {
80-
case HEADER_TABLE_SIZE -> validateHeaderTableSize(value);
80+
case HEADER_TABLE_SIZE -> {
81+
// RFC 7540, section 6.5.2: no upper bound is defined for SETTINGS_HEADER_TABLE_SIZE.
82+
// Cap the value at the implementation limit rather than treating it as a protocol error.
83+
set(setting, Long.valueOf(Math.min(value, MAX_HEADER_TABLE_SIZE)), force);
84+
return;
85+
}
8186
case ENABLE_PUSH -> validateEnablePush(value);
8287
case MAX_CONCURRENT_STREAMS, MAX_HEADER_LIST_SIZE -> validateUnsigned32BitSetting(setting, value);
8388
case INITIAL_WINDOW_SIZE -> validateInitialWindowSize(value);
@@ -189,15 +194,6 @@ private synchronized int getMaxInt(Setting setting) {
189194
}
190195

191196

192-
private void validateHeaderTableSize(long headerTableSize) throws T {
193-
if (headerTableSize > MAX_HEADER_TABLE_SIZE) {
194-
String msg = sm.getString("connectionSettings.headerTableSizeLimit", connectionId,
195-
Long.toString(headerTableSize));
196-
throwException(msg, Http2Error.PROTOCOL_ERROR);
197-
}
198-
}
199-
200-
201197
private void validateEnablePush(long enablePush) throws T {
202198
// Can't be less than zero since the result of the byte->long conversion
203199
// will never be negative

‎java/org/apache/coyote/http2/LocalStrings.properties‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ connectionPrefaceParser.mismatch=An unexpected byte sequence was received at the
2424

2525
connectionSettings.debug=Connection [{0}], Endpoint [{1}], Parameter type [{2}] set to [{3}]
2626
connectionSettings.enablePushInvalid=Connection [{0}], The requested value for enable push [{1}] is not one of the permitted values (zero or one)
27-
connectionSettings.headerTableSizeLimit=Connection [{0}], Attempted to set a header table size of [{1}] but the limit is 16k
2827
connectionSettings.maxFrameSizeInvalid=Connection [{0}], The requested maximum frame size of [{1}] is outside the permitted range of [{2}] to [{3}]
2928
connectionSettings.noRfc7540PrioritiesInvalid=Connection [{0}], The requested no RFC 7540 priorities setting [{1}] was not zero or one
3029
connectionSettings.settingValueInvalid=Connection [{0}], The requested value [{2}] for the setting [{1}] is outside the permitted range of [{3}] to [{4}]

‎java/org/apache/coyote/http2/LocalStrings_cs.properties‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ abstractStream.windowSizeInc=Spojení [{0}], Stream [{1}], zvyšte tok kontroln
2121
connectionPrefaceParser.mismatch=Neočekávaná sekvence bytů byla přijata při zahájení klientem [{0}]
2222

2323
connectionSettings.debug=Spojení [{0}], typ parametru [{1}] nastaven na [{2}]
24-
connectionSettings.headerTableSizeLimit=Spojení [{0}], Pokus o nastavení velikosti hlavičky tabulky na [{1}], limit je však 16k
2524
connectionSettings.maxFrameSizeInvalid=Spojení [{0}], požadovaná maximnální velikost rámce [{1}] je mimo povolený rozsah od [{2}] do [{3}]
2625

2726
hpack.invalidCharacter=Unicode znak [{0}] na kódové značce [{1}] nemůže být zakódován, protože je mimo povolený rozsah 0 až 255.

‎java/org/apache/coyote/http2/LocalStrings_de.properties‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ abstractStream.windowSizeInc=Verbindung [{0}], Stream [{1}], erhöhe Flow Contrr
2121
connectionPrefaceParser.mismatch=Es wurde eine unerwartete Byte Sequenz beim Start der Client Preface Phase [{0}] empfangen
2222

2323
connectionSettings.debug=Verbindung [{0}], Parameter typ [{1}] gesetzt auf [{2}]
24-
connectionSettings.headerTableSizeLimit=Verbindung [{0}], versuchte die Kopfzeilentabellengröße auf [{1}] zu setzen aber die Grenze liegt bei 16k
2524
connectionSettings.maxFrameSizeInvalid=Verbindung [{0}], die angeforderte maximale Framegröße von [{1}] ist außerhalb des erlaubten Bereichs von [{2}] bis [{3}]
2625

2726
hpack.invalidCharacter=Das Unicode Zeichen [{0}] an Code Punkt [{1}] kann nicht kodiert werden, da es außerhalb des erlaubten Bereiches von 0 bis 255 ist.

‎java/org/apache/coyote/http2/LocalStrings_es.properties‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ abstractStream.windowSizeInc=Conexión [{0}], Flujo [{1}], aumente el control de
2121
connectionPrefaceParser.mismatch=Una sequencia de byte no esperada fue recibida al inicio del prefacio de cliente [{0}]
2222

2323
connectionSettings.debug=Conexión [{0}], Parámetro tipo [{1}] fijado a [{2}]
24-
connectionSettings.headerTableSizeLimit=La conexión [{0}], intentó fijar un tamaño de cabecera de [{1}] pero el límite es 16k\n
2524
connectionSettings.maxFrameSizeInvalid=Conexión [{0}], El tamaño de cuadro máximo solicitado de [{1}] esta fuera del rango permitido de [{2}] hasta [{3}]\n
2625
connectionSettings.unknown=Conexión [{0}], Un parámetro desconocido con identificador [{1}] y valor [{2}] fue ignorado\n
2726

‎java/org/apache/coyote/http2/LocalStrings_fr.properties‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ connectionPrefaceParser.mismatch=Une séquence inattendue d''octets a été recu
2727

2828
connectionSettings.debug=Connection [{0}], Paramètre type [{1}] mis à [{2}]
2929
connectionSettings.enablePushInvalid=Connection [{0}], La valeur demandée pour activer le push [{1}] n''est pas une de celles permises (zéro ou un)
30-
connectionSettings.headerTableSizeLimit=La Connection [{0}] a essayé de configurer une taille de [{1}] pour la table des en-têtes (headers), mais la limite est 16k
3130
connectionSettings.maxFrameSizeInvalid=Connection [{0}], la taille maximum de trame demandée [{1}] est en-dehors des limites permises [{2}] - [{3}]
3231
connectionSettings.noRfc7540PrioritiesInvalid=Connection [{0}], Le paramètre "no RFC 7540 priorities" [{1}] n''était pas zéro ou un
3332
connectionSettings.unknown=Connection [{0}], Un paramètre inconnu avec l''identifiant [{1}] et la valeur [{2}] a été ignoré

‎java/org/apache/coyote/http2/LocalStrings_ja.properties‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ connectionPrefaceParser.mismatch=クライアントプリフェイス [{0}] の
2727

2828
connectionSettings.debug=コネクション [{0}]、エンドポイント [{1}]、パラメータ型 [{2}] に [{3}] を設定しました
2929
connectionSettings.enablePushInvalid=コネクション[{0}]、有効プッシュ[{1}]にリクエストされた値が許容値(0または1)のいずれでもありません。
30-
connectionSettings.headerTableSizeLimit=コネクション [{0}]、ヘッダーテーブルサイズに [{1}] を指定されましたが上限は 16k です。
3130
connectionSettings.maxFrameSizeInvalid=コネクション [{0}]、要求された最大フレームサイズ [{1}] は可能な範囲の [{2}] から [{3}] を超えています。
3231
connectionSettings.noRfc7540PrioritiesInvalid=コネクション [{0}]、要求された RFC 7540 優先度設定 [{1}] が 0 でも 1 でもありませんでした
3332
connectionSettings.unknown=コネクション [{0}]、未知の設定名 [{1}] の値 [{2}] を無視しました。

‎java/org/apache/coyote/http2/LocalStrings_ko.properties‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ connectionPrefaceParser.mismatch=해당 client preface [{0}]의 시작 부분에
2727

2828
connectionSettings.debug=연결 [{0}]: 파라미터 타입 [{1}]을(를) [{2}](으)로 설정함.
2929
connectionSettings.enablePushInvalid=연결 [{0}], enablePush를 위해 요청된 값 [{1}]은(는), 허용된 값들(0 또는 1) 중의 하나가 아닙니다.
30-
connectionSettings.headerTableSizeLimit=연결 [{0}]: 헤더 테이블 크기로 [{1}]을(를) 설정하려 시도했으나, 한계값은 16k입니다.
3130
connectionSettings.maxFrameSizeInvalid=연결 [{0}]: [{1}]의 요청된 최대 프레임 크기가 허용된 범위([{2}] - [{3}])의 바깥에 존재합니다.
3231
connectionSettings.unknown=연결 [{0}]: 식별자가 [{1}](이)고 값이 [{2}]인 알 수 없는 설정이 무시되었습니다.
3332
connectionSettings.windowSizeTooBig=연결 [{0}]: 요청된 윈도우 크기 [{1}]이(가) 최대 허용치 [{2}] 보다 큽니다.

‎java/org/apache/coyote/http2/LocalStrings_zh_CN.properties‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ connectionPrefaceParser.mismatch=请求了新的远程流ID[{0}],但所有远
2727

2828
connectionSettings.debug=连接[{0}],参数类型[{1}]设置为[{2}]
2929
connectionSettings.enablePushInvalid=连接[{0}],请求的enable push[{1}]值不是允许的值之一(零或一)
30-
connectionSettings.headerTableSizeLimit=连接 [{0}],尝试将 header 表大小设置为 [{1}],但限制为 16k
3130
connectionSettings.maxFrameSizeInvalid=连接[{0}],请求的最大帧大小[{1}]在[{2}]到[{3}]的允许范围之外
3231
connectionSettings.unknown=连接[{0}],标识为[{1}]和值为[{2}]的未知设置被忽略
3332
connectionSettings.windowSizeTooBig=连接[{0}],请求窗口大小[{0}],大于最大允许的值[{1}]

‎test/org/apache/coyote/http2/TestHttp2Section_6_5.java‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,19 @@ public void testSettingsUnknownSetting() throws Exception {
118118
}
119119

120120
// delayed ACKs. Requires an API (TBD) for applications to send settings.
121+
122+
123+
@Test
124+
public void testSettingsLargeHeaderTableSize() throws Exception {
125+
// RFC 7540, section 6.5.2: SETTINGS_HEADER_TABLE_SIZE has no defined upper bound.
126+
// The encoder selects any size equal to or less than the advertised value (section 6.5.2).
127+
// A large value is valid; rejecting it with a connection error violates the RFC.
128+
http2Connect();
129+
130+
sendSettings(0, false, new SettingValue(0x1, 65537));
131+
132+
parser.readFrame();
133+
134+
Assert.assertTrue(output.getTrace(), output.getTrace().startsWith("0-Settings-Ack"));
135+
}
121136
}

0 commit comments

Comments
 (0)