fix-qdf: handle object streams with > 255 objects

fix-qdf was previously hard-coding the number of bytes for the f2
field of the xref stream entry. This addresses issue #37. Thanks
aluebcke for reporting.
This commit is contained in:
Jay Berkenbilt 2015-05-24 16:20:22 -04:00
parent cf43882e9f
commit b356b9dfa2
4 changed files with 2249 additions and 11 deletions

View File

@ -1,5 +1,8 @@
2015-05-24 Jay Berkenbilt <ejb@ql.org>
* Bug fix: fix-qdf was not handling object streams with more than
255 objects in them.
* Handle Microsoft crypt provider initialization properly for case
where no keys have been previously created, such as in a fresh
Windows installation.

View File

@ -53,6 +53,7 @@ my $stream_start = 0;
my $stream_length = 0;
my $xref_offset = 0;
my $xref_f1_nbytes = 0;
my $xref_f2_nbytes = 0;
my $xref_size = 0;
my $cur_state = 0;
@ -122,11 +123,28 @@ while (defined($line = get_line()))
$t >>= 8;
++$xref_f1_nbytes;
}
my $esize = $xref_f1_nbytes + 2;
# Figure out how many bytes we need for ostream index.
# Make sure we get at least 1 byte even if there are no
# object streams.
my $max_objects = 1;
foreach my $e (@xref)
{
my ($type, $f1, $f2) = @$e;
if ((defined $f2) && ($f2 > $max_objects))
{
$max_objects = $f2;
}
}
while ($max_objects)
{
$max_objects >>=8;
++$xref_f2_nbytes;
}
my $esize = 1 + $xref_f1_nbytes + $xref_f2_nbytes;
$xref_size = 1 + @xref;
my $length = $xref_size * $esize;
print " /Length $length\n";
print " /W [ 1 $xref_f1_nbytes 1 ]\n";
print " /W [ 1 $xref_f1_nbytes $xref_f2_nbytes ]\n";
$state = $st_in_xref_stream_dict;
}
}
@ -200,19 +218,25 @@ while (defined($line = get_line()))
}
if ($line =~ m/^stream\n/)
{
my $pack = "(C C$xref_f1_nbytes C)";
my $pack = "(C C$xref_f1_nbytes C$xref_f2_nbytes)";
print pack($pack, 0, 0, 0);
foreach my $x (@xref)
{
my ($type, $f1, $f2) = @$x;
$f2 = 0 unless defined $f2;
my @f1 = ();
for (my $i = 0; $i < $xref_f1_nbytes; ++$i)
{
unshift(@f1, $f1 & 0xff);
$f1 >>= 8;
}
print pack($pack, $type, @f1, $f2);
my @f1 = ();
my @f2 = ();
foreach my $d ([\@f1, $f1, $xref_f1_nbytes],
[\@f2, $f2, $xref_f2_nbytes])
{
my ($fa, $f, $nbytes) = @$d;
for (my $i = 0; $i < $nbytes; ++$i)
{
unshift(@$fa, $f & 0xff);
$f >>= 8;
}
}
print pack($pack, $type, @f1, @f2);
}
print "\nendstream\nendobj\n\n";
print "startxref\n$xref_offset\n\%\%EOF\n";

View File

@ -1993,7 +1993,7 @@ compare_pdfs("inline-images-cr.pdf", "a.pdf");
show_ntests();
# ----------
$td->notify("--- fix-qdf Tests ---");
$n_tests += 4;
$n_tests += 5;
for (my $n = 1; $n <= 2; ++$n)
{
@ -2007,6 +2007,10 @@ for (my $n = 1; $n <= 2; ++$n)
{$td->FILE => "fix$n.qdf.out",
$td->EXIT_STATUS => 0});
}
$td->runtest("fix-qdf with big object stream", # > 255 objects in a stream
{$td->COMMAND => "fix-qdf big-ostream.pdf"},
{$td->FILE => "big-ostream.pdf",
$td->EXIT_STATUS => 0});
show_ntests();
# ----------

File diff suppressed because it is too large Load Diff