update to p5-PDF-API2-2.027

This commit is contained in:
sthen 2016-03-16 00:17:01 +00:00
parent e8c6e70e82
commit f044f8f774
5 changed files with 6 additions and 279 deletions

View File

@ -1,11 +1,10 @@
# $OpenBSD: Makefile,v 1.15 2016/03/09 23:35:32 sthen Exp $
# $OpenBSD: Makefile,v 1.16 2016/03/16 00:17:01 sthen Exp $
COMMENT = create PDF documents with perl
MODULES = cpan
DISTNAME = PDF-API2-2.026
REVISION = 2
DISTNAME = PDF-API2-2.027
CATEGORIES = textproc
MAINTAINER = Stuart Henderson <sthen@openbsd.org>

View File

@ -1,2 +1,2 @@
SHA256 (PDF-API2-2.026.tar.gz) = 9Jpmyv/5oqgrXHLA3CZj/W8wXTatM7ciyYxZ+yELkYQ=
SIZE (PDF-API2-2.026.tar.gz) = 3498117
SHA256 (PDF-API2-2.027.tar.gz) = 0k2wLZAhmEBicFUYV4MGM7KJrTn1qbpUMSRvjNYOdZk=
SIZE (PDF-API2-2.027.tar.gz) = 3500950

View File

@ -1,142 +0,0 @@
$OpenBSD: patch-lib_PDF_API2_Basic_PDF_File_pm,v 1.1 2016/03/05 11:04:22 sthen Exp $
Fixes to cross-reference stream handling from upstream git.
https://github.com/ssimms/pdfapi2/commits/master/lib/PDF/API2/Basic/PDF/File.pm
--- lib/PDF/API2/Basic/PDF/File.pm.orig Sat Mar 5 10:45:30 2016
+++ lib/PDF/API2/Basic/PDF/File.pm Sat Mar 5 10:45:18 2016
@@ -255,6 +255,7 @@ sub open {
die "Malformed PDF file $filename";
}
my $xpos = $1;
+ $self->{' xref_position'} = $xpos;
my $tdict = $self->readxrtr($xpos, $self);
foreach my $key (keys %$tdict) {
@@ -455,8 +456,11 @@ sub readval {
my ($result, $value);
my $update = defined($opts{update}) ? $opts{update} : 1;
- $str = update($fh, $str) if $update;
+ $str = update($fh, $str);
+ $str =~ s/^$ws_char+//; # Ignore initial white space
+ $str =~ s/^\%[^\015\012]*$ws_char+//; # Ignore comments
+
# Dictionary
if ($str =~ m/^<</s) {
$str = substr ($str, 2);
@@ -464,7 +468,10 @@ sub readval {
$result = PDFDict();
while ($str !~ m/^>>/) {
- if ($str =~ s|^/($reg_char+)$ws_char?||) {
+ $str =~ s/^$ws_char+//; # Ignore initial white space
+ $str =~ s/^\%[^\015\012]*$ws_char+//; # Ignore comments
+
+ if ($str =~ s|^/($reg_char+)||) {
my $key = PDF::API2::Basic::PDF::Name::name_to_string($1, $self);
($value, $str) = $self->readval($str, %opts);
$result->{$key} = $value;
@@ -489,7 +496,13 @@ sub readval {
my $length = $result->{'Length'}->val;
$result->{' streamsrc'} = $fh;
$result->{' streamloc'} = $fh->tell - length($str);
- $result->{' streamloc'}-- if $fh->eof;
+
+ # The following line was added as part of the initial XRef Stream patch, but it breaks
+ # streams that are near the end of a file (starting the stream one byte early, resulting
+ # in corruption).
+ #
+ # $result->{' streamloc'}-- if $fh->eof;
+
unless ($opts{'nostreams'}) {
if ($length > length($str)) {
$value = $str;
@@ -615,7 +628,7 @@ sub readval {
elsif ($str =~ m/^</) {
$str =~ s/^<//;
$fh->read($str, 255, length($str)) while (0 > index($str, '>'));
- ($value, $str) = ($str =~ /^(.*?)>(.*?)$/s);
+ ($value, $str) = ($str =~ /^(.*?)>(.*)/s);
$result = PDF::API2::Basic::PDF::String->from_pdf('<' . $value . '>');
}
@@ -625,6 +638,9 @@ sub readval {
$str = update($fh, $str) if $update;
$result = PDFArray();
while ($str !~ m/^\]/) {
+ $str =~ s/^$ws_char+//; # Ignore initial white space
+ $str =~ s/^\%[^\015\012]*$ws_char+//; # Ignore comments
+
($value, $str) = $self->readval($str, %opts);
$result->add_elements($value);
$str = update($fh, $str) if $update; # str might just be exhausted!
@@ -656,7 +672,7 @@ sub readval {
die "Can't parse `$str' near " . ($fh->tell()) . " length " . length($str) . ".";
}
- $str =~ s/^$ws_char*//s;
+ $str =~ s/^$ws_char+//s;
return ($result, $str);
}
@@ -1012,7 +1028,7 @@ sub update {
while ($str =~ m/^\%/) { # restructured by fredo/2003-03-23
print STDERR 'fpos=' . tell($fh) . ' strlen=' . length($str) . "\n" if $readDebug;
$fh->read($str, 314, length($str)) while ($str !~ m/$cr/ and not $fh->eof());
- $str =~ s/^\%[^\015\012]+$ws_char*//so; # fixed for reportlab -- fredo
+ $str =~ s/^\%[^\015\012]*$ws_char*//so; # fixed for reportlab -- fredo
}
}
@@ -1069,6 +1085,7 @@ sub _unpack_xref_stream {
return unpack('C', $data) if $width == 1;
return unpack('n', $data) if $width == 2;
return unpack('N', "\x00$data") if $width == 3;
+ return unpack('N', $data) if $width == 4;
die "Invalid column width: $width";
}
@@ -1120,16 +1137,18 @@ sub readxrtr {
($tdict, $buf) = $self->readval($buf);
}
- elsif ($buf =~ m/^\d+\s+\d+\s+obj/i)
+ elsif ($buf =~ m/^(\d+)\s+(\d+)\s+obj/i)
{
+ my ($xref_obj, $xref_gen) = ($1, $2);
+
# XRef streams.
($tdict, $buf) = $self->readval($buf);
unless ($tdict->{' stream'})
{
- die "Malformed XRefStm object in PDF file $self->{' fname'}";
+ die "Malformed XRefStm at $xref_obj $xref_gen obj in PDF file $self->{' fname'}";
}
- $tdict->read_stream();
+ $tdict->read_stream(1);
my $stream = $tdict->{' stream'};
my @widths = map { $_->val } @{$tdict->{W}->val};
@@ -1144,7 +1163,7 @@ sub readxrtr {
}
else
{
- @index = (0, $tdict->{Size}->val - 1);
+ @index = (0, $tdict->{Size}->val);
}
while (scalar @index) {
@@ -1164,7 +1183,9 @@ sub readxrtr {
}
$cols[0] = 1 unless defined $cols[0];
- die 'Invalid XRefStm entry type: ', $cols[0] if $cols[0] > 2;
+ if ($cols[0] > 2) {
+ die "Invalid XRefStm entry type ($cols[0]) at $xref_obj $xref_gen obj";
+ }
next if exists $xlist->{$xmin};

View File

@ -1,131 +0,0 @@
$OpenBSD: patch-lib_PDF_API2_Basic_PDF_Filter_FlateDecode_pm,v 1.1 2016/03/09 23:35:32 sthen Exp $
From 18f81bcd903f21a52f152efacd4ed5e4b6151154 Mon Sep 17 00:00:00 2001
From: Steve Simms <steve@deefs.net>
Date: Wed, 9 Mar 2016 09:35:36 -0500
Subject: [PATCH] Code style update.
From d3ef24a699a056d7f50c3c97aa05805e2a253587 Mon Sep 17 00:00:00 2001
From: Steve Simms <steve@deefs.net>
Date: Wed, 9 Mar 2016 10:07:17 -0500
Subject: [PATCH] Fix: Don't break if a large stream requires more than one
call to depredict.
From 94db17671a13a34122aa2dcb89562c0132bf1f77 Mon Sep 17 00:00:00 2001
From: Steve Simms <steve@deefs.net>
Date: Wed, 9 Mar 2016 10:23:21 -0500
Subject: [PATCH] Die sooner if an invalid depredict algorithm is requested.
--- lib/PDF/API2/Basic/PDF/Filter/FlateDecode.pm.orig Wed Feb 24 13:52:32 2016
+++ lib/PDF/API2/Basic/PDF/Filter/FlateDecode.pm Wed Mar 9 23:02:34 2016
@@ -68,6 +68,10 @@ sub _depredict_png {
my ($self, $stream) = @_;
my $param = $self->{'DecodeParms'};
+ my $prev = '';
+ $stream = $self->{'_depredict_next'} . $stream if defined $self->{'_depredict_next'};
+ $prev = $self->{'_depredict_prev'} if defined $self->{'_depredict_prev'};
+
my $alpha = $param->{Alpha} ? $param->{Alpha}->val() : 0;
my $bpc = $param->{BitsPerComponent} ? $param->{BitsPerComponent}->val() : 8;
my $colors = $param->{Colors} ? $param->{Colors}->val() : 1;
@@ -78,58 +82,67 @@ sub _depredict_png {
my $bpp = ceil($bpc * $comp / 8);
my $scanline = 1 + ceil($bpp * $columns);
- my $prev='';
- my $clearstream='';
- my $lastrow=($height||(length($stream)/$scanline))-1;
- foreach my $n (0..$lastrow) {
+ my $clearstream = '';
+ my $lastrow = ($height || int(length($stream) / $scanline)) - 1;
+ foreach my $n (0 .. $lastrow) {
# print STDERR "line $n:";
- my $line=substr($stream,$n*$scanline,$scanline);
- my $filter=vec($line,0,8);
- my $clear='';
- $line=substr($line,1);
- # print STDERR " filter=$filter";
- if($filter==0) {
- $clear=$line;
- } elsif($filter==1) {
- foreach my $x (0..length($line)-1) {
- vec($clear,$x,8)=(vec($line,$x,8)+vec($clear,$x-$bpp,8))%256;
+ my $line = substr($stream, $n * $scanline, $scanline);
+ my $filter = vec($line, 0, 8);
+ my $clear = '';
+ $line = substr($line, 1);
+ # print STDERR " filter=$filter ";
+ if ($filter == 0) {
+ $clear = $line;
+ }
+ elsif ($filter == 1) {
+ foreach my $x (0 .. length($line) - 1) {
+ vec($clear, $x, 8) = (vec($line, $x, 8) + vec($clear, $x - $bpp, 8)) % 256;
}
- } elsif($filter==2) {
- foreach my $x (0..length($line)-1) {
- vec($clear,$x,8)=(vec($line,$x,8)+vec($prev,$x,8))%256;
+ }
+ elsif ($filter == 2) {
+ foreach my $x (0 .. length($line) - 1) {
+ vec($clear, $x, 8) = (vec($line, $x, 8) + vec($prev, $x, 8)) % 256;
}
- } elsif($filter==3) {
- foreach my $x (0..length($line)-1) {
- vec($clear,$x,8)=(vec($line,$x,8)+floor((vec($clear,$x-$bpp,8)+vec($prev,$x,8))/2))%256;
+ }
+ elsif ($filter == 3) {
+ foreach my $x (0 .. length($line) - 1) {
+ vec($clear, $x, 8) = (vec($line, $x, 8) + floor((vec($clear, $x - $bpp, 8) + vec($prev, $x, 8)) / 2)) % 256;
}
- } elsif($filter==4) {
- # die "paeth/png filter not supported.";
- foreach my $x (0..length($line)-1) {
- vec($clear,$x,8)=(vec($line,$x,8)+_paeth_predictor(vec($clear,$x-$bpp,8),vec($prev,$x,8),vec($prev,$x-$bpp,8)))%256;
+ }
+ elsif ($filter == 4) {
+ foreach my $x (0 .. length($line) - 1) {
+ vec($clear, $x, 8) = (vec($line, $x, 8) + _paeth_predictor(vec($clear, $x - $bpp, 8), vec($prev, $x, 8), vec($prev, $x - $bpp, 8))) % 256;
}
}
- $prev=$clear;
- foreach my $x (0..($columns*$comp)-1) {
- vec($clearstream,($n*$columns*$comp)+$x,$bpc)=vec($clear,$x,$bpc);
- # print STDERR "".vec($clear,$x,$bpc).",";
+ else {
+ die "Unexpected depredictor algorithm $filter requested on line $n (valid options are 0-4)";
}
+ $prev = $clear;
+ foreach my $x (0 .. ($columns * $comp) - 1) {
+ vec($clearstream, ($n * $columns * $comp) + $x, $bpc) = vec($clear, $x, $bpc);
+ # print STDERR "" . vec($clear, $x, $bpc) . ",";
+ }
# print STDERR "\n";
}
+ $self->{'_depredict_next'} = substr($stream, ($lastrow + 1) * $scanline);
+ $self->{'_depredict_prev'} = $prev;
return $clearstream;
}
sub _paeth_predictor {
- my ($a, $b, $c)=@_;
+ my ($a, $b, $c) = @_;
my $p = $a + $b - $c;
my $pa = abs($p - $a);
my $pb = abs($p - $b);
my $pc = abs($p - $c);
- if(($pa <= $pb) && ($pa <= $pc)) {
+ if ($pa <= $pb && $pa <= $pc) {
return $a;
- } elsif($pb <= $pc) {
+ }
+ elsif ($pb <= $pc) {
return $b;
- } else {
+ }
+ else {
return $c;
}
}

View File

@ -1,4 +1,4 @@
@comment $OpenBSD: PLIST,v 1.3 2016/03/02 23:58:54 sthen Exp $
@comment $OpenBSD: PLIST,v 1.4 2016/03/16 00:17:01 sthen Exp $
${P5SITE}/PDF/
${P5SITE}/PDF/API2/
${P5SITE}/PDF/API2.pm
@ -172,6 +172,7 @@ ${P5SITE}/PDF/API2/Win32.pm
@man man/man3p/PDF::API2::Util.3p
share/examples/p5-PDF-API2/
share/examples/p5-PDF-API2/combine_pdfs.pl
share/examples/p5-PDF-API2/pdf-debug.pl
share/examples/p5-PDF-API2/pdf-deoptimize.pl
share/examples/p5-PDF-API2/pdf-optimize.pl
share/examples/p5-PDF-API2/text2pdf.pl