Subject: | OBOE error in /Length dicts for streams ending on ^M (patch incl.) |
When computing the value of the /Length dict for streams ending on a carriage return, the necessary adjustment is not always applied. This results in corrupt PDFs.
Compare Text::PDF::Dict->outobjdeep() line 90
$self->{'Length'} = Text::PDF::Number->new(length($self->{' stream'}) + ($self->{' stream'} =~ m/$cr$/o ? 0 : 1));
with line 171 (and 205), where 1 is always added regardless:
$len = $fh->tell - $loc + 1;
I believe the above line should be aligned with the logic of line 90 to read:
$len = $fh->tell - $loc + ($str =~ m/$cr$/o ? 0 : 1);
This'll uncorrupt the PDfs in question.
Best regards
Thomas
--- Dict.pm.orig 2016-08-24 23:18:16.000000000 +0200
+++ Dict.pm 2017-12-08 11:32:45.483949200 +0100
@@ -168,7 +168,7 @@
$fh->print($str);
if (@filts > 0)
{
- $len = $fh->tell - $loc + 1;
+ $len = $fh->tell - $loc + ($str =~ m/$cr$/o ? 0 : 1);
if ($self->{'Length'}{'val'} != $len)
{
$self->{'Length'}{'val'} = $len;
@@ -202,7 +202,7 @@
$fh->print($str);
}
- $len = $fh->tell - $loc + 1;
+ $len = $fh->tell - $loc + ($str =~ m/$cr$/o ? 0 : 1);
if ($self->{'Length'}{'val'} != $len)
{
$self->{'Length'}{'val'} = $len;
@@ -325,4 +325,4 @@
$res;
}
-1;
\ No newline at end of file
+1;