EA-43240 - AIOOBE: ClassReader.a

Index out of bounds from ASM
This commit is contained in:
Andrey Breslav
2013-01-28 21:22:29 +04:00
parent d633dd7bb7
commit 17b4a5a15c
@@ -17,6 +17,7 @@
package org.jetbrains.jet.plugin.versions; package org.jetbrains.jet.plugin.versions;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.fileTypes.StdFileTypes;
import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.Ref;
import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFile;
@@ -31,12 +32,14 @@ import org.jetbrains.asm4.Opcodes;
import org.jetbrains.jet.lang.resolve.java.AbiVersionUtil; import org.jetbrains.jet.lang.resolve.java.AbiVersionUtil;
import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames; import org.jetbrains.jet.lang.resolve.java.JvmStdlibNames;
import java.lang.Throwable;
import java.util.Map; import java.util.Map;
/** /**
* Important! This is not a stub-based index. And it has its own version * Important! This is not a stub-based index. And it has its own version
*/ */
public class KotlinAbiVersionIndex extends ScalarIndexExtension<Integer> { public class KotlinAbiVersionIndex extends ScalarIndexExtension<Integer> {
private static final Logger LOG = Logger.getInstance(KotlinAbiVersionIndex.class);
public static final KotlinAbiVersionIndex INSTANCE = new KotlinAbiVersionIndex(); public static final KotlinAbiVersionIndex INSTANCE = new KotlinAbiVersionIndex();
@@ -58,32 +61,37 @@ public class KotlinAbiVersionIndex extends ScalarIndexExtension<Integer> {
final Map<Integer, Void> result = Maps.newHashMap(); final Map<Integer, Void> result = Maps.newHashMap();
final Ref<Boolean> annotationPresent = new Ref<Boolean>(false); final Ref<Boolean> annotationPresent = new Ref<Boolean>(false);
ClassReader classReader = new ClassReader(inputData.getContent()); try {
classReader.accept(new ClassVisitor(Opcodes.ASM4) { ClassReader classReader = new ClassReader(inputData.getContent());
@Override classReader.accept(new ClassVisitor(Opcodes.ASM4) {
public AnnotationVisitor visitAnnotation(String desc, boolean visible) { @Override
if (!JvmStdlibNames.JET_CLASS.getDescriptor().equals(desc) && public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
!JvmStdlibNames.JET_PACKAGE_CLASS.getDescriptor().equals(desc)) { if (!JvmStdlibNames.JET_CLASS.getDescriptor().equals(desc) &&
return null; !JvmStdlibNames.JET_PACKAGE_CLASS.getDescriptor().equals(desc)) {
} return null;
annotationPresent.set(true); }
return new AnnotationVisitor(Opcodes.ASM4) { annotationPresent.set(true);
@Override return new AnnotationVisitor(Opcodes.ASM4) {
public void visit(String name, Object value) { @Override
if (JvmStdlibNames.ABI_VERSION_NAME.equals(name)) { public void visit(String name, Object value) {
if (value instanceof Integer) { if (JvmStdlibNames.ABI_VERSION_NAME.equals(name)) {
Integer abiVersion = (Integer) value; if (value instanceof Integer) {
result.put(abiVersion, null); Integer abiVersion = (Integer) value;
} result.put(abiVersion, null);
else { }
// Version is set to something weird else {
result.put(AbiVersionUtil.INVALID_VERSION, null); // Version is set to something weird
result.put(AbiVersionUtil.INVALID_VERSION, null);
}
} }
} }
} };
}; }
} }, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
}, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES); }
catch (Throwable e) {
LOG.warn("Indexing ABI version for file " + inputData.getFile(), e);
}
if (annotationPresent.get() && result.isEmpty()) { if (annotationPresent.get() && result.isEmpty()) {
// No version at all: the class is too old // No version at all: the class is too old