@@ -781,7 +781,6 @@ void ClassVerifier::verify_method(const methodHandle& m, TRAPS) {
781781
782782    //  Merge with the next instruction
783783    {
784-       int  target;
785784      VerificationType type, type2;
786785      VerificationType atype;
787786
@@ -1606,9 +1605,8 @@ void ClassVerifier::verify_method(const methodHandle& m, TRAPS) {
16061605        case  Bytecodes::_ifle:
16071606          current_frame.pop_stack (
16081607            VerificationType::integer_type (), CHECK_VERIFY (this ));
1609-           target = bcs.dest ();
16101608          stackmap_table.check_jump_target (
1611-             ¤t_frame, target , CHECK_VERIFY (this ));
1609+             ¤t_frame, bcs. bci (), bcs. get_offset_s2 () , CHECK_VERIFY (this ));
16121610          no_control_flow = false ; break ;
16131611        case  Bytecodes::_if_acmpeq :
16141612        case  Bytecodes::_if_acmpne :
@@ -1619,19 +1617,16 @@ void ClassVerifier::verify_method(const methodHandle& m, TRAPS) {
16191617        case  Bytecodes::_ifnonnull :
16201618          current_frame.pop_stack (
16211619            VerificationType::reference_check (), CHECK_VERIFY (this ));
1622-           target = bcs.dest ();
16231620          stackmap_table.check_jump_target 
1624-             (¤t_frame, target , CHECK_VERIFY (this ));
1621+             (¤t_frame, bcs. bci (), bcs. get_offset_s2 () , CHECK_VERIFY (this ));
16251622          no_control_flow = false ; break ;
16261623        case  Bytecodes::_goto :
1627-           target = bcs.dest ();
16281624          stackmap_table.check_jump_target (
1629-             ¤t_frame, target , CHECK_VERIFY (this ));
1625+             ¤t_frame, bcs. bci (), bcs. get_offset_s2 () , CHECK_VERIFY (this ));
16301626          no_control_flow = true ; break ;
16311627        case  Bytecodes::_goto_w :
1632-           target = bcs.dest_w ();
16331628          stackmap_table.check_jump_target (
1634-             ¤t_frame, target , CHECK_VERIFY (this ));
1629+             ¤t_frame, bcs. bci (), bcs. get_offset_s4 () , CHECK_VERIFY (this ));
16351630          no_control_flow = true ; break ;
16361631        case  Bytecodes::_tableswitch :
16371632        case  Bytecodes::_lookupswitch :
@@ -2280,15 +2275,14 @@ void ClassVerifier::verify_switch(
22802275      }
22812276    }
22822277  }
2283-   int  target = bci + default_offset;
2284-   stackmap_table->check_jump_target (current_frame, target, CHECK_VERIFY (this ));
2278+   stackmap_table->check_jump_target (current_frame, bci, default_offset, CHECK_VERIFY (this ));
22852279  for  (int  i = 0 ; i < keys; i++) {
22862280    //  Because check_jump_target() may safepoint, the bytecode could have
22872281    //  moved, which means 'aligned_bcp' is no good and needs to be recalculated.
22882282    aligned_bcp = align_up (bcs->bcp () + 1 , jintSize);
2289-     target = bci +  (jint)Bytes::get_Java_u4 (aligned_bcp+(3 +i*delta)*jintSize);
2283+     int  offset =  (jint)Bytes::get_Java_u4 (aligned_bcp+(3 +i*delta)*jintSize);
22902284    stackmap_table->check_jump_target (
2291-       current_frame, target , CHECK_VERIFY (this ));
2285+       current_frame, bci, offset , CHECK_VERIFY (this ));
22922286  }
22932287  NOT_PRODUCT (aligned_bcp = nullptr );  //  no longer valid at this point
22942288}
@@ -2549,7 +2543,12 @@ bool ClassVerifier::ends_in_athrow(u4 start_bc_offset) {
25492543
25502544      case  Bytecodes::_goto:
25512545      case  Bytecodes::_goto_w: {
2552-         int  target = (opcode == Bytecodes::_goto ? bcs.dest () : bcs.dest_w ());
2546+         int  offset = (opcode == Bytecodes::_goto ? bcs.get_offset_s2 () : bcs.get_offset_s4 ());
2547+         int  min_offset = -1  * max_method_code_size;
2548+         //  Check offset for overflow
2549+         if  (offset < min_offset || offset > max_method_code_size) return  false ;
2550+ 
2551+         int  target = bci + offset;
25532552        if  (visited_branches->contains (bci)) {
25542553          if  (bci_stack->is_empty ()) {
25552554            if  (handler_stack->is_empty ()) {
@@ -2607,7 +2606,10 @@ bool ClassVerifier::ends_in_athrow(u4 start_bc_offset) {
26072606
26082607          //  Push the switch alternatives onto the stack.
26092608          for  (int  i = 0 ; i < keys; i++) {
2610-             int  target = bci + (jint)Bytes::get_Java_u4 (aligned_bcp+(3 +i*delta)*jintSize);
2609+             int  min_offset = -1  * max_method_code_size;
2610+             int  offset = (jint)Bytes::get_Java_u4 (aligned_bcp+(3 +i*delta)*jintSize);
2611+             if  (offset < min_offset || offset > max_method_code_size) return  false ;
2612+             int  target = bci + offset;
26112613            if  (target > code_length) return  false ;
26122614            bci_stack->push (target);
26132615          }
0 commit comments