changeset 8514:bd297baf4981

8160090: Better signature handling in pack200 Reviewed-by: jrose, mschoene
author ksrini
date Wed, 19 Oct 2016 02:27:09 +0100
parents 47bb3af1c6a9
children 38b3caf22e7e
files src/share/native/com/sun/java/util/jar/pack/unpack.cpp
diffstat 1 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/native/com/sun/java/util/jar/pack/unpack.cpp	Wed Oct 19 02:13:26 2016 +0100
+++ b/src/share/native/com/sun/java/util/jar/pack/unpack.cpp	Wed Oct 19 02:27:09 2016 +0100
@@ -157,7 +157,10 @@
 
   const char* utf8String() {
     assert(tagMatches(CONSTANT_Utf8));
-    assert(value.b.len == strlen((const char*)value.b.ptr));
+    if (value.b.len != strlen((const char*)value.b.ptr)) {
+      unpack_abort("bad utf8 encoding");
+      // and fall through
+    }
     return (const char*)value.b.ptr;
   }
 
@@ -1262,10 +1265,10 @@
     CHECK;
     int nc = 0;
 
-    for ( const char* ncp = form.utf8String() ; *ncp; ncp++) {
-      if (*ncp == 'L')  nc++;
+    for (int j = 0; j < (int)form.value.b.len; j++) {
+      int c = form.value.b.ptr[j];
+      if (c == 'L') nc++;
     }
-
     ncTotal += nc;
     e.refs = U_NEW(entry*, cpMap[i].nrefs = 1 + nc);
     CHECK;
@@ -3711,8 +3714,8 @@
   uint* map = (uint*) bcimap.base();
   assert(len > 0);  // must be initialized before using to_bci
   if (len == 0) {
-      abort("bad bcimap");
-      return 0;
+    abort("bad bcimap");
+    return 0;
   }
   if (bii < len)
     return map[bii];
@@ -4658,6 +4661,7 @@
     entry* e = file_name.getRef();
     CHECK_0;
     cur_file.name = e->utf8String();
+    CHECK_0;
     bool haveLongSize = ((archive_options & AO_HAVE_FILE_SIZE_HI) != 0);
     cur_file.size = file_size_hi.getLong(file_size_lo, haveLongSize);
     if ((archive_options & AO_HAVE_FILE_MODTIME) != 0)