NickNaso / ghostscript4js

Ghostscript4JS binds the Ghostscript C API to the Node.JS world.
http://www.nacios.it
Apache License 2.0
66 stars 19 forks source link

Segmentation fault on multiple runs #47

Closed hamzashezad closed 4 years ago

hamzashezad commented 4 years ago

OS: macOS 10.14.5 Node version: 10.15.3 Ghostscript version: 9.27 (2019-04-04) Electron version: 5.0.7 Ghostscript4js version: 3.1.1

I am converting postscript files to text files using the following:

gs.executeSync("-sDEVICE=txtwrite -dNOPAUSE -dQUIET -dBATCH \
    -sOutputFile=output.txt -sDEVICE=txtwrite input.ps");

It works the first time but my electron application crashes when I try to convert a second file.

The command runs fine on bash but gives a segmentation fault when I run it on Node REPL:

> const gs = require("ghostscript4js")
undefined
> gs.executeSync("-sDEVICE=txtwrite -dNOPAUSE -dQUIET -dBATCH -sOutputFile=job1.txt -sDEVICE=txtwrite job-1.ps")
undefined
> gs.executeSync("-sDEVICE=txtwrite -dNOPAUSE -dQUIET -dBATCH -sOutputFile=job2.txt -sDEVICE=txtwrite job-1.ps")
[1]    70491 segmentation fault  node

Note job2.txt was not created and it crashed after with a segmentation fault.

BoxSo commented 4 years ago

I see this happening on windows 10 with ghostscript 9.27 too. Also updated Ghostscript to 9.50 and reinstalled ghostscript4js package without success. First run works like a charm, second run crashes app without any feedback.

console.log(gs.MIN_SUPPORTED_REVISION);
console.log(gs.MAX_SUPPORTED_REVISION);
gs.execute(param_ghostscript)
            .then(() => {
              // Ghostscript returned successfully
              logger.info(svcName + ' | Successfully converted PDF to PNG');
            }.catch((err) => {
              // Error in ghostscript execution
              logger.error(svcName + ' | Error converting PDF document to OCR readbable format: ' + err);
            });

the catch-path is not executed at the second run. The whole process seems to die without any feedback.

Node Version 10.16.3

GautierT commented 4 years ago

Same problem. first run is okay second run crash the app without any feedback. Ghostscript.version() :

{
  product: 'GPL Ghostscript',
  copyright: 'Copyright (C) 2019 Artifex Software, Inc.  All rights reserved.',
  revision: 950,
  revisiondate: 20191015
}
GautierT commented 4 years ago

Hi @NickNaso Do you have an idea how to fix this ? Or how to downgrade to 9.22 on macos (installed from brew) ? I have only one version in /usr/local/Cellar/ghostscript/ and it's 9.50.

Thanks !

luco commented 4 years ago

+1 on this on mac. On the second run it gives me [1] 89399 segmentation fault node --inspect index.js

@NickNaso thoughts?

EDIT

I manage it to work by using exec instead of ghostscript4js:

 exec(`gs -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite -sColorConversionStrategy=CMYK -sOutputFile=${outputFront.path} ${tmpFront.path} && gs -dBATCH -dNOPAUSE -dNOCACHE -sDEVICE=pdfwrite -sColorConversionStrategy=CMYK -sOutputFile=${outputBack.path} ${tmpBack.path}`, async (err, stdout, stderr) => {
NickNaso commented 4 years ago

Hi everybody, I'm closing the issue because the release 3.2.0 should solve the problem.