Add additional checks for index size when writing various items

This commit is contained in:
Ben Gruver
2011-11-17 11:21:28 -08:00
committed by =
parent d12c769276
commit 8b3b577f00
3 changed files with 34 additions and 5 deletions

View File

@ -117,8 +117,20 @@ public class FieldIdItem extends Item<FieldIdItem> {
out.annotate(4, "field_name: " + fieldName.getStringValue());
}
out.writeShort(classType.getIndex());
out.writeShort(fieldType.getIndex());
int classIndex = classType.getIndex();
if (classIndex > 0xffff) {
throw new RuntimeException(String.format("Error writing field_id_item for %s. The type index of " +
"defining class %s is too large", getFieldString(), classType.getTypeDescriptor()));
}
out.writeShort(classIndex);
int typeIndex = fieldType.getIndex();
if (typeIndex > 0xffff) {
throw new RuntimeException(String.format("Error writing field_id_item for %s. The type index of field " +
"type %s is too large", getFieldString(), fieldType.getTypeDescriptor()));
}
out.writeShort(typeIndex);
out.writeInt(fieldName.getIndex());
}

View File

@ -112,8 +112,20 @@ public class MethodIdItem extends Item<MethodIdItem> {
out.annotate(4, "method_name: " + methodName.getStringValue());
}
out.writeShort(classType.getIndex());
out.writeShort(methodPrototype.getIndex());
int classIndex = classType.getIndex();
if (classIndex > 0xffff) {
throw new RuntimeException(String.format("Error writing method_id_item for %s. The type index of " +
"defining class %s is too large", getMethodString(), classType.getTypeDescriptor()));
}
out.writeShort(classIndex);
int prototypeIndex = methodPrototype.getIndex();
if (prototypeIndex > 0xffff) {
throw new RuntimeException(String.format("Error writing method_id_item for %0. The prototype index of " +
"method prototype %s is too large", getMethodString(), methodPrototype.getPrototypeString()));
}
out.writeShort(prototypeIndex);
out.writeInt(methodName.getIndex());
}

View File

@ -116,7 +116,12 @@ public class TypeListItem extends Item<TypeListItem> {
}
out.writeInt(typeList.length);
for (TypeIdItem typeIdItem: typeList) {
out.writeShort(typeIdItem.getIndex());
int typeIndex = typeIdItem.getIndex();
if (typeIndex > 0xffff) {
throw new RuntimeException(String.format("Error writing type_list entry. The type index of " +
"type %s is too large", typeIdItem.getTypeDescriptor()));
}
out.writeShort(typeIndex);
}
}