Skip to content

Commit 1d170c9

Browse files
committed
FIX: classfile/verifier.cpp
Verified by manually inserting an invalid opcode into a classfile. Replaced an opcode with the 'cf' opcode, which is invalid. The opcodes 'cb'-'fd' are unassigned and reserved for future use. Caused by: java.lang.VerifyError: Bad instruction: cf Exception Details: Location: MediumHarvestChurn.main([Ljava/lang/String;)V @56: fast_fgetfield Reason: Error exists in the bytecode Bytecode: 0000000: 2a03 32b8 0007 b600 0d3c bb00 1159 b700 0000010: 134e 1b9a 0006 a700 6a2d 1064 b200 1468 0000020: bc08 b600 1a57 a7ff ec3a 0403 3605 1505 0000030: 1020 a200 2803 3606 cf06 b200 20a2 0017 0000040: 2d15 05b2 0020 6815 0660 b600 2357 8406 0000050: 01a7 ffe7 8405 01a7 ffd7 b800 2706 b200 0000060: 2c68 bc08 4dbb 0011 59b7 0013 4e01 4db8 0000070: 0027 8401 ffb2 002f 1233 b600 35a7 ff95 0000080: b1 Exception Handler Table: bci [25, 38] => handler: 41 Stackmap Table: append_frame(@18,Integer,Top,Object[openjdk#17]) same_frame(@25) same_locals_1_stack_item_frame(@41,Object[openjdk#30]) append_frame(@46,Object[openjdk#30],Integer) append_frame(@56,Integer) chop_frame(@84,1) chop_frame(@90,1) chop_frame(@128,1)
1 parent b96547e commit 1d170c9

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

src/hotspot/share/classfile/verifier.cpp

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,10 @@ void ErrorContext::details(outputStream* ss, const Method* method) const {
446446
}
447447

448448
void ErrorContext::reason_details(outputStream* ss) const {
449-
streamIndentor si(ss);
450-
ss->indent().print_cr("Reason:");
451-
streamIndentor si2(ss);
452-
ss->indent().print("%s", "");
449+
StreamAutoIndentor sai(ss, 2);
450+
ss->print_cr("Reason:");
451+
452+
StreamAutoIndentor sai2(ss, 2);
453453
switch (_fault) {
454454
case INVALID_BYTECODE:
455455
ss->print("Error exists in the bytecode");
@@ -507,7 +507,6 @@ void ErrorContext::reason_details(outputStream* ss) const {
507507

508508
void ErrorContext::location_details(outputStream* ss, const Method* method) const {
509509
if (_bci != -1 && method != nullptr) {
510-
streamIndentor si(ss);
511510
const char* bytecode_name = "<invalid>";
512511
if (method->validate_bci(_bci) != -1) {
513512
Bytecodes::Code code = Bytecodes::code_or_bp_at(method->bcp_from(_bci));
@@ -518,46 +517,51 @@ void ErrorContext::location_details(outputStream* ss, const Method* method) cons
518517
}
519518
}
520519
InstanceKlass* ik = method->method_holder();
521-
ss->indent().print_cr("Location:");
522-
streamIndentor si2(ss);
523-
ss->indent().print_cr("%s.%s%s @%d: %s",
520+
521+
StreamAutoIndentor sai(ss, 2);
522+
ss->print_cr("Location:");
523+
524+
StreamAutoIndentor sai2(ss, 2);
525+
ss->print_cr("%s.%s%s @%d: %s",
524526
ik->name()->as_C_string(), method->name()->as_C_string(),
525527
method->signature()->as_C_string(), _bci, bytecode_name);
526528
}
527529
}
528530

529531
void ErrorContext::frame_details(outputStream* ss) const {
530-
streamIndentor si(ss);
532+
StreamAutoIndentor sai(ss, 2);
531533
if (_type.is_valid() && _type.frame() != nullptr) {
532-
ss->indent().print_cr("Current Frame:");
533-
streamIndentor si2(ss);
534+
ss->print_cr("Current Frame:");
535+
StreamAutoIndentor sai2(ss, 2);
534536
_type.frame()->print_on(ss);
535537
}
536538
if (_expected.is_valid() && _expected.frame() != nullptr) {
537-
ss->indent().print_cr("Stackmap Frame:");
538-
streamIndentor si2(ss);
539+
ss->print_cr("Stackmap Frame:");
540+
StreamAutoIndentor sai2(ss, 2);
539541
_expected.frame()->print_on(ss);
540542
}
541543
}
542544

543545
void ErrorContext::bytecode_details(outputStream* ss, const Method* method) const {
544546
if (method != nullptr) {
545-
streamIndentor si(ss);
546-
ss->indent().print_cr("Bytecode:");
547-
streamIndentor si2(ss);
547+
StreamAutoIndentor sai(ss, 2);
548+
ss->print_cr("Bytecode:");
549+
StreamAutoIndentor sai2(ss, 2);
550+
// TODO: print_data should not indent
548551
ss->print_data(method->code_base(), method->code_size(), false);
549552
}
550553
}
551554

552555
void ErrorContext::handler_details(outputStream* ss, const Method* method) const {
553556
if (method != nullptr) {
554-
streamIndentor si(ss);
557+
StreamAutoIndentor sai(ss, 2);
558+
555559
ExceptionTable table(method);
556560
if (table.length() > 0) {
557-
ss->indent().print_cr("Exception Handler Table:");
558-
streamIndentor si2(ss);
561+
ss->print_cr("Exception Handler Table:");
562+
StreamAutoIndentor sai2(ss, 2);
559563
for (int i = 0; i < table.length(); ++i) {
560-
ss->indent().print_cr("bci [%d, %d] => handler: %d", table.start_pc(i),
564+
ss->print_cr("bci [%d, %d] => handler: %d", table.start_pc(i),
561565
table.end_pc(i), table.handler_pc(i));
562566
}
563567
}
@@ -566,17 +570,16 @@ void ErrorContext::handler_details(outputStream* ss, const Method* method) const
566570

567571
void ErrorContext::stackmap_details(outputStream* ss, const Method* method) const {
568572
if (method != nullptr && method->has_stackmap_table()) {
569-
streamIndentor si(ss);
570-
ss->indent().print_cr("Stackmap Table:");
573+
StreamAutoIndentor sai(ss, 2);
574+
ss->print_cr("Stackmap Table:");
571575
Array<u1>* data = method->stackmap_data();
572576
stack_map_table* sm_table =
573577
stack_map_table::at((address)data->adr_at(0));
574578
stack_map_frame* sm_frame = sm_table->entries();
575-
streamIndentor si2(ss);
579+
StreamAutoIndentor sai2(ss, 2);
576580
int current_offset = -1;
577581
address end_of_sm_table = (address)sm_table + method->stackmap_data()->length();
578582
for (u2 i = 0; i < sm_table->number_of_entries(); ++i) {
579-
ss->indent();
580583
if (!sm_frame->verify((address)sm_frame, end_of_sm_table)) {
581584
sm_frame->print_truncated(ss, current_offset);
582585
return;

0 commit comments

Comments
 (0)