@@ -791,7 +791,6 @@ void ClassVerifier::verify_method(const methodHandle& m, TRAPS) {
791791 // Merge with the next instruction
792792 {
793793 u2 index;
794- int target;
795794 VerificationType type, type2;
796795 VerificationType atype;
797796
@@ -1607,9 +1606,8 @@ void ClassVerifier::verify_method(const methodHandle& m, TRAPS) {
16071606 case Bytecodes::_ifle:
16081607 current_frame.pop_stack (
16091608 VerificationType::integer_type (), CHECK_VERIFY (this ));
1610- target = bcs.dest ();
16111609 stackmap_table.check_jump_target (
1612- ¤t_frame, target , CHECK_VERIFY (this ));
1610+ ¤t_frame, bcs. bci (), bcs. get_offset_s2 () , CHECK_VERIFY (this ));
16131611 no_control_flow = false ; break ;
16141612 case Bytecodes::_if_acmpeq :
16151613 case Bytecodes::_if_acmpne :
@@ -1620,19 +1618,16 @@ void ClassVerifier::verify_method(const methodHandle& m, TRAPS) {
16201618 case Bytecodes::_ifnonnull :
16211619 current_frame.pop_stack (
16221620 VerificationType::reference_check (), CHECK_VERIFY (this ));
1623- target = bcs.dest ();
16241621 stackmap_table.check_jump_target
1625- (¤t_frame, target , CHECK_VERIFY (this ));
1622+ (¤t_frame, bcs. bci (), bcs. get_offset_s2 () , CHECK_VERIFY (this ));
16261623 no_control_flow = false ; break ;
16271624 case Bytecodes::_goto :
1628- target = bcs.dest ();
16291625 stackmap_table.check_jump_target (
1630- ¤t_frame, target , CHECK_VERIFY (this ));
1626+ ¤t_frame, bcs. bci (), bcs. get_offset_s2 () , CHECK_VERIFY (this ));
16311627 no_control_flow = true ; break ;
16321628 case Bytecodes::_goto_w :
1633- target = bcs.dest_w ();
16341629 stackmap_table.check_jump_target (
1635- ¤t_frame, target , CHECK_VERIFY (this ));
1630+ ¤t_frame, bcs. bci (), bcs. get_offset_s4 () , CHECK_VERIFY (this ));
16361631 no_control_flow = true ; break ;
16371632 case Bytecodes::_tableswitch :
16381633 case Bytecodes::_lookupswitch :
@@ -2282,15 +2277,14 @@ void ClassVerifier::verify_switch(
22822277 }
22832278 }
22842279 }
2285- int target = bci + default_offset;
2286- stackmap_table->check_jump_target (current_frame, target, CHECK_VERIFY (this ));
2280+ stackmap_table->check_jump_target (current_frame, bci, default_offset, CHECK_VERIFY (this ));
22872281 for (int i = 0 ; i < keys; i++) {
22882282 // Because check_jump_target() may safepoint, the bytecode could have
22892283 // moved, which means 'aligned_bcp' is no good and needs to be recalculated.
22902284 aligned_bcp = align_up (bcs->bcp () + 1 , jintSize);
2291- target = bci + (jint)Bytes::get_Java_u4 (aligned_bcp+(3 +i*delta)*jintSize);
2285+ int offset = (jint)Bytes::get_Java_u4 (aligned_bcp+(3 +i*delta)*jintSize);
22922286 stackmap_table->check_jump_target (
2293- current_frame, target , CHECK_VERIFY (this ));
2287+ current_frame, bci, offset , CHECK_VERIFY (this ));
22942288 }
22952289 NOT_PRODUCT (aligned_bcp = nullptr ); // no longer valid at this point
22962290}
@@ -2549,8 +2543,13 @@ bool ClassVerifier::ends_in_athrow(u4 start_bc_offset) {
25492543 break ;
25502544
25512545 case Bytecodes::_goto:
2552- case Bytecodes::_goto_w:
2553- target = (opcode == Bytecodes::_goto ? bcs.dest () : bcs.dest_w ());
2546+ case Bytecodes::_goto_w: {
2547+ int offset = (opcode == Bytecodes::_goto ? bcs.get_offset_s2 () : bcs.get_offset_s4 ());
2548+ int min_offset = -1 * max_method_code_size;
2549+ // Check offset for overflow
2550+ if (offset < min_offset || offset > max_method_code_size) return false ;
2551+
2552+ target = bci + offset;
25542553 if (visited_branches->contains (bci)) {
25552554 if (bci_stack->is_empty ()) {
25562555 if (handler_stack->is_empty ()) {
@@ -2571,6 +2570,7 @@ bool ClassVerifier::ends_in_athrow(u4 start_bc_offset) {
25712570 visited_branches->append (bci);
25722571 }
25732572 break ;
2573+ }
25742574
25752575 // Check that all switch alternatives end in 'athrow' bytecodes. Since it
25762576 // is difficult to determine where each switch alternative ends, parse
@@ -2607,7 +2607,10 @@ bool ClassVerifier::ends_in_athrow(u4 start_bc_offset) {
26072607
26082608 // Push the switch alternatives onto the stack.
26092609 for (int i = 0 ; i < keys; i++) {
2610- u4 target = bci + (jint)Bytes::get_Java_u4 (aligned_bcp+(3 +i*delta)*jintSize);
2610+ int min_offset = -1 * max_method_code_size;
2611+ int offset = (jint)Bytes::get_Java_u4 (aligned_bcp+(3 +i*delta)*jintSize);
2612+ if (offset < min_offset || offset > max_method_code_size) return false ;
2613+ u4 target = bci + offset;
26112614 if (target > code_length) return false ;
26122615 bci_stack->push (target);
26132616 }
0 commit comments