Silent error on parse semi-transparent content

Aperta
#157 6 commenti 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
28/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
javascript
Ambito
backend

Direzione di ricerca

Riproduci il problema con Declaration.pdf o con il comando pdf2json.js mostrato nell’issue, quindi esamina /base/core/jpg.js intorno alle righe 832-833 e il percorso di gestione di pdfParser_dataError. Verifica come vengono gestiti i JPEG a quattro componenti e assicurati che l’analisi riporti un errore utile o venga completata senza interrompersi silenziosamente; esegui nuovamente il test sul documento segnalato e sul comando di esempio esistente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Hello, recently I found bug with parsing some .pdf files. If file have symbols colored in semi-transparent color, a program just stops without any error messages. Here's code which stops silent (declaration.pdf - "unparsable" document):

let fs = require('fs'),
    PDFParser = require("pdf2json");

let pdfParser = new PDFParser(this, 1);

pdfParser.on("pdfParser_dataError", errData => console.error(errData.parserError) );
pdfParser.on("pdfParser_dataReady", pdfData => {
    fs.writeFile("./content.txt", pdfParser.getRawTextContent());
});

pdfParser.loadPDF("./Declaration.pdf");

So, after I tried to parse document directly with pdf2json:
node pdf2json.js "../../documents/whitepaper/47/WP_En.pdf" "../../"
And I got some errors:

Warning: Unhandled rejection: Error: JPEG error: Unsupported color mode (4 components)
Error: JPEG error: Unsupported color mode (4 components)
    at error (eval at <anonymous> (app\node_modules\pdf2json\lib\pdf.js:64:1), <anonymous>:195:9)
    at JpegStream_ensureBuffer [as ensureBuffer] (eval at <anonymous> (app\node_modules\pdf2json\lib\pdf.js:64:1), <anonymous>:25571:7)
    at JpegStream.DecodeStream_getBytes [as getBytes] (eval at <anonymous> (app\node_modules\pdf2json\lib\pdf.js:64:1), <anonymous>:24875:14)
    at PDFImage_getImageBytes [as getImageBytes] (eval at <anonymous> (app\node_modules\pdf2json\lib\pdf.js:64:1), <anonymous>:21009:25)
    at PDFImage_fillRgbaBuffer [as fillRgbaBuffer] (eval at <anonymous> (app\node_modules\pdf2json\lib\pdf.js:64:1), <anonymous>:20941:27)
    at PDFImage_getImageData [as getImageData] (eval at <anonymous> (app\node_modules\pdf2json\lib\pdf.js:64:1), <anonymous>:21004:12)
    at eval (eval at <anonymous> (app\node_modules\pdf2json\lib\pdf.js:64:1), <anonymous>:7125:34)
    at Object.eval [as onResolve] (eval at <anonymous> (app\node_modules\pdf2json\lib\pdf.js:64:1), <anonymous>:20657:7)
    at Object.runHandlers (eval at <anonymous> (app\node_modules\pdf2json\lib\pdf.js:64:1), <anonymous>:864:35)
    at ontimeout (timers.js:466:11)

In a nutshell, my solution was to comment 2 lines(832-833) in /base/core/jpg.js:

if (!this.adobe)
    throw 'Unsupported color mode (4 components)';

After that I successfully parsed my document.

So, @modesty, can you fix this or just remove?

Lingua principale
Java
Stelle
2.2k
Fork
396
Merge medio
9g 19h
PR unite (30g)
3

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di modesty/pdf2json

Tutte le issue di modesty/pdf2json

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.