diff options
author | Carlos Garcia Campos <carlosgc@gnome.org> | 2009-04-19 15:47:01 +0200 |
---|---|---|
committer | Carlos Garcia Campos <carlosgc@gnome.org> | 2009-04-19 15:47:01 +0200 |
commit | 42df22b63cafbb4f7f9aa1e3ddc4df61a71a072b (patch) | |
tree | 0ec08cac7da7e10cd043e2d134aa6da8f797ef07 | |
parent | 38d9d955cf7a6baed877331d60837d9ce1b853c3 (diff) |
Improve detection of invalid PS files
A document scanned without errors with no pages and no format is likely
to be an invalid file, or not a PostScript file at all. Since this
cannot be detected by the scanner, in this particular case, we try to
render the document to set SPECTRE_STATUS_LOAD_ERROR in case it fails to
render. Fixes bug #19042.
-rw-r--r-- | libspectre/spectre-document.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/libspectre/spectre-document.c b/libspectre/spectre-document.c index 9fef951..6dde48b 100644 --- a/libspectre/spectre-document.c +++ b/libspectre/spectre-document.c @@ -69,7 +69,6 @@ spectre_document_load (SpectreDocument *document, document->doc = psscan (filename, SCANSTYLE_NORMAL); if (!document->doc) { - /* FIXME: OOM | INVALID_PS */ document->status = SPECTRE_STATUS_LOAD_ERROR; return; } @@ -80,6 +79,21 @@ spectre_document_load (SpectreDocument *document, document->doc = NULL; return; + } else if (document->doc->numpages == 0 && !document->doc->format) { + /* Make sure it's a valid PS document */ + unsigned char *data = NULL; + int row_length; + + spectre_document_render (document, &data, &row_length); + free (data); + + if (spectre_document_status (document)) { + document->status = SPECTRE_STATUS_LOAD_ERROR; + psdocdestroy (document->doc); + document->doc = NULL; + + return; + } } document->structured = ((!document->doc->epsf && document->doc->numpages > 0) || |