提交 bbb2b65e 编写于 作者: W weijun

80594853: Resolve parsing ambiguity

Reviewed-by: mullan, vinnie
上级 09315ed3
...@@ -95,6 +95,9 @@ public final class BerDecoder extends Ber { ...@@ -95,6 +95,9 @@ public final class BerDecoder extends Ber {
for( int i = 0; i < lengthbyte; i++) { for( int i = 0; i < lengthbyte; i++) {
retval = (retval << 8) + (buf[offset++] & 0xff); retval = (retval << 8) + (buf[offset++] & 0xff);
} }
if (retval < 0) {
throw new DecodeException("Invalid length bytes");
}
return retval; return retval;
} else { } else {
return lengthbyte; return lengthbyte;
......
...@@ -156,12 +156,18 @@ class DerIndefLenConverter { ...@@ -156,12 +156,18 @@ class DerIndefLenConverter {
} }
if (isLongForm(lenByte)) { if (isLongForm(lenByte)) {
lenByte &= LEN_MASK; lenByte &= LEN_MASK;
if (lenByte > 4) if (lenByte > 4) {
throw new IOException("Too much data"); throw new IOException("Too much data");
if ((dataSize - dataPos) < (lenByte + 1)) }
if ((dataSize - dataPos) < (lenByte + 1)) {
throw new IOException("Too little data"); throw new IOException("Too little data");
for (int i = 0; i < lenByte; i++) }
for (int i = 0; i < lenByte; i++) {
curLen = (curLen << 8) + (data[dataPos++] & 0xff); curLen = (curLen << 8) + (data[dataPos++] & 0xff);
}
if (curLen < 0) {
throw new IOException("Invalid length bytes");
}
} else { } else {
curLen = (lenByte & LEN_MASK); curLen = (lenByte & LEN_MASK);
} }
...@@ -188,10 +194,15 @@ class DerIndefLenConverter { ...@@ -188,10 +194,15 @@ class DerIndefLenConverter {
} }
if (isLongForm(lenByte)) { if (isLongForm(lenByte)) {
lenByte &= LEN_MASK; lenByte &= LEN_MASK;
for (int i = 0; i < lenByte; i++) for (int i = 0; i < lenByte; i++) {
curLen = (curLen << 8) + (data[dataPos++] & 0xff); curLen = (curLen << 8) + (data[dataPos++] & 0xff);
} else }
if (curLen < 0) {
throw new IOException("Invalid length bytes");
}
} else {
curLen = (lenByte & LEN_MASK); curLen = (lenByte & LEN_MASK);
}
writeLength(curLen); writeLength(curLen);
writeValue(curLen); writeValue(curLen);
} }
......
...@@ -566,6 +566,10 @@ public class DerInputStream { ...@@ -566,6 +566,10 @@ public class DerInputStream {
value <<= 8; value <<= 8;
value += 0x0ff & in.read(); value += 0x0ff & in.read();
} }
if (value < 0) {
throw new IOException("DerInputStream.getLength(): "
+ "Invalid length bytes");
}
} }
return value; return value;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册