Bug 64271 - JVM crashes when we write XL file
Summary: JVM crashes when we write XL file
Status: RESOLVED INFORMATIONPROVIDED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-26 16:19 UTC by Girish Kumar
Modified: 2020-05-14 16:23 UTC (History)
0 users



Attachments
crash pid file (220.31 KB, text/plain)
2020-03-26 16:19 UTC, Girish Kumar
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Girish Kumar 2020-03-26 16:19:26 UTC
Created attachment 37127 [details]
crash pid file

We notice JVM crash occurring when we try to write workbook very rarely.

Code in summary would be as follows
OPCPackage opcPackage = OPCPackage.open(workbookFilename, PackageAccess.READ_WRITE);
    Workbook  workbook = new XSSFWorkbook(opcPackage);
    File tmpFile =  tmpFile = File.createTempFile(existingFile.getName(), ".tmp", new File("."));

    try (FileOutputStream fos = new FileOutputStream(tmpFile)) {
      workbook.write(fos);
    }


Details of the crash would be attached in the PID file
Comment 1 Girish Kumar 2020-03-26 16:28:33 UTC
Apache POI version - 3.15
Comment 2 Girish Kumar 2020-03-26 16:29:46 UTC
Apache POI version - 3.15
Comment 3 Axel Howind 2020-03-26 17:04:21 UTC
This does not look like a POI bug to me, but rather a JVM bug: 

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGBUS (0x7) at pc=0x00007ff613be8a32, pid=33123, tid=140691906696960
#
# JRE version: Java(TM) SE Runtime Environment (8.0_91-b14) (build 1.8.0_91-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.91-b14 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libzip.so+0x11a32]  newEntry+0x62
#

Please first update your Java installation to a more recent patch level of Java 8 (current for Java 8 is Java 8 Update 241 CPU) and report back if you can reproduce the crash.
Comment 4 Axel Howind 2020-03-26 17:24:23 UTC
BTW: I have seen bug reports JVM crashes with SIGBUS when creating temp files and there's not enough space left on the device. But these should have already been fixed even in your 4 year-old version of Java.

As a side note, the double assignment to `tmpFile` looks really weird (but it has nothing to do with the crash):

    File tmpFile =  tmpFile = File.createTempFile(existingFile.getName(), ".tmp", new File("."));
Comment 5 Girish Kumar 2020-03-26 17:29:22 UTC
Thanks for responding Axel.

double assignment of tmp is my mistake while copy and paste and formatting.

Also I see another bug link which is close to crash location

https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8186557 and they recommend disabling memory mapping. Not sure whether that would help.


Also see another stack overflow message, which talks about WorkBookFactory 

https://stackoverflow.com/questions/11344131/jvm-crashing-while-writing-to-xlsx-file-poi/17329250
Comment 6 Nick Burch 2020-03-26 20:22:18 UTC
Java programs shouldn't be able to crash the JVM.

I think you'll need to report this to Oracle or OpenJDK (depending on which JDK you use)
Comment 7 Axel Howind 2020-03-27 03:40:22 UTC
A little info I copied from https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8233188 :

> Historically, native crashes in
> java.util.zip.ZipFile::getNextEntry
> were invariably due to the zip file being overwritten while running. (DON'T DO THAT)
> In recent jdks, I think this was addressed by moving the native code into java (and not using mmap).

Since the bug seems to be within the JDK, and should be fixed in more recent versions, you should first update your JDK 8 and see if you can reproduce the crash. Alternatively disable mmap or make sure files are not changed/moved/deleted while writing the workbook.
Comment 8 Dominik Stadler 2020-05-14 16:23:29 UTC
This seems to be a problem in the JDK itself, so there is nothing that we can fix in Apache POI as far as I see, thus I am closing this for now.