diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassReader.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassReader.java index 8102a7dee8b..6511d0f905c 100644 --- a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassReader.java +++ b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/ClassReader.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2007, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -56,6 +56,15 @@ public class ClassReader { public Attribute readAttribute() throws IOException { int name_index = readUnsignedShort(); int length = readInt(); + if (length < 0) { // we have an overflow as max_value(u4) > max_value(int) + String attrName; + try { + attrName = getConstantPool().getUTF8Value(name_index); + } catch (ConstantPool.InvalidIndex | ConstantPool.UnexpectedEntry e) { + attrName = ""; + } + throw new FatalError(String.format("attribute %s too big to handle", attrName)); + } byte[] data = new byte[length]; readFully(data); diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/classfile/FatalError.java b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/FatalError.java new file mode 100644 index 00000000000..1f7ad56ef9d --- /dev/null +++ b/src/jdk.jdeps/share/classes/com/sun/tools/classfile/FatalError.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +package com.sun.tools.classfile; + +/** + *
This is NOT part of any supported API.
+ * If you write code that depends on this, you do so at your own risk.
+ * This code and its internal interfaces are subject to change or
+ * deletion without notice.
+ */
+public class FatalError extends Error {
+ private static final long serialVersionUID = 8114054446416187030L;
+
+ FatalError(String message) {
+ super(message);
+ }
+}
diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/javap/JavapTask.java b/src/jdk.jdeps/share/classes/com/sun/tools/javap/JavapTask.java
index e446de3d4e7..fc511a2e25c 100644
--- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/JavapTask.java
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/JavapTask.java
@@ -632,6 +632,13 @@ public class JavapTask implements DisassemblerTool.DisassemblerTask, Messages {
} catch (OutOfMemoryError e) {
reportError("err.nomem");
result = EXIT_ERROR;
+ } catch (FatalError e) {
+ Object msg = e.getLocalizedMessage();
+ if (msg == null) {
+ msg = e;
+ }
+ reportError("err.fatal.err", msg);
+ result = EXIT_ERROR;
} catch (Throwable t) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
diff --git a/src/jdk.jdeps/share/classes/com/sun/tools/javap/resources/javap.properties b/src/jdk.jdeps/share/classes/com/sun/tools/javap/resources/javap.properties
index e406d9c82e5..d1eced3174f 100644
--- a/src/jdk.jdeps/share/classes/com/sun/tools/javap/resources/javap.properties
+++ b/src/jdk.jdeps/share/classes/com/sun/tools/javap/resources/javap.properties
@@ -46,6 +46,7 @@ err.nomem=Insufficient memory. To increase memory use -J-Xmx option.
err.cant.find.module=Cannot find module {0}
err.cant.find.module.ex=Problem finding module {0}: {1}
err.only.for.launcher=This option can only be used when invoking javap from the command-line launcher.
+err.fatal.err=Fatal error: {0}
main.usage.summary=\
Usage: {0}