@@ -717,7 +717,6 @@ void ClassVerifier::verify_method(const methodHandle& m, TRAPS) {
717717 // Merge with the next instruction
718718 {
719719 u2 index;
720- int target;
721720 VerificationType type, type2;
722721 VerificationType atype;
723722
@@ -1534,9 +1533,8 @@ void ClassVerifier::verify_method(const methodHandle& m, TRAPS) {
15341533 case Bytecodes::_ifle:
15351534 current_frame.pop_stack (
15361535 VerificationType::integer_type (), CHECK_VERIFY (this ));
1537- target = bcs.dest ();
15381536 stackmap_table.check_jump_target (
1539- ¤t_frame, target , CHECK_VERIFY (this ));
1537+ ¤t_frame, bcs. bci (), bcs. get_offset_s2 () , CHECK_VERIFY (this ));
15401538 no_control_flow = false ; break ;
15411539 case Bytecodes::_if_acmpeq :
15421540 case Bytecodes::_if_acmpne :
@@ -1547,19 +1545,16 @@ void ClassVerifier::verify_method(const methodHandle& m, TRAPS) {
15471545 case Bytecodes::_ifnonnull :
15481546 current_frame.pop_stack (
15491547 VerificationType::reference_check (), CHECK_VERIFY (this ));
1550- target = bcs.dest ();
15511548 stackmap_table.check_jump_target
1552- (¤t_frame, target , CHECK_VERIFY (this ));
1549+ (¤t_frame, bcs. bci (), bcs. get_offset_s2 () , CHECK_VERIFY (this ));
15531550 no_control_flow = false ; break ;
15541551 case Bytecodes::_goto :
1555- target = bcs.dest ();
15561552 stackmap_table.check_jump_target (
1557- ¤t_frame, target , CHECK_VERIFY (this ));
1553+ ¤t_frame, bcs. bci (), bcs. get_offset_s2 () , CHECK_VERIFY (this ));
15581554 no_control_flow = true ; break ;
15591555 case Bytecodes::_goto_w :
1560- target = bcs.dest_w ();
15611556 stackmap_table.check_jump_target (
1562- ¤t_frame, target , CHECK_VERIFY (this ));
1557+ ¤t_frame, bcs. bci (), bcs. get_offset_s4 () , CHECK_VERIFY (this ));
15631558 no_control_flow = true ; break ;
15641559 case Bytecodes::_tableswitch :
15651560 case Bytecodes::_lookupswitch :
@@ -2208,15 +2203,14 @@ void ClassVerifier::verify_switch(
22082203 }
22092204 }
22102205 }
2211- int target = bci + default_offset;
2212- stackmap_table->check_jump_target (current_frame, target, CHECK_VERIFY (this ));
2206+ stackmap_table->check_jump_target (current_frame, bci, default_offset, CHECK_VERIFY (this ));
22132207 for (int i = 0 ; i < keys; i++) {
22142208 // Because check_jump_target() may safepoint, the bytecode could have
22152209 // moved, which means 'aligned_bcp' is no good and needs to be recalculated.
22162210 aligned_bcp = align_up (bcs->bcp () + 1 , jintSize);
2217- target = bci + (jint)Bytes::get_Java_u4 (aligned_bcp+(3 +i*delta)*jintSize);
2211+ int offset = (jint)Bytes::get_Java_u4 (aligned_bcp+(3 +i*delta)*jintSize);
22182212 stackmap_table->check_jump_target (
2219- current_frame, target , CHECK_VERIFY (this ));
2213+ current_frame, bci, offset , CHECK_VERIFY (this ));
22202214 }
22212215 NOT_PRODUCT (aligned_bcp = NULL ); // no longer valid at this point
22222216}
@@ -2479,8 +2473,13 @@ bool ClassVerifier::ends_in_athrow(u4 start_bc_offset) {
24792473 break ;
24802474
24812475 case Bytecodes::_goto:
2482- case Bytecodes::_goto_w:
2483- target = (opcode == Bytecodes::_goto ? bcs.dest () : bcs.dest_w ());
2476+ case Bytecodes::_goto_w: {
2477+ int offset = (opcode == Bytecodes::_goto ? bcs.get_offset_s2 () : bcs.get_offset_s4 ());
2478+ int min_offset = -1 * max_method_code_size;
2479+ // Check offset for overflow
2480+ if (offset < min_offset || offset > max_method_code_size) return false ;
2481+
2482+ target = bci + offset;
24842483 if (visited_branches->contains (bci)) {
24852484 if (bci_stack->is_empty ()) {
24862485 if (handler_stack->is_empty ()) {
@@ -2501,6 +2500,7 @@ bool ClassVerifier::ends_in_athrow(u4 start_bc_offset) {
25012500 visited_branches->append (bci);
25022501 }
25032502 break ;
2503+ }
25042504
25052505 // Check that all switch alternatives end in 'athrow' bytecodes. Since it
25062506 // is difficult to determine where each switch alternative ends, parse
@@ -2537,7 +2537,10 @@ bool ClassVerifier::ends_in_athrow(u4 start_bc_offset) {
25372537
25382538 // Push the switch alternatives onto the stack.
25392539 for (int i = 0 ; i < keys; i++) {
2540- u4 target = bci + (jint)Bytes::get_Java_u4 (aligned_bcp+(3 +i*delta)*jintSize);
2540+ int min_offset = -1 * max_method_code_size;
2541+ int offset = (jint)Bytes::get_Java_u4 (aligned_bcp+(3 +i*delta)*jintSize);
2542+ if (offset < min_offset || offset > max_method_code_size) return false ;
2543+ u4 target = bci + offset;
25412544 if (target > code_length) return false ;
25422545 bci_stack->push (target);
25432546 }
0 commit comments