Accept over 2^31-1 MAX_HEADER_LIST_SIZE

Motivation:

The MAX_HEADER_LIST_SIZE of SETTINGS is represented by
unsigned 32-bit value and this value isn't limited in RFC7540.
But in current implementation, its stored to int variable so
over 2^31-1 value is recognized as minus and handled as
PROTOCOL_ERROR.

Modifications:

If a value of MAX_HEADER_LIST_SIZE is larger than 2^31-1, its
handled as 2^31-1

Result:

Over 2^31-1 MAX_HEADER_LIST_SIZE is became acceptable
This commit is contained in:
Ryo Okubo 2015-07-09 23:39:42 +09:00 committed by nmittler
parent 60c59f39af
commit aaba1b9ed5
4 changed files with 84 additions and 3 deletions

View File

@ -25,10 +25,12 @@ class DefaultHttp2HeaderTableListSize {
public void maxHeaderListSize(int max) throws Http2Exception {
if (max < 0) {
throw connectionError(PROTOCOL_ERROR, "Header List Size must be non-negative but was %d", max);
}
// Over 2^31 - 1 (minus in integer) size is set to the maximun value
maxHeaderListSize = Integer.MAX_VALUE;
} else {
maxHeaderListSize = max;
}
}
public int maxHeaderListSize() {
return maxHeaderListSize;

View File

@ -162,7 +162,14 @@ public final class Http2Settings extends CharObjectHashMap<Long> {
* Gets the {@code SETTINGS_MAX_HEADER_LIST_SIZE} value. If unavailable, returns {@code null}.
*/
public Integer maxHeaderListSize() {
return getIntValue(SETTINGS_MAX_HEADER_LIST_SIZE);
Integer value = getIntValue(SETTINGS_MAX_HEADER_LIST_SIZE);
// Over 2^31 - 1 (minus in integer) size is set to the maximun value
if (value != null && value < 0) {
value = Integer.MAX_VALUE;
}
return value;
}
/**
@ -171,6 +178,11 @@ public final class Http2Settings extends CharObjectHashMap<Long> {
* @throws IllegalArgumentException if verification of the setting fails.
*/
public Http2Settings maxHeaderListSize(int value) {
// Over 2^31 - 1 (minus in integer) size is set to the maximun value
if (value < 0) {
value = Integer.MAX_VALUE;
}
put(SETTINGS_MAX_HEADER_LIST_SIZE, (long) value);
return this;
}

View File

@ -0,0 +1,56 @@
/*
* Copyright 2015 The Netty Project
*
* The Netty Project 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 io.netty.handler.codec.http2;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.Test;
/**
* Tests for {@link DefaultHttp2HeaderTableListSize}.
*/
public class DefaultHttp2HeaderTableListSizeTest {
private DefaultHttp2HeaderTableListSize headerTable;
@Before
public void setup() {
headerTable = new DefaultHttp2HeaderTableListSize();
}
@Test
public void defaultMaxHeaderListSizeShouldSucceed() {
assertEquals(Integer.MAX_VALUE, (long) headerTable.maxHeaderListSize());
}
@Test
public void standardMaxHeaderListSizeShouldSucceed() throws Http2Exception {
headerTable.maxHeaderListSize(123);
assertEquals(123L, (long) headerTable.maxHeaderListSize());
}
@Test
public void boundaryMaxHeaderListSizeShouldSucceed() throws Http2Exception {
headerTable.maxHeaderListSize(Integer.MAX_VALUE);
assertEquals(Integer.MAX_VALUE, (long) headerTable.maxHeaderListSize());
final long settingsValueUpperBound = (1L << 32) - 1L;
headerTable.maxHeaderListSize((int) settingsValueUpperBound);
assertEquals(Integer.MAX_VALUE, (long) headerTable.maxHeaderListSize());
}
}

View File

@ -75,4 +75,15 @@ public class Http2SettingsTest {
settings.put(key, 123L);
assertEquals(123L, (long) settings.get(key));
}
@Test
public void boundarySettingsShouldBeSet() {
final long overIntegerMaxValue = 1L << 31;
settings.maxHeaderListSize((int) overIntegerMaxValue);
assertEquals(Integer.MAX_VALUE, (long) settings.maxHeaderListSize());
final long settingsValueUpperBound = (1L << 32) - 1L;
settings.maxHeaderListSize((int) settingsValueUpperBound);
assertEquals(Integer.MAX_VALUE, (long) settings.maxHeaderListSize());
}
}