Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is ILLegal Byte code?

Tags:

java

bytecode

While reading Java Security I came across the below sentences but could not get any satisfactory explanation on the Internet. Can anyone please explain

  • Prevents loading of classes with bytecode
  • Prevents loading of in illegal packages
like image 843
Geek Avatar asked Feb 05 '26 06:02

Geek


2 Answers

We cannot, however, be sure that the class itself is safe. There is still the safety net of the SecurityManager which will prevent the class from accessing protected resources such as network and local hard disk, but that in itself is not enough. The class might contain illegal bytecode, forge pointers to protected memory, overflow or underflow the program stack, or in some other way corrupt the integrity of the JVM. Check Topic The Class File Verifier in [1]: http://medialab.di.unipi.it/doc/JNetSec/jns_ch5.htm

like image 139
valli Avatar answered Feb 12 '26 11:02

valli


The byte code verifier makes the following checks:

  • Branches must be within the bounds of the code array for the method.
  • The targets of all control-flow instructions are each the start of an instruction. In the case of a wide instruction, the wide opcode is considered the start of the instruction, and the opcode giving the operation modified by that wide instruction is not considered to start an instruction. Branches into the middle of an instruction are disallowed.
  • No instruction can access or modify a local variable at an index greater than or equal to the number of local variables that its method indicates it allocates.
  • All references to the constant pool must be to an entry of the appropriate type. For example: the instruction ldc can be used only for data of type int or float or for instances of class String; the instruction getfield must reference a field.
  • The code does not end in the middle of an instruction.
  • Execution cannot fall off the end of the code.
  • For each exception handler, the starting and ending point of code protected by the handler must be at the beginning of an instruction or, in the case of the ending point, immediately past the end of the code. The starting point must be before the ending point. - The exception handler code must start at a valid instruction, and it may not start at an opcode being modified by the wide instruction.
like image 26
brianegge Avatar answered Feb 12 '26 13:02

brianegge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!