From 6fe18085d2d8934396569692cf7ec14c08b3d119 Mon Sep 17 00:00:00 2001 From: thk123 Date: Mon, 5 Feb 2018 16:58:50 +0000 Subject: [PATCH 1/3] Improved error reporting on invalid constant pool index This will allow easy deduction of whether the invalid index comes from some constant not being loaded (probably only slightly invalid) or reading an irreveant byte when trying to read a constant pool index (much larger than the constant pool size). --- src/java_bytecode/java_bytecode_parser.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/java_bytecode/java_bytecode_parser.cpp b/src/java_bytecode/java_bytecode_parser.cpp index 4b71fd29f13..b2f295affc6 100644 --- a/src/java_bytecode/java_bytecode_parser.cpp +++ b/src/java_bytecode/java_bytecode_parser.cpp @@ -79,6 +79,7 @@ class java_bytecode_parsert:public parsert if(index==0 || index>=constant_pool.size()) { error() << "invalid constant pool index (" << index << ")" << eom; + error() << "constant pool size: " << constant_pool.size() << eom; throw 0; } From 9bfe1770efd59880c1eede3f34ffa6ac179fb9ba Mon Sep 17 00:00:00 2001 From: thk123 Date: Mon, 5 Feb 2018 17:13:49 +0000 Subject: [PATCH 2/3] Adding an early guard for correctly parsed exception table This must be true, so catching this early is an indicator that something has gone wrong earlier when parsing this bytecode file. --- src/java_bytecode/java_bytecode_parser.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/java_bytecode/java_bytecode_parser.cpp b/src/java_bytecode/java_bytecode_parser.cpp index b2f295affc6..0db26a5ec06 100644 --- a/src/java_bytecode/java_bytecode_parser.cpp +++ b/src/java_bytecode/java_bytecode_parser.cpp @@ -947,6 +947,12 @@ void java_bytecode_parsert::rmethod_attribute(methodt &method) { u2 start_pc=read_u2(); u2 end_pc=read_u2(); + + INVARIANT( + start_pc < end_pc, + "The start_pc must be less than the end_pc as this is the range the " + "exception is active"); + u2 handler_pc=read_u2(); u2 catch_type=read_u2(); method.exception_table[e].start_pc=start_pc; From 4a538d20bfe9d66dca1c16f0c27d9932a6e43da7 Mon Sep 17 00:00:00 2001 From: thk123 Date: Mon, 5 Feb 2018 17:24:12 +0000 Subject: [PATCH 3/3] Adding comments on the non-standard patternt --- src/java_bytecode/java_bytecode_convert_method.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/java_bytecode/java_bytecode_convert_method.cpp b/src/java_bytecode/java_bytecode_convert_method.cpp index b834efc4d5c..9cda1dd2c65 100644 --- a/src/java_bytecode/java_bytecode_convert_method.cpp +++ b/src/java_bytecode/java_bytecode_convert_method.cpp @@ -45,6 +45,9 @@ Author: Daniel Kroening, kroening@kroening.com #include #include +/// Given a string of the format '?blah?', will return true when compared +/// against a string that matches appart from any characters that are '?' +/// in the original string. Equivalent to doing a regex match on '.blah.' class patternt { public: