Java class file verification
chf at redhat.com
Wed Jan 14 21:03:18 UTC 2015
If you look at the documentation: https://docs.oracle.com/javase/specs/jvms/se5.0/html/ClassFile.doc.html
The given local variable must have a value at indices into the code array in the interval [start_pc, start_pc+length], that is, between start_pc and start_pc+length inclusive. The value of start_pc must be a valid index into the code array of this Code attribute and must be the index of the opcode of an instruction. Either the value of start_pc+length must be a valid index into the code array of this Code attribute and be the index of the opcode of an instruction, or it must be the first index beyond the end of that code array."
The first index beyond the end of the code array is acceptable.
----- Original Message -----
> From: "John Bergin" <john.bergin at gmail.com>
> To: discuss at openjdk.java.net
> Sent: Wednesday, January 14, 2015 3:35:48 PM
> Subject: Java class file verification
> Hi all.
> I have a query regarding Java class file verification in particular
> verification of the LocalVariableTable attribute defined by the Java
> Virtual Machine 7 specification here,
> The specification states that "The value of start_pc must be a valid
> index into the code array of this Code attribute and must be the index
> of the opcode of an instruction." And in the example below the
> start_pc for args is 0 and for s it is 3 and both these indexes are
> valid code array offsets.
> public static void main(java.lang.String);
> flags: ACC_PUBLIC, ACC_STATIC
> stack=1, locals=2, args_size=1
> 0: ldc #2 // String A string
> 2: astore_1
> 3: return
> line 3: 0
> line 4: 3
> Start Length Slot Name Signature
> 0 4 0 args [Ljava/lang/String;
> 3 1 1 s Ljava/lang/String;
> My question is: a program I'm helping to develop is dynamically
> generating Java class files where the start_pc indexes are NOT valid
> indexes into the code array (in fact they're off by one) and OpenJDK
> is not rejecting the class via a ClassFormatException. Has anyone got
> any idea why this is the case?
> Kind regards,
More information about the discuss