8232890: Remove bad Code attribute parsing code
authorhseigel
Mon, 28 Oct 2019 12:55:48 +0000
changeset 58817 7f27d70a2424
parent 58816 77148b8bb7a1
child 58818 a9316bb4c0e8
child 58819 ef8be51fff48
child 58823 6a21dba79b81
8232890: Remove bad Code attribute parsing code Summary: Remove code that accepts illegal max_stack, max_locals, and length values for Code attribute in old class files. Reviewed-by: dholmes, lfoltan
src/hotspot/share/classfile/classFileParser.cpp
--- a/src/hotspot/share/classfile/classFileParser.cpp	Wed Oct 23 12:51:53 2019 +0200
+++ b/src/hotspot/share/classfile/classFileParser.cpp	Mon Oct 28 12:55:48 2019 +0000
@@ -2448,17 +2448,10 @@
       parsed_code_attribute = true;
 
       // Stack size, locals size, and code size
-      if (_major_version == 45 && _minor_version <= 2) {
-        cfs->guarantee_more(4, CHECK_NULL);
-        max_stack = cfs->get_u1_fast();
-        max_locals = cfs->get_u1_fast();
-        code_length = cfs->get_u2_fast();
-      } else {
-        cfs->guarantee_more(8, CHECK_NULL);
-        max_stack = cfs->get_u2_fast();
-        max_locals = cfs->get_u2_fast();
-        code_length = cfs->get_u4_fast();
-      }
+      cfs->guarantee_more(8, CHECK_NULL);
+      max_stack = cfs->get_u2_fast();
+      max_locals = cfs->get_u2_fast();
+      code_length = cfs->get_u4_fast();
       if (_need_verify) {
         guarantee_property(args_size <= max_locals,
                            "Arguments can't fit into locals in class file %s",
@@ -2489,13 +2482,8 @@
 
       unsigned int calculated_attribute_length = 0;
 
-      if (_major_version > 45 || (_major_version == 45 && _minor_version > 2)) {
-        calculated_attribute_length =
-            sizeof(max_stack) + sizeof(max_locals) + sizeof(code_length);
-      } else {
-        // max_stack, locals and length are smaller in pre-version 45.2 classes
-        calculated_attribute_length = sizeof(u1) + sizeof(u1) + sizeof(u2);
-      }
+      calculated_attribute_length =
+          sizeof(max_stack) + sizeof(max_locals) + sizeof(code_length);
       calculated_attribute_length +=
         code_length +
         sizeof(exception_table_length) +