diff --git a/src/hotspot/share/cds/classListParser.cpp b/src/hotspot/share/cds/classListParser.cpp index b2695ac2e78..f8d24295a12 100644 --- a/src/hotspot/share/cds/classListParser.cpp +++ b/src/hotspot/share/cds/classListParser.cpp @@ -463,7 +463,7 @@ void ClassListParser::check_class_name(const char* class_name) { err = "class name too long"; } else { assert(Symbol::max_length() < INT_MAX && len < INT_MAX, "must be"); - if (!UTF8::is_legal_utf8((const unsigned char*)class_name, (int)len, /*version_leq_47*/false)) { + if (!UTF8::is_legal_utf8((const unsigned char*)class_name, len, /*version_leq_47*/false)) { err = "class name is not valid UTF8"; } } @@ -849,4 +849,3 @@ void ClassListParser::parse_constant_pool_tag() { ClassPrelinker::preresolve_field_and_method_cp_entries(THREAD, ik, &preresolve_list); } } - diff --git a/src/hotspot/share/classfile/classFileParser.cpp b/src/hotspot/share/classfile/classFileParser.cpp index a5b8604a9d5..46421ccc90c 100644 --- a/src/hotspot/share/classfile/classFileParser.cpp +++ b/src/hotspot/share/classfile/classFileParser.cpp @@ -4559,7 +4559,8 @@ void ClassFileParser::verify_legal_utf8(const unsigned char* buffer, int length, TRAPS) const { assert(_need_verify, "only called when _need_verify is true"); - if (!UTF8::is_legal_utf8(buffer, length, _major_version <= 47)) { + // Note: 0 <= length < 64K, as it comes from a u2 entry in the CP. + if (!UTF8::is_legal_utf8(buffer, static_cast(length), _major_version <= 47)) { classfile_parse_error("Illegal UTF8 string in constant pool in class file %s", THREAD); } } diff --git a/src/hotspot/share/classfile/systemDictionary.cpp b/src/hotspot/share/classfile/systemDictionary.cpp index e32d124013d..b9a559cf977 100644 --- a/src/hotspot/share/classfile/systemDictionary.cpp +++ b/src/hotspot/share/classfile/systemDictionary.cpp @@ -285,8 +285,7 @@ Symbol* SystemDictionary::class_name_symbol(const char* name, Symbol* exception, return nullptr; } // Callers should ensure that the name is never an illegal UTF8 string. - assert(UTF8::is_legal_utf8((const unsigned char*)name, - static_cast(name_len), false), + assert(UTF8::is_legal_utf8((const unsigned char*)name, name_len, false), "Class name is not a valid utf8 string."); // Make a new symbol for the class name. diff --git a/src/hotspot/share/prims/jniCheck.cpp b/src/hotspot/share/prims/jniCheck.cpp index 87543686c3c..8c1f9f53b34 100644 --- a/src/hotspot/share/prims/jniCheck.cpp +++ b/src/hotspot/share/prims/jniCheck.cpp @@ -475,7 +475,7 @@ void jniCheck::validate_class_descriptor(JavaThread* thr, const char* name) { } // Verify that the class name given is a valid utf8 string - if (!UTF8::is_legal_utf8((const unsigned char*)name, (int)strlen(name), false)) { + if (!UTF8::is_legal_utf8((const unsigned char*)name, strlen(name), false)) { char msg[JVM_MAXPATHLEN]; jio_snprintf(msg, JVM_MAXPATHLEN, "%s%s%s", fatal_non_utf8_class_name1, name, fatal_non_utf8_class_name2); ReportJNIFatalError(thr, msg); diff --git a/src/hotspot/share/prims/jvm.cpp b/src/hotspot/share/prims/jvm.cpp index 6425f5f583f..bf9874956ba 100644 --- a/src/hotspot/share/prims/jvm.cpp +++ b/src/hotspot/share/prims/jvm.cpp @@ -809,7 +809,7 @@ JVM_ENTRY(jclass, JVM_FindClassFromBootLoader(JNIEnv* env, // into the constant pool. return nullptr; } - assert(UTF8::is_legal_utf8((const unsigned char*)name, (int)strlen(name), false), "illegal UTF name"); + assert(UTF8::is_legal_utf8((const unsigned char*)name, strlen(name), false), "illegal UTF name"); TempNewSymbol h_name = SymbolTable::new_symbol(name); Klass* k = SystemDictionary::resolve_or_null(h_name, CHECK_NULL); diff --git a/src/hotspot/share/utilities/exceptions.cpp b/src/hotspot/share/utilities/exceptions.cpp index f730b37b8ff..10405a06048 100644 --- a/src/hotspot/share/utilities/exceptions.cpp +++ b/src/hotspot/share/utilities/exceptions.cpp @@ -288,7 +288,7 @@ void Exceptions::fthrow(JavaThread* thread, const char* file, int line, Symbol* // parameter controls a check for a specific character appearing in the "name", which is only // allowed for classfile versions <= 47. We pass `true` so that we allow such strings as this code // know nothing about the actual string content. - assert(UTF8::is_legal_utf8((const unsigned char*)msg, (int)strlen(msg), true), "must be"); + assert(UTF8::is_legal_utf8((const unsigned char*)msg, strlen(msg), true), "must be"); _throw_msg(thread, file, line, h_name, msg); } diff --git a/test/hotspot/jtreg/ProblemList.txt b/test/hotspot/jtreg/ProblemList.txt index 1b139063b5d..6ff3dec89a1 100644 --- a/test/hotspot/jtreg/ProblemList.txt +++ b/test/hotspot/jtreg/ProblemList.txt @@ -118,8 +118,6 @@ runtime/ErrorHandling/TestDwarf.java#checkDecoder 8305489 linux-all runtime/ErrorHandling/MachCodeFramesInErrorFile.java 8313315 linux-ppc64le runtime/Thread/TestAlwaysPreTouchStacks.java 8335167 macosx-aarch64 runtime/cds/appcds/customLoader/HelloCustom_JFR.java 8241075 linux-all,windows-x64 -runtime/exceptionMsgs/NoClassDefFoundError/NoClassDefFoundErrorTest.java 8339316 generic-all - applications/jcstress/copy.java 8229852 linux-all