Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid index out of bounds with Http/2 settings id in the experimental range #3377

Merged
merged 1 commit into from
Jun 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions okhttp-tests/src/test/java/okhttp3/internal/http2/Http2Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,21 @@ public void pushPromise(int streamId, int promisedStreamId, List<Header> headerB
assertEquals(settingValue.intValue(), 1);
}

@Test public void readSettingsFrameExperimentalId() throws IOException {
writeMedium(frame, 6); // 2 for the code and 4 for the value
frame.writeByte(Http2.TYPE_SETTINGS);
frame.writeByte(Http2.FLAG_NONE);
frame.writeInt(0); // Settings are always on the connection stream 0.
frame.write(ByteString.decodeHex("f000")); // Id reserved for experimental use.
frame.writeInt(1);

reader.nextFrame(false, new BaseTestHandler() {
@Override public void settings(boolean clearPrevious, Settings settings) {
// no-op
}
});
}

@Test public void readSettingsFrameNegativeWindowSize() throws IOException {
writeMedium(frame, 6); // 2 for the code and 4 for the value
frame.writeByte(Http2.TYPE_SETTINGS);
Expand Down
2 changes: 1 addition & 1 deletion okhttp/src/main/java/okhttp3/internal/http2/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void clear() {
}

Settings set(int id, int value) {
if (id >= values.length) {
if (id < 0 || id >= values.length) {
return this; // Discard unknown settings.
}

Expand Down