Skip to content

Commit da2ff54

Browse files
arturobernalgmarkt-asf
authored andcommitted
Accept SETTINGS_HEADER_TABLE_SIZE values above the implementation limit
(#1123) RFC 9113, 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 64 KiB 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 613e1e2 commit da2ff54

10 files changed

Lines changed: 35 additions & 19 deletions

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,12 @@ final void set(Setting setting, long value, boolean force) throws T {
7979

8080
switch (setting) {
8181
case HEADER_TABLE_SIZE:
82-
validateHeaderTableSize(value);
83-
break;
82+
// RFC 9113, section 6.5.2: no protocol-defined upper bound exists for
83+
// SETTINGS_HEADER_TABLE_SIZE; any value up to 2^32-1 is valid. Cap the
84+
// stored value at the implementation limit rather than treating a large
85+
// value as a protocol error.
86+
set(setting, Long.valueOf(Math.min(value, MAX_HEADER_TABLE_SIZE)), force);
87+
return;
8488
case ENABLE_PUSH:
8589
validateEnablePush(value);
8690
break;
@@ -203,15 +207,6 @@ private synchronized int getMaxInt(Setting setting) {
203207
}
204208

205209

206-
private void validateHeaderTableSize(long headerTableSize) throws T {
207-
if (headerTableSize > MAX_HEADER_TABLE_SIZE) {
208-
String msg = sm.getString("connectionSettings.headerTableSizeLimit", connectionId,
209-
Long.toString(headerTableSize));
210-
throwException(msg, Http2Error.PROTOCOL_ERROR);
211-
}
212-
}
213-
214-
215210
private void validateEnablePush(long enablePush) throws T {
216211
// Can't be less than zero since the result of the byte->long conversion
217212
// 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
@@ -27,7 +27,6 @@ connectionPrefaceParser.mismatch=An unexpected byte sequence was received at the
2727

2828
connectionSettings.debug=Connection [{0}], Endpoint [{1}], Parameter type [{2}] set to [{3}]
2929
connectionSettings.enablePushInvalid=Connection [{0}], The requested value for enable push [{1}] is not one of the permitted values (zero or one)
30-
connectionSettings.headerTableSizeLimit=Connection [{0}], Attempted to set a header table size of [{1}] but the limit is 16k
3130
connectionSettings.maxFrameSizeInvalid=Connection [{0}], The requested maximum frame size of [{1}] is outside the permitted range of [{2}] to [{3}]
3231
connectionSettings.noRfc7540PrioritiesInvalid=Connection [{0}], The requested no RFC 7540 priorities setting [{1}] was not zero or one
3332
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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,4 +158,33 @@ public void testSettingsUnknownSetting() throws Exception {
158158
}
159159

160160
// delayed ACKs. Requires an API (TBD) for applications to send settings.
161+
162+
163+
@Test
164+
public void testSettingsLargeHeaderTableSize() throws Exception {
165+
// RFC 9113, section 6.5.2: SETTINGS_HEADER_TABLE_SIZE has no protocol-defined upper
166+
// bound. The encoder selects any size equal to or less than the advertised value.
167+
// A value above the implementation limit must be accepted, not rejected.
168+
http2Connect();
169+
170+
sendSettings(0, false, new SettingValue(0x1, 65537));
171+
172+
parser.readFrame();
173+
174+
Assert.assertTrue(output.getTrace(), output.getTrace().startsWith("0-Settings-Ack"));
175+
}
176+
177+
178+
@Test
179+
public void testSettingsMaxUnsignedHeaderTableSize() throws Exception {
180+
// RFC 9113, section 6.5.2: any value up to 2^32-1 is valid for
181+
// SETTINGS_HEADER_TABLE_SIZE. The maximum unsigned 32-bit value must be accepted.
182+
http2Connect();
183+
184+
sendSettings(0, false, new SettingValue(0x1, 0xFFFFFFFFL));
185+
186+
parser.readFrame();
187+
188+
Assert.assertTrue(output.getTrace(), output.getTrace().startsWith("0-Settings-Ack"));
189+
}
161190
}

0 commit comments

Comments
 (0)