zippy1978 / ghost4j

Java wrapper for Ghostscript C API + PS/PDF document handling API
http://www.ghost4j.org
GNU Lesser General Public License v3.0
64 stars 38 forks source link

SIGSEGV (0xb) - libgs.so #37

Open jtyreman opened 9 years ago

jtyreman commented 9 years ago

using the following code:

    Ghostscript gs = Ghostscript.getInstance();

    try {
        synchronized (gs) {
            String[] gsArgs = new String[9];
            gsArgs[0] = "-psconv";
            gsArgs[1] = "-dNOPAUSE";
            gsArgs[2] = "-dBATCH";
            gsArgs[3] = "-dSAFER";
            gsArgs[4] = "-dAutoRotatePages=/None";
            gsArgs[5] = "-sDEVICE=ps2write";
            gsArgs[6] = "-sOutputFile=" + outputPath;
            gsArgs[7] = "-f";
            gsArgs[8] = pdfFile;

            gs.initialize(gsArgs);
            gs.exit();
        }
        //delete pdf as we no longer need this.
        pdf.delete();

    } catch (GhostscriptException e) {
        // TODO Auto-generated catch block
        System.out.println("Error 1 = " + e.getMessage());
    } finally {

        //delete interpreter instance (safer)
        try {
            Ghostscript.deleteInstance();
        } catch (GhostscriptException e) {
            //nothing
        }
        return outputPath;
    }

Causing a SIGSEGV (0xb) error

any suggestions as to why this may be?

Thanks

zippy1978 commented 9 years ago

Hi,

It seems to be related to your Ghostscript installation. Did you try to achieve the same operation with the GS command line ?

Regards, Gilles

lucguinchard commented 8 years ago

Hello,

I have the same problem, using the example code from Ghost4J project home page.

My program crashes with the following message. If needed I can provide more stacktrace output.


# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f6d75a9e9d8, pid=8818, tid=140109663655680
#
# JRE version: OpenJDK Runtime Environment (8.0_72-b15) (build 1.8.0_72-b15)
# Java VM: OpenJDK 64-Bit Server VM (25.72-b15 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# C  [libgs.so.9.14+0x1ae9d8]
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c #unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/luc/Documents/Java Project/AMGlassfish-root/BackFishManager/hs_err_pid8818.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.

Any help would be appreciated. Thanks,

Luc

4F2E4A2E commented 8 years ago

We are going to need more info on this in order to reproduce, which OS (the version matters) and which GS are you using? How are you running the code from the first comment?

lucguinchard commented 8 years ago

Here is a Maven project. (testGS.zip) I tested the execution of the program on two systems:

The problem is similar on both systems. Thanks,

4F2E4A2E commented 8 years ago

Hey there, i am about to run your code, please upload fichier.ps, thanks.

lucguinchard commented 8 years ago

Hey :) Since I have been testing some PS files pass, but not the other . In the zip Imprimante virtuel.zip, there are two files:

4F2E4A2E commented 8 years ago

There is alot of stuff wrong with your project, but since they are related to maven and java standards, i am going to skip that. i think i am able to reproduce that error on ubuntu with your fichierKO.ps file, which i think is corrupt, never the less it should lead to an total crash in the jvm since gs native command can convert it to pdf.

  1. install ghostscript on ubuntu and than create a symlinc like that: sudo ln -s /usr/lib/libgs.so.9 /usr/lib/libgs.so
  2. download the testGhost4jIssue37.zip project, unzip it, than run "mvn test"
  3. the juni ttest will try to convert every ps file inside the src/test/resources/test-data folder

As you can see in the log fichierOK.ps is beeing converted just fine, but as assumed fichierKO.ps is not: testGhost4jIssue37.zip

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestPsTopdf
PDF creation successful, here the file path: '/home/eduard/testGhost4jIssue37/src/test/resources/test-results/fichierOK.pdf'.
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007f1ff2a95717, pid=16591, tid=139775577265920
#
# JRE version: OpenJDK Runtime Environment (7.0_95) (build 1.7.0_95-b00)
# Java VM: OpenJDK 64-Bit Server VM (24.95-b01 mixed mode linux-amd64 compressed oops)
# Derivative: IcedTea 2.6.4
# Distribution: Ubuntu 14.04.3 LTS, package 7u95-2.6.4-0ubuntu0.14.04.1
# Problematic frame:
# C  [libgs.so+0x190717]
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /home/eduard/testGhost4jIssue37/hs_err_pid16591.log
#
# If you would like to submit a bug report, please include
# instructions on how to reproduce the bug and visit:
#   http://icedtea.classpath.org/bugzilla
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Aborted (core dumped)

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.211s
[INFO] Finished at: Sat Feb 13 23:07:26 CET 2016
[INFO] Final Memory: 16M/191M
[INFO] ------------------------------------------------------------------------

So i am assuming your .ps file is broken, it has more then 7K lines in it, never the less, i was not able to find a way to validate postscript files, so what i did is to basically try to convert it using gs natively Here the output converting the fichierOK.ps file using gs natively:

eduard@ubuntu:~$ gs   -o output.pdf   -sDEVICE=pdfwrite   -dPDFSETTINGS=/prepress   -dHaveTrueTypes=true   -dEmbedAllFonts=true   -dSubsetFonts=false   -c ".setpdfwrite <</NeverEmbed [ ]>> setdistillerparams"   -f /home/eduard/testGhost4jIssue37/src/test/resources/test-data/fichierOK.ps
GPL Ghostscript 9.10 (2013-08-30)
Copyright (C) 2013 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.

Here the output converting the fichierKO.ps file using gs natively:

eduard@ubuntu:~$ gs   -o output.pdf   -sDEVICE=pdfwrite   -dPDFSETTINGS=/prepress   -dHaveTrueTypes=true   -dEmbedAllFonts=true   -dSubsetFonts=false   -c ".setpdfwrite <</NeverEmbed [ ]>> setdistillerparams"   -f /home/eduard/testGhost4jIssue37/src/test/resources/test-data/fichierKO.ps
GPL Ghostscript 9.10 (2013-08-30)
Copyright (C) 2013 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Loading NimbusMonL-Regu font from /usr/share/fonts/type1/gsfonts/n022003l.pfb... 4365672 2758088 1994864 639743 1 done.
%%[ ProductName: GPL Ghostscript ]%%
%%[Page: 1]%%
%%[Page: 2]%%
%%[LastPage]%%
eduard@ubuntu:~$ 

@zippy1978 gs is not crashing, though the ps file is corrupt we should find a way in catching this fatal error. Should this be further investigated or do you have enough information for now?

P.s.: results and jvm crash log are inside the zip file.

cheers

lucguinchard commented 8 years ago

Thank you for your participation.

The solution I have adopted (also in first zip 'testGS.zip') is: I use the method ps2pdf

Runtime runtime = Runtime.getRuntime();
runtime.exec(new String[] { "ps2pdf", input.getAbsolutePath(), output.getAbsolutePath()} );

I also think it will be that the JVM does not crashing during the run.

4F2E4A2E commented 8 years ago

You are welcome. Well since you may have solved it with ps2pdf we can close this ticket right?

Am 26.02.2016 um 18:47 schrieb lucguinchard notifications@github.com:

Thank you for your participation.

The solution I have adopted (also in first zip 'testGS.zip') is: I use the method ps2pdf

Runtime runtime = Runtime.getRuntime(); runtime.exec(new String[] { "ps2pdf", input.getAbsolutePath(), output.getAbsolutePath()} ); I also think it will be that the JVM does not crashing during the run.

— Reply to this email directly or view it on GitHub.

lucguinchard commented 8 years ago

Hey, I'm sorry, the workaround does not resolve the application bug. It'll be good that it does not crash the JVM. I try to come back with more information. Thanks,

zippy1978 commented 8 years ago

Hi,

Could you tell me which version of Ghost4J is used for your test ?

For the native GS API / Java interaction, Ghost4J uses JNA. when a crash like this occurs, it's probably due to JNA.

The master branch uses a more recent version of JNA, did you use this one (1.0.1-SNAPSHOT) or the 1.0.0 version ?

Regards

4F2E4A2E commented 8 years ago

Hi there!

This error can be reproduced using GS Version 9 and Ghost4J Version 1.0.0 as you can see in this example project created: testGhost4jIssue37.zip

lucguinchard commented 3 years ago

Hello everyone,

I did a test today. I have the error:

org.ghost4j.converter.ConverterException: org.ghost4j.GhostscriptException: Cannot initialize Ghostscript interpreter. Error code is -100
    at org.ghost4j.converter.PDFConverter.run(PDFConverter.java:251)
    at org.ghost4j.converter.AbstractRemoteConverter.convert(AbstractRemoteConverter.java:85)
    at fr.amtrust.amtrustcommonghost4j.PSToPDF.Go(PSToPDF.java:32)
    at github.issue37.UnitTest.hello(UnitTest.java:46)
    at github.issue37.UnitTest.main(UnitTest.java:60)
Caused by: org.ghost4j.GhostscriptException: Cannot initialize Ghostscript interpreter. Error code is -100
    at org.ghost4j.Ghostscript.initialize(Ghostscript.java:365)
    at org.ghost4j.converter.PDFConverter.run(PDFConverter.java:231)

But the JVM is not crashed. The exception thrown is ConverterException.

this issue may be closed.

Luc