Fix possible NPEs and IndexOutOfBoundsExceptions in HTTP/2 Codec (#10640)

Motivation:

There are possible NPEs and IndexOutOfBoundsExceptions in HTTP/2 code. 

Modification:
Fixed possible NPEs and IOOBEs

Result:
Better code
This commit is contained in:
Aayush Atharva 2020-10-26 19:11:49 +05:30 committed by GitHub
parent 065c39611e
commit ee3b9a5f7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 17 deletions

View File

@ -147,8 +147,8 @@ abstract class AbstractHttp2StreamChannel extends DefaultAttributeMap implements
REQUESTED
}
private final AbstractHttp2StreamChannel.Http2StreamChannelConfig config = new Http2StreamChannelConfig(this);
private final AbstractHttp2StreamChannel.Http2ChannelUnsafe unsafe = new Http2ChannelUnsafe();
private final Http2StreamChannelConfig config = new Http2StreamChannelConfig(this);
private final Http2ChannelUnsafe unsafe = new Http2ChannelUnsafe();
private final ChannelId channelId;
private final ChannelPipeline pipeline;
private final DefaultHttp2FrameStream stream;
@ -258,7 +258,7 @@ abstract class AbstractHttp2StreamChannel extends DefaultAttributeMap implements
final int oldValue = unwritable;
final int newValue = oldValue | 1;
if (UNWRITABLE_UPDATER.compareAndSet(this, oldValue, newValue)) {
if (oldValue == 0 && newValue != 0) {
if (oldValue == 0) {
fireChannelWritabilityChanged(invokeLater);
}
break;

View File

@ -507,10 +507,6 @@ public class DefaultHttp2ConnectionDecoder implements Http2ConnectionDecoder {
return;
}
if (parentStream == null) {
throw connectionError(PROTOCOL_ERROR, "Stream %d does not exist", streamId);
}
switch (parentStream.state()) {
case OPEN:
case HALF_CLOSED_LOCAL:

View File

@ -219,7 +219,7 @@ public class DefaultHttp2FrameWriter implements Http2FrameWriter, Http2FrameSize
ctx.write(frameHeader2, promiseAggregator.newPromise());
// Write the payload.
if (frameDataBytes != 0) {
if (frameDataBytes != 0 && data != null) { // Make sure Data is not null
if (remainingData == 0) {
ByteBuf lastFrame = data.readSlice(frameDataBytes);
data = null;

View File

@ -183,12 +183,14 @@ final class HpackDynamicTable {
// initially length will be 0 so there will be no copy
int len = length();
int cursor = tail;
for (int i = 0; i < len; i++) {
HpackHeaderField entry = hpackHeaderFields[cursor++];
tmp[i] = entry;
if (cursor == hpackHeaderFields.length) {
cursor = 0;
if (hpackHeaderFields != null) {
int cursor = tail;
for (int i = 0; i < len; i++) {
HpackHeaderField entry = hpackHeaderFields[cursor++];
tmp[i] = entry;
if (cursor == hpackHeaderFields.length) {
cursor = 0;
}
}
}

View File

@ -823,12 +823,14 @@ public final class ReadOnlyHttp2Headers implements Http2Headers {
for (; i < current.length; i += 2) {
AsciiString roName = current[i];
if (roName.hashCode() == nameHash && roName.contentEqualsIgnoreCase(name)) {
next = current[i + 1];
i += 2;
if (i + 1 < current.length) {
next = current[i + 1];
i += 2;
}
return;
}
}
if (i >= current.length && current == pseudoHeaders) {
if (current == pseudoHeaders) {
i = 0;
current = otherHeaders;
calculateNext();