StackWalker can crash the JVM
Luke Hutchison
luke.hutch at gmail.com
Tue Apr 30 08:25:37 UTC 2019
I received a bug report that my library ClassGraph crashes the JVM:
https://github.com/classgraph/classgraph/issues/341
The top few stack frames are
V [libjvm.dylib+0x65ca9b] ResolvedMethodTable::add_method(Handle)+0x61
V [libjvm.dylib+0x4eabf5] CallInfo::set_resolved_method_name(Thread*)+0x5d
V [libjvm.dylib+0x4eaaf7] CallInfo::CallInfo(Method*, Klass*, Thread*)+0x1c5
V [libjvm.dylib+0x3a95e5]
java_lang_StackFrameInfo::set_method_and_bci(Handle, methodHandle
const&, int, Thread*)+0x7f
V [libjvm.dylib+0x68f6f0] StackWalk::fill_in_frames(long,
BaseFrameStream&, int, int, objArrayHandle, int&, Thread*)+0x252
V [libjvm.dylib+0x6907d3] StackWalk::fetchNextBatch(Handle, long,
long, int, int, objArrayHandle, Thread*)+0xd9
V [libjvm.dylib+0x417264] JVM_MoreStackWalk+0x12f
j java.lang.StackStreamFactory$AbstractStackWalker.fetchStackFrames(JJII[Ljava/lang/Object;)I+0
java.base at 11.0.3
j java.lang.StackStreamFactory$AbstractStackWalker.fetchStackFrames(I)I+35
java.base at 11.0.3
Here is the class that calls into StackWalker, in method
getCallStackViaStackWalker() (it uses reflection to ensure the code is
backwards compatible with JDK 7/8):
https://github.com/classgraph/classgraph/blob/master/src/main/java/nonapi/io/github/classgraph/classpath/CallStackReader.java
This code works as intended most of the time, so I don't know what is
different about the reporting user's environment that triggers this crash.
It is possible that ClassGraph is somehow calling StackWalker wrongly in
some circumstances (if so, please let me know what I'm doing wrong) --
however, I am reporting the problem here, because I assume that non-native
code should never be able to crash the JVM.
Thank you,
Luke Hutchison
More information about the jdk-dev
mailing list