Bug 91200 - invalid input will cause out of bounds heap read in function Hints::getPageObjectNum
Summary: invalid input will cause out of bounds heap read in function Hints::getPageOb...
Status: RESOLVED FIXED
Alias: None
Product: poppler
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: poppler-bugs
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-02 21:36 UTC by Hanno Böck
Modified: 2015-08-23 23:12 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments
sample input causing out of bounds access (1.78 KB, text/plain)
2015-07-02 21:36 UTC, Hanno Böck
Details
Fix bounds check in Linearization::getPageFirst (956 bytes, patch)
2015-08-23 22:13 UTC, Jason Crain
Details | Splinter Review

Description Hanno Böck 2015-07-02 21:36:27 UTC
Created attachment 116894 [details]
sample input causing out of bounds access

The attached file will cause an invalid read access in poppler. Can be tested with either address sanitizer or valgrind.

This is the address sanitizer output with pdftoppm:
==31074==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60200000fc74 at pc 0x0000008aaaaf bp 0x7fffdd7b1f00 sp 0x7fffdd7b1ef8
READ of size 4 at 0x60200000fc74 thread T0
    #0 0x8aaaae in Hints::getPageObjectNum(int) /f/poppler-0.33.0/poppler/Hints.cc:449:12
    #1 0x68807d in PDFDoc::parsePage(int) /f/poppler-0.33.0/poppler/PDFDoc.cc:1888:17
    #2 0x673518 in PDFDoc::getPage(int) /f/poppler-0.33.0/poppler/PDFDoc.cc:1929:27
    #3 0x522284 in PDFDoc::getPageMediaWidth(int) /f/poppler-0.33.0/utils/../poppler/PDFDoc.h:126:14
    #4 0x522284 in main /f/poppler-0.33.0/utils/pdftoppm.cc:492
    #5 0x7f9403dbdf9f in __libc_start_main /var/tmp/portage/sys-libs/glibc-2.20-r2/work/glibc-2.20/csu/libc-start.c:289
    #6 0x47a0cb in _start (/mnt/ram/poppler/pdftoppm+0x47a0cb)

0x60200000fc74 is located 0 bytes to the right of 4-byte region [0x60200000fc70,0x60200000fc74)
allocated by thread T0 here:
    #0 0x501092 in __interceptor_malloc (/mnt/ram/poppler/pdftoppm+0x501092)
    #1 0x708812 in gmalloc(unsigned long, bool) /f/poppler-0.33.0/goo/gmem.cc:110:13
    #2 0x708812 in gmallocn(int, int, bool) /f/poppler-0.33.0/goo/gmem.cc:192
    #3 0x708812 in gmallocn_checkoverflow /f/poppler-0.33.0/goo/gmem.cc:200

SUMMARY: AddressSanitizer: heap-buffer-overflow /f/poppler-0.33.0/poppler/Hints.cc:449 Hints::getPageObjectNum(int)
Shadow bytes around the buggy address:
  0x0c047fff9f30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9f40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9f50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9f60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x0c047fff9f70: fa fa fa fa fa fa fa fa fa fa 00 fa fa fa 04 fa
=>0x0c047fff9f80: fa fa 00 fa fa fa 04 fa fa fa 04 fa fa fa[04]fa
  0x0c047fff9f90: fa fa 04 fa fa fa 00 fa fa fa 04 fa fa fa 00 00
  0x0c047fff9fa0: fa fa 00 00 fa fa 01 fa fa fa 04 fa fa fa fd fa
  0x0c047fff9fb0: fa fa fd fa fa fa fd fa fa fa fd fa fa fa fd fa
  0x0c047fff9fc0: fa fa 05 fa fa fa fd fa fa fa fd fa fa fa fd fa
  0x0c047fff9fd0: fa fa fd fa fa fa fd fa fa fa 05 fa fa fa fd fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Heap right redzone:      fb
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack partial redzone:   f4
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==31074==ABORTING
Comment 1 Jason Crain 2015-08-23 22:13:43 UTC
Created attachment 117884 [details] [review]
Fix bounds check in Linearization::getPageFirst

This document has a linearization parameter dictionary in which the 'first page' parameter, /P, is equal to the total number of pages /N and is therefore out of bounds, and leads to Hints::getPageObjectNum having an out of bounds read.  The attached patch modified a bounds check to make sure pageFirst is within the interval [0, getNumPages).
Comment 2 Albert Astals Cid 2015-08-23 23:12:22 UTC
Pushed


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.