Subject: | Unable to parse '/' as Name |
Date: | Fri, 25 Sep 2015 16:01:51 -0500 |
To: | bug-PDF-API2 [...] rt.cpan.org |
From: | "Mark Balitsky" <mark [...] ghy.com> |
I've recently encountered some PDF files which have failed to parse with
PDF::API2. The problem was due to an entry in an image dictionary which
used the value '/' as a Name, e.g. :
4 0 obj
<<
/DecodeParms [
<<
/Colors 1
/Rows 3300
/Columns 2550
/K -1
Show quoted text
>>]
/Width 2550
/BitsPerComponent 1
/Name /XImg
/Height 3300
/Intent /
/Filter [/CCITTFaxDecode]
/Subtype /Image
/Length 23634
/Type /XObject
/ColorSpace /DeviceGray
Show quoted text>>
The attempt to read the dictionary crashes with:
Can't parse `/
/Filter [/CCITTFaxDecode]
/Subtype /Image
(etc...)
I first noticed this with PDF::API2 version 2.019, then verified it is
still present in 2.024.
As a workaround, I've made the following change in Basic/PDF/File.pm, in
sub readval, between lines 550-555 (ver. 2.024):
from:
# Name
elsif ($str =~ m|^/($reg_char+)|s) {
$value = $1;
$str =~ s|^/($reg_char+)||s;
$result = PDF::API2::Basic::PDF::Name->from_pdf($value, $self);
}
to:
# Name
elsif ($str =~ m|^/($reg_char*)|s) {
$value = $1;
$str =~ s|^/($reg_char*)||s;
$result = PDF::API2::Basic::PDF::Name->from_pdf($value, $self);
}
This successfully consumes the '/' token without crashing.
--
Mark Balitsky
I.T. Department
GHY International
809-167 Lombard Avenue
Winnipeg, MB, R3B 3H8, Canada
------------------------------
web: http://www.ghy.com
Main Phone: (204) 947-6851
Fax: (204) 947-3306