Thu, 10 Apr 2008 12:21:01 -0400
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
Summary: A check on Code length did not take into account the old sizes of the max_stack, max_locals, and code_length.
Reviewed-by: phh, sbohne
src/share/vm/classfile/classFileParser.cpp | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/classfile/classFileParser.cpp Wed Apr 09 14:22:48 2008 -0400 1.2 +++ b/src/share/vm/classfile/classFileParser.cpp Thu Apr 10 12:21:01 2008 -0400 1.3 @@ -1359,16 +1359,25 @@ 1.4 // Parse additional attributes in code attribute 1.5 cfs->guarantee_more(2, CHECK_(nullHandle)); // code_attributes_count 1.6 u2 code_attributes_count = cfs->get_u2_fast(); 1.7 - unsigned int calculated_attribute_length = sizeof(max_stack) + 1.8 - sizeof(max_locals) + 1.9 - sizeof(code_length) + 1.10 - code_length + 1.11 - sizeof(exception_table_length) + 1.12 - sizeof(code_attributes_count) + 1.13 - exception_table_length*(sizeof(u2) /* start_pc */+ 1.14 - sizeof(u2) /* end_pc */ + 1.15 - sizeof(u2) /* handler_pc */ + 1.16 - sizeof(u2) /* catch_type_index */); 1.17 + 1.18 + unsigned int calculated_attribute_length = 0; 1.19 + 1.20 + if (_major_version > 45 || (_major_version == 45 && _minor_version > 2)) { 1.21 + calculated_attribute_length = 1.22 + sizeof(max_stack) + sizeof(max_locals) + sizeof(code_length); 1.23 + } else { 1.24 + // max_stack, locals and length are smaller in pre-version 45.2 classes 1.25 + calculated_attribute_length = sizeof(u1) + sizeof(u1) + sizeof(u2); 1.26 + } 1.27 + calculated_attribute_length += 1.28 + code_length + 1.29 + sizeof(exception_table_length) + 1.30 + sizeof(code_attributes_count) + 1.31 + exception_table_length * 1.32 + ( sizeof(u2) + // start_pc 1.33 + sizeof(u2) + // end_pc 1.34 + sizeof(u2) + // handler_pc 1.35 + sizeof(u2) ); // catch_type_index 1.36 1.37 while (code_attributes_count--) { 1.38 cfs->guarantee_more(6, CHECK_(nullHandle)); // code_attribute_name_index, code_attribute_length