Fixed issue: NETTY-226 IndexOutOfBoundsException on empty HTTP header value.

* Skipped substring operation for an HTTP header value if there's nothing after a colon (:).
This commit is contained in:
Trustin Lee 2009-09-10 10:34:49 +00:00
parent 794f805a30
commit 3179d8094e

View File

@ -566,6 +566,7 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
} }
private String[] splitHeader(String sb) { private String[] splitHeader(String sb) {
final int length = sb.length();
int nameStart; int nameStart;
int nameEnd; int nameEnd;
int colonEnd; int colonEnd;
@ -573,14 +574,14 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
int valueEnd; int valueEnd;
nameStart = findNonWhitespace(sb, 0); nameStart = findNonWhitespace(sb, 0);
for (nameEnd = nameStart; nameEnd < sb.length(); nameEnd ++) { for (nameEnd = nameStart; nameEnd < length; nameEnd ++) {
char ch = sb.charAt(nameEnd); char ch = sb.charAt(nameEnd);
if (ch == ':' || Character.isWhitespace(ch)) { if (ch == ':' || Character.isWhitespace(ch)) {
break; break;
} }
} }
for (colonEnd = nameEnd; colonEnd < sb.length(); colonEnd ++) { for (colonEnd = nameEnd; colonEnd < length; colonEnd ++) {
if (sb.charAt(colonEnd) == ':') { if (sb.charAt(colonEnd) == ':') {
colonEnd ++; colonEnd ++;
break; break;
@ -588,11 +589,18 @@ public abstract class HttpMessageDecoder extends ReplayingDecoder<HttpMessageDec
} }
valueStart = findNonWhitespace(sb, colonEnd); valueStart = findNonWhitespace(sb, colonEnd);
valueEnd = findEndOfString(sb); if (valueStart == length) {
return new String[] {
sb.substring(nameStart, nameEnd),
""
};
}
valueEnd = findEndOfString(sb);
return new String[] { return new String[] {
sb.substring(nameStart, nameEnd), sb.substring(nameStart, nameEnd),
sb.substring(valueStart, valueEnd) }; sb.substring(valueStart, valueEnd)
};
} }
private int findNonWhitespace(String sb, int offset) { private int findNonWhitespace(String sb, int offset) {