Bug 693934 - Attached PDF file causes a segfault
Summary: Attached PDF file causes a segfault
Status: RESOLVED FIXED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: PDF Interpreter (show other bugs)
Version: 9.07
Hardware: PC Linux
: P4 major
Assignee: Chris Liddell (chrisl)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-25 06:30 UTC by Till Kamppeter
Modified: 2013-06-19 16:32 UTC (History)
0 users

See Also:
Customer:
Word Size: ---


Attachments
page.pdf (57.33 KB, application/pdf)
2013-04-25 06:30 UTC, Till Kamppeter
Details
just a thought that might help...... (1.45 KB, patch)
2013-04-25 09:05 UTC, Chris Liddell (chrisl)
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Till Kamppeter 2013-04-25 06:30:48 UTC
Created attachment 9589 [details]
page.pdf

Original bug report:

https://bugs.launchpad.net/ubuntu/+source/ghostscript/+bug/1172571

The attached file causes Ghostscript 9.07 (and also 9.05) to segfault with the following command line:

gs -dBATCH -dNOPAUSE -o page.png -sDEVICE=pngmono page.pdf
Comment 1 Till Kamppeter 2013-04-25 07:16:35 UTC
There is a Valgrind log posted on the Ubuntu bug report.
Comment 2 Chris Liddell (chrisl) 2013-04-25 09:05:11 UTC
Created attachment 9590 [details]
just a thought that might help......

In order to reproduce this in the master code, you need to build with -DGS_USE_MEMORY_HEADER_ID=0 in your CFLAGS (the memory ID code "hides" the problem).

The memory header is being corrupted by the "invert_data()" macro in cf_decode_2d(). During decoding, we get a run length of "-2" in a part of the code where negative run lengths are not catered for, we then try to invert that number of bytes - hence zapping the memory header.

The negative run length happens around line 732 in scfd.c, from the line:
hwb:get_run(cf_black_decode, cfd_black_initial_bits, cfd_black_min_bits,

The following invert_data() call corrupts the header.

The patch attached *seems* to work, but is a bit of a stab in the dark (I think we should get rid of the get_run() macro, and make it a function!) - I'll defer to Alex on whether it's useful.

Till, please don't consider using this patch until Alex has a chance to investigate.
Comment 3 Till Kamppeter 2013-04-25 18:46:28 UTC
Chris, the original reporter of the Ubuntu bug has tested your patch and it seems to fix the problem for him.
Comment 4 Ken Sharp 2013-06-12 09:13:40 UTC
Passing this one back to Chris since he did some work on it. Looks to me like th best solution is to adopt his patch.
Comment 5 Chris Liddell (chrisl) 2013-06-19 16:32:36 UTC
Patch applied in:

http://git.ghostscript.com/?p=ghostpdl.git;a=commitdiff;h=f1b0e276