[Jamvm-general] Illegal classes which should cause verification errors do not in JamVM.
Brought to you by:
rlougher
|
From: Steven G. <st...@mu...> - 2016-04-19 19:07:22
|
Hello,
JamVM is able to use classes which are malformed and violate the
specification of the JVM.
Take the given class:
public class Bar
{
public static void main(String... __args)
{
XclinitX();
}
static void XclinitX()
{
System.err.println(new Bar());
}
}
Compile it and modify it with a hex editor so that `XclinitX` becomes
`<clinit>`. Zero prints the following:
Exception in thread "main" java.lang.ClassFormatError: Bad method
name at constant pool index 14 in class file Bar
While JamVM prints this:
Bar@97a2aa08
Bar@97a2b290
According to the virtual machine specification, one cannot
`invokestatic` a static initializer.
> Class and interface initialization methods are invoked
> implicitly by the Java Virtual Machine; they are never invoked
> directly from any Java Virtual Machine instruction, but are invoked
> only indirectly as part of the class initialization process.
Another issue with the following class:
public class Bar
{
public static void main(String... __args)
{
}
public synchronized void XinitX(int __i)
{
System.err.println(__i);
}
}
Modify the compiled class in the hex editor so that `XinitX` becomes
`<init>`. Zero prints:
Exception in thread "main" java.lang.ClassFormatError: Method <init>
in class Bar has illegal modifiers: 0x21
JamVM prints nothing. However the class should not load because the
initializer of an instance cannot be synchronized (along with some other
flags).
This can also be seen with:
public class Bar
{
public Bar()
{
System.err.println("Created");
}
public void XinitX(int __v)
{
System.err.println(__v);
}
public void hello()
{
System.err.println("Hello");
}
public static void main(String... __args)
{
Bar b = new Bar();
b.XinitX(2);
b.hello();
}
}
Hex edit `XinitX` to become `<init>`. JamVM prints:
Created
Hello
while Zero fails to load the class with:
Exception in thread "main" java.lang.VerifyError: Constructor must
call super() or this() before return
|