JVM crash from java.util.zip.ZipFile.open() in libzip readCEN

Solution Unverified - Updated

Environment

  • Red Hat Enterprise Linux
  • Red Hat build of OpenJKD8 u342

Issue

The JVM crashes with the following in the fatal error log:

#  SIGBUS (0x7) at pc=0x00007f75f5bb8c59, pid=122363, tid=0x00007f758d260700
#
# JRE version: OpenJDK Runtime Environment (8.0_342-b07) (build 1.8.0_342-b07)
# Java VM: OpenJDK 64-Bit Server VM (25.342-b07 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libzip.so+0x4c59]  readCEN+0x8e9
...
siginfo: si_signo: 7 (SIGBUS), si_code: 2 (BUS_ADRERR), si_addr: 0x00007f75c074e114
...
Stack: [0x00007f758d160000,0x00007f758d261000],  sp=0x00007f758d25eba0,  free space=1018k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [libzip.so+0x4c59]  readCEN+0x8e9
C  [libzip.so+0x5eb0]  ZIP_Put_In_Cache0+0x120
C  [libzip.so+0x3b77]  Java_java_util_zip_ZipFile_open+0xf7
J 1514  java.util.zip.ZipFile.open(Ljava/lang/String;IJZ)J (0 bytes) @ 0x00007f75e151c112 [0x00007f75e151c040+0xd2]
J 11345 C2 java.util.zip.ZipFile.<init>(Ljava/io/File;ILjava/nio/charset/Charset;)V (223 bytes) @ 0x00007f75e305f5ec [0x00007f75e305edc0+0x82c]

Resolution

Address the application or operations use case resulting in the zipped file being modified/overwritten outside of the current thread, or work around the issue by disabling memory mapping in ZipFile with -Dsun.zip.disableMemoryMapping=true (at the cost of some loss in performance) or upgrade to JDK 11.

Root Cause

An application or operations use case resulting in the zipped xml file being modified/overwritten outside of the current thread.

The following issue details the change in JDK9+ to address the mmap crash risk in JDK8:
Content from bugs.openjdk.org is not included.To bring j.u.z.ZipFile's native implementation to Java to remove the expensive jni cost and mmap crash risk


This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.