Subject: | problems found handling some PDF files - here is a possible solution to the issues I found. |
Date: | Wed, 1 Aug 2012 18:35:35 -0400 |
To: | "bug-CAM-PDF [...] rt.cpan.org" <bug-CAM-PDF [...] rt.cpan.org> |
From: | Martin Smoot <msmoot [...] infoplanning.com> |
testing a program using this package found several problems in the CAM-PDF-1.58 download in the CAM/PDF.pm file. in case the line numbers are not right for some reason I have tried to include some of the surrounding code.
1. I was getting undefined warnings in this block of code in sub _buildxref_pdf15:
for my $key (qw(type major minor)) {
$w += shift @w;
if ($w > $pos) {
my $val = 0;
for (; $pos < $w; ++$pos) { ## no critic (ProhibitCStyleForLoops)
$val = ($val << 8) + $byte[$pos] if defined $byte[$pos]; # added if defined
}
$values{$key} = $val;
}
}
so I added the "if defined" that was noted and the warnings went away.
2. I was getting a complaint about data outside of string for the substr call in the same routine so I changed the code just a few lines above the above block of code:
original code was:
my @byte = unpack 'C*', substr $stream, $i++ * $entry_size, $entry_size;
code was modified to be:
my @byte;
my $strlen=length $stream;
if(($i * $entry_size) <= $strlen)
{
@byte = unpack 'C*', substr $stream, $i * $entry_size, $entry_size;
}
$i++;
3. for some reason some of the PDF files that were tested were identified as Version 1.3 files had an offset slightly off but I found that if I changed the start of this code in _buildxref then the problem was corrected. I do not know if the offset was off because of bad data or some other code issue.
sub _buildxref
{
my $self = shift;
my $startxref = shift;
my $index = shift;
my $versions = shift;
my $objstreamrefs = shift;
my $trailer;
#
# this is the block of code that was added - found that the $startxref position was off by one for some reason
#
my $stuff=substr $self->{content}, $startxref, 1;
if($stuff eq "\n")
{
$startxref++;
#fordebug#print __LINE__," $self->{pdfversion} - position was off a little\n";
}
4. I found that it was helpful to change all of the "die" statements to include the line number:
die __LINE__." " . "...................whatever the message was...."
so that I could quickly determine where the error came from (the error I got in one case could occur in 2 different locations).
Show quoted text
________________________________
This message is private and confidential. If you have received this message in error, please notify us by replying to this email and then delete it from your system. Thank you for your cooperation. Information Planning & Management Service, Inc.
Message body is not shown because it is too large.