Here is revised patch.
The code issuing error messages are harmonized to the surrounding code,
so there are inconsistency (some use error(), other uses fprintf()).
If further work (or better wording) is needed, I will do.
Please comment.
Regards,
mpsuzuki
suzuki toshiya wrote:
> Albert Astals Cid wrote:
>>> If endDocument() is invoked without beginDocument(), uninitialized
>>> surface and output_file are referred, therefore, SEGV is caused.
>>>
>>> The easiest fix would be NULL-initialization (not needed in C++?) of
>>> surface & output_file, and checking NULL before referring them in
>>> endDocument(). Patch is attached.
>> I'd prefer an if check for lastPage < firstPage that tells the user to not
>> give the program bad parameters. Can you work on that?
>
> OK, I will do so. Although SEGV does not occur, other utilities
> (e.g. pdftotext, pdftoppm, pdftops etc) do not check such. I will
> make a patchset for all pdftoXXX utilities.
>
>> Cheers.
>> Albert
>>
>>> Regards,
>>> mpsuzuki
>
> _______________________________________________
> poppler mailing list
> [email protected]
> http://lists.freedesktop.org/mailman/listinfo/poppler
diff --git a/utils/pdffonts.cc b/utils/pdffonts.cc
index 820abbf..2812957 100644
--- a/utils/pdffonts.cc
+++ b/utils/pdffonts.cc
@@ -150,6 +150,12 @@ int main(int argc, char *argv[]) {
if (lastPage < 1 || lastPage > doc->getNumPages()) {
lastPage = doc->getNumPages();
}
+ if (lastPage < firstPage) {
+ fprintf(stderr,
+ "Wrong page range is given: the last page %d must be after the first page %d.\n",
+ lastPage, firstPage);
+ goto err1;
+ }
// get the fonts
{
diff --git a/utils/pdfimages.cc b/utils/pdfimages.cc
index 82c301c..eb6b9ce 100644
--- a/utils/pdfimages.cc
+++ b/utils/pdfimages.cc
@@ -166,6 +166,12 @@ int main(int argc, char *argv[]) {
firstPage = 1;
if (lastPage < 1 || lastPage > doc->getNumPages())
lastPage = doc->getNumPages();
+ if (lastPage < firstPage) {
+ error(errCommandLine, -1,
+ "Wrong page range is given: the last page {0:d} must be after the first page {1:d}.",
+ lastPage, firstPage);
+ goto err1;
+ }
// write image files
imgOut = new ImageOutputDev(imgRoot, pageNames, dumpJPEG, listImages);
diff --git a/utils/pdfinfo.cc b/utils/pdfinfo.cc
index 14e4f6c..34bea2d 100644
--- a/utils/pdfinfo.cc
+++ b/utils/pdfinfo.cc
@@ -202,6 +202,12 @@ int main(int argc, char *argv[]) {
if (lastPage < 1 || lastPage > doc->getNumPages()) {
lastPage = doc->getNumPages();
}
+ if (lastPage < firstPage) {
+ error(errCommandLine, -1,
+ "Wrong page range is given: the last page {0:d} must be after the first page {1:d}.",
+ lastPage, firstPage);
+ goto err2;
+ }
// print doc info
doc->getDocInfo(&info);
diff --git a/utils/pdfseparate.cc b/utils/pdfseparate.cc
index d7efcf0..d878818 100644
--- a/utils/pdfseparate.cc
+++ b/utils/pdfseparate.cc
@@ -63,6 +63,12 @@ bool extractPages (const char *srcFileName, const char *destFileName) {
lastPage = doc->getNumPages();
if (firstPage == 0)
firstPage = 1;
+ if (lastPage < firstPage) {
+ error(errCommandLine, -1,
+ "Wrong page range is given: the last page {0:d} must be after the first page {1:d}.",
+ lastPage, firstPage);
+ return false;
+ }
if (firstPage != lastPage && strstr(destFileName, "%d") == NULL) {
error(errSyntaxError, -1, "'{0:s}' must contain '%d' if more than one page should be extracted", destFileName);
return false;
diff --git a/utils/pdftocairo.cc b/utils/pdftocairo.cc
index e1fb258..0f46c0f 100644
--- a/utils/pdftocairo.cc
+++ b/utils/pdftocairo.cc
@@ -964,6 +964,12 @@ int main(int argc, char *argv[]) {
if (lastPage < 1 || lastPage > doc->getNumPages())
lastPage = doc->getNumPages();
+ if (lastPage < firstPage) {
+ fprintf(stderr,
+ "Wrong page range is given: the last page %d must be after the first page %d.\n",
+ lastPage, firstPage);
+ exit(99);
+ }
if (eps && firstPage != lastPage) {
fprintf(stderr, "EPS files can only contain one page.\n");
exit(99);
diff --git a/utils/pdftohtml.cc b/utils/pdftohtml.cc
index bcec8cb..4496d9e 100644
--- a/utils/pdftohtml.cc
+++ b/utils/pdftohtml.cc
@@ -322,6 +322,12 @@ int main(int argc, char *argv[]) {
firstPage = 1;
if (lastPage < 1 || lastPage > doc->getNumPages())
lastPage = doc->getNumPages();
+ if (lastPage < firstPage) {
+ error(errCommandLine, -1,
+ "Wrong page range is given: the last page {0:d} must be after the first page {1:d}.",
+ lastPage, firstPage);
+ goto error;
+ }
doc->getDocInfo(&info);
if (info.isDict()) {
diff --git a/utils/pdftoppm.cc b/utils/pdftoppm.cc
index 73f337c..6edea04 100644
--- a/utils/pdftoppm.cc
+++ b/utils/pdftoppm.cc
@@ -412,6 +412,12 @@ int main(int argc, char *argv[]) {
lastPage = firstPage;
if (lastPage < 1 || lastPage > doc->getNumPages())
lastPage = doc->getNumPages();
+ if (lastPage < firstPage) {
+ fprintf(stderr,
+ "Wrong page range is given: the last page %d must be after the first page %d.\n",
+ lastPage, firstPage);
+ goto err1;
+ }
if (singleFile && firstPage < lastPage) {
if (!quiet) {
diff --git a/utils/pdftops.cc b/utils/pdftops.cc
index 7f5a0ce..06847a7 100644
--- a/utils/pdftops.cc
+++ b/utils/pdftops.cc
@@ -380,6 +380,12 @@ int main(int argc, char *argv[]) {
if (lastPage < 1 || lastPage > doc->getNumPages()) {
lastPage = doc->getNumPages();
}
+ if (lastPage < firstPage) {
+ error(errCommandLine, -1,
+ "Wrong page range is given: the last page {0:d} must be after the first page {1:d}.",
+ lastPage, firstPage);
+ goto err2;
+ }
// check for multi-page EPS or form
if ((doEPS || doForm) && firstPage != lastPage) {
diff --git a/utils/pdftotext.cc b/utils/pdftotext.cc
index bd687ec..fcce517 100644
--- a/utils/pdftotext.cc
+++ b/utils/pdftotext.cc
@@ -290,6 +290,12 @@ int main(int argc, char *argv[]) {
if (lastPage < 1 || lastPage > doc->getNumPages()) {
lastPage = doc->getNumPages();
}
+ if (lastPage < firstPage) {
+ error(errCommandLine, -1,
+ "Wrong page range is given: the last page {0:d} must be after the first page {1:d}.",
+ lastPage, firstPage);
+ goto err3;
+ }
// write HTML header
if (htmlMeta) {
_______________________________________________
poppler mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/poppler