Bug 101149 - [pdfunite] crash when parsing a crafted pdf due to null pointer deference in ~/utils/pdfunite.cc:357
Summary: [pdfunite] crash when parsing a crafted pdf due to null pointer deference in ...
Status: RESOLVED FIXED
Alias: None
Product: poppler
Classification: Unclassified
Component: utils (show other bugs)
Version: unspecified
Hardware: x86-64 (AMD64) Linux (All)
: medium normal
Assignee: poppler-bugs
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-05-23 03:57 UTC by Jiaqi Peng
Modified: 2017-05-26 22:10 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Jiaqi Peng 2017-05-23 03:57:40 UTC
## Summary
pdfunite util in poppler-0.55.0 will crash when parsing a crafted pdf file due to null pointer deference in main()@~/utils/pdfunite.cc:357


## Reprocude
openstack@openstack-virtual-machine:~/pjq/poppler-0.55.0/build-gcc/utils$ ./pdfunite null_pointer_deference_poc.pdf 1.pdf
Syntax Error (224): Dictionary key must be a name object
Syntax Error (226): Dictionary key must be a name object
Syntax Error (230): Dictionary key must be a name object
Syntax Error (232): Dictionary key must be a name object
Syntax Error (241): Dictionary key must be a name object
Syntax Error: Kid object (page 1) is wrong type (stream)
Segmentation fault


## Crash Stack
Program received signal SIGSEGV, Segmentation fault.
main (argc=3, argv=<optimized out>) at ../../poppler/Page.h:156
156       GBool isCropped() { return attrs->isCropped(); }
(gdb) bt
#0  main (argc=3, argv=<optimized out>) at ../../poppler/Page.h:156


## Analysis
in ~/utils/pdfunite.cc:357
354   for (i = 0; i < (int) docs.size(); i++) {
355     for (j = 1; j <= docs[i]->getNumPages(); j++) {
356       PDFRectangle *cropBox = NULL;
357       if (docs[i]->getCatalog()->getPage(j)->isCropped())

Here, the value of "docs[i]->getCatalog()->getPage(j)" is zero, then isCropped() will deference a null pointer, which causes crash.


in ~/poppler/Catalog.cc:243
 235 Page *Catalog::getPage(int i)
 236 {
 237   if (i < 1) return NULL;
 238 
 239   catalogLocker();
 240   if (i > lastCachedPage) {
 241      GBool cached = cachePageTree(i);
 242      if ( cached == gFalse) {
 243        return NULL;
 244      }
 245   }
 246   return pages[i-1];
 247 }
Here, Catalog.cc:getPage() will return NULL in line 243, which causes the address to deference above to be zero.


## Patch
In ~/utils/pdfunite.cc:357, before calling isCropped(), first check the return value of getPage(j) is zero or not.


## Author
name: Jiaqi Peng
email: pjqruc@gmail.com (if you need poc, contact me via email)
Comment 1 Albert Astals Cid 2017-05-23 19:22:38 UTC
Please provide the file
Comment 2 Jiaqi Peng 2017-05-24 01:52:12 UTC
(In reply to Albert Astals Cid from comment #1)
> Please provide the file

I have send the two PoC files to your mailbox.
Comment 3 Albert Astals Cid 2017-05-26 22:10:54 UTC
Fixed, thanks


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.