提交 6e6e66ef 编写于 作者: P pgovereau

8038023: Compiler crash ClassCastException

Summary: Add additional checks on results of ClassReader.readPool
Reviewed-by: vromero
上级 0b6d20a5
...@@ -512,14 +512,14 @@ public class ClassReader { ...@@ -512,14 +512,14 @@ public class ClassReader {
break; break;
case CONSTANT_Fieldref: { case CONSTANT_Fieldref: {
ClassSymbol owner = readClassSymbol(getChar(index + 1)); ClassSymbol owner = readClassSymbol(getChar(index + 1));
NameAndType nt = (NameAndType)readPool(getChar(index + 3)); NameAndType nt = readNameAndType(getChar(index + 3));
poolObj[i] = new VarSymbol(0, nt.name, nt.uniqueType.type, owner); poolObj[i] = new VarSymbol(0, nt.name, nt.uniqueType.type, owner);
break; break;
} }
case CONSTANT_Methodref: case CONSTANT_Methodref:
case CONSTANT_InterfaceMethodref: { case CONSTANT_InterfaceMethodref: {
ClassSymbol owner = readClassSymbol(getChar(index + 1)); ClassSymbol owner = readClassSymbol(getChar(index + 1));
NameAndType nt = (NameAndType)readPool(getChar(index + 3)); NameAndType nt = readNameAndType(getChar(index + 3));
poolObj[i] = new MethodSymbol(0, nt.name, nt.uniqueType.type, owner); poolObj[i] = new MethodSymbol(0, nt.name, nt.uniqueType.type, owner);
break; break;
} }
...@@ -588,13 +588,34 @@ public class ClassReader { ...@@ -588,13 +588,34 @@ public class ClassReader {
/** Read class entry. /** Read class entry.
*/ */
ClassSymbol readClassSymbol(int i) { ClassSymbol readClassSymbol(int i) {
return (ClassSymbol) (readPool(i)); Object obj = readPool(i);
if (obj != null && !(obj instanceof ClassSymbol))
throw badClassFile("bad.const.pool.entry",
currentClassFile.toString(),
"CONSTANT_Class_info", i);
return (ClassSymbol)obj;
} }
/** Read name. /** Read name.
*/ */
Name readName(int i) { Name readName(int i) {
return (Name) (readPool(i)); Object obj = readPool(i);
if (obj != null && !(obj instanceof Name))
throw badClassFile("bad.const.pool.entry",
currentClassFile.toString(),
"CONSTANT_Utf8_info or CONSTANT_String_info", i);
return (Name)obj;
}
/** Read name and type.
*/
NameAndType readNameAndType(int i) {
Object obj = readPool(i);
if (obj != null && !(obj instanceof NameAndType))
throw badClassFile("bad.const.pool.entry",
currentClassFile.toString(),
"CONSTANT_NameAndType_info", i);
return (NameAndType)obj;
} }
/************************************************************************ /************************************************************************
...@@ -1245,7 +1266,7 @@ public class ClassReader { ...@@ -1245,7 +1266,7 @@ public class ClassReader {
sym.owner.members().remove(sym); sym.owner.members().remove(sym);
ClassSymbol self = (ClassSymbol)sym; ClassSymbol self = (ClassSymbol)sym;
ClassSymbol c = readClassSymbol(nextChar()); ClassSymbol c = readClassSymbol(nextChar());
NameAndType nt = (NameAndType)readPool(nextChar()); NameAndType nt = readNameAndType(nextChar());
if (c.members_field == null) if (c.members_field == null)
throw badClassFile("bad.enclosing.class", self, c); throw badClassFile("bad.enclosing.class", self, c);
......
...@@ -1705,6 +1705,11 @@ compiler.err.cant.access=\ ...@@ -1705,6 +1705,11 @@ compiler.err.cant.access=\
cannot access {0}\n\ cannot access {0}\n\
{1} {1}
# 0: file name, 1: expected CP entry type, 2: constant pool index
compiler.misc.bad.const.pool.entry=\
bad constant pool entry in {0}\n\
expected {1} at index {2}
# 0: file name, 1: message segment # 0: file name, 1: message segment
compiler.misc.bad.class.file.header=\ compiler.misc.bad.class.file.header=\
bad class file: {0}\n\ bad class file: {0}\n\
......
...@@ -111,3 +111,4 @@ compiler.warn.unknown.enum.constant # in bad class file ...@@ -111,3 +111,4 @@ compiler.warn.unknown.enum.constant # in bad class file
compiler.warn.unknown.enum.constant.reason # in bad class file compiler.warn.unknown.enum.constant.reason # in bad class file
compiler.warn.override.equals.but.not.hashcode # when a class overrides equals but not hashCode method from Object compiler.warn.override.equals.but.not.hashcode # when a class overrides equals but not hashCode method from Object
compiler.err.cant.inherit.from.anon # error for subclass of anonymous class compiler.err.cant.inherit.from.anon # error for subclass of anonymous class
compiler.misc.bad.const.pool.entry # constant pool entry has wrong type
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册