Commit 1c7c6dd161856c121416c1acb39239a073713104
1 parent
8bd09112
fix offset calculation bug when writing object streams
git-svn-id: svn+q:///qpdf/trunk@657 71b93d88-0707-0410-a8cf-f5a4172ac649
Showing
1 changed file
with
29 additions
and
9 deletions
qpdf/fix-qdf
| @@ -72,6 +72,7 @@ my $st_done = ++$cur_state; | @@ -72,6 +72,7 @@ my $st_done = ++$cur_state; | ||
| 72 | 72 | ||
| 73 | my @ostream = (); | 73 | my @ostream = (); |
| 74 | my @ostream_offsets = (); | 74 | my @ostream_offsets = (); |
| 75 | +my @ostream_discarded = (); | ||
| 75 | my $ostream_idx = 0; | 76 | my $ostream_idx = 0; |
| 76 | my $ostream_id = 0; | 77 | my $ostream_id = 0; |
| 77 | my $ostream_extends = ""; | 78 | my $ostream_extends = ""; |
| @@ -130,13 +131,17 @@ while (defined($line = get_line())) | @@ -130,13 +131,17 @@ while (defined($line = get_line())) | ||
| 130 | } | 131 | } |
| 131 | elsif ($state == $st_in_ostream_dict) | 132 | elsif ($state == $st_in_ostream_dict) |
| 132 | { | 133 | { |
| 133 | - if ($line =~ m,/Extends (\d+ 0 R),) | 134 | + if ($line =~ m/^stream/) |
| 134 | { | 135 | { |
| 135 | - $ostream_extends = $1; | 136 | + $state = $st_in_ostream_offsets; |
| 136 | } | 137 | } |
| 137 | - elsif ($line =~ m/^stream/) | 138 | + else |
| 138 | { | 139 | { |
| 139 | - $state = $st_in_ostream_offsets; | 140 | + push(@ostream_discarded, $line); |
| 141 | + if ($line =~ m,/Extends (\d+ 0 R),) | ||
| 142 | + { | ||
| 143 | + $ostream_extends = $1; | ||
| 144 | + } | ||
| 140 | } | 145 | } |
| 141 | # discard line | 146 | # discard line |
| 142 | } | 147 | } |
| @@ -149,6 +154,10 @@ while (defined($line = get_line())) | @@ -149,6 +154,10 @@ while (defined($line = get_line())) | ||
| 149 | $state = $st_in_ostream_outer; | 154 | $state = $st_in_ostream_outer; |
| 150 | push(@ostream, $line); | 155 | push(@ostream, $line); |
| 151 | } | 156 | } |
| 157 | + else | ||
| 158 | + { | ||
| 159 | + push(@ostream_discarded, $line); | ||
| 160 | + } | ||
| 152 | # discard line | 161 | # discard line |
| 153 | } | 162 | } |
| 154 | elsif ($state == $st_in_ostream_outer) | 163 | elsif ($state == $st_in_ostream_outer) |
| @@ -327,16 +336,20 @@ sub write_ostream | @@ -327,16 +336,20 @@ sub write_ostream | ||
| 327 | ++$onum; | 336 | ++$onum; |
| 328 | $offsets .= "$onum $_\n"; | 337 | $offsets .= "$onum $_\n"; |
| 329 | } | 338 | } |
| 339 | + my $offset_adjust = length($offsets); | ||
| 330 | $first += length($offsets); | 340 | $first += length($offsets); |
| 331 | $stream_length += length($offsets); | 341 | $stream_length += length($offsets); |
| 332 | - print " /Length $stream_length\n"; | ||
| 333 | - print " /N $n\n"; | ||
| 334 | - print " /First $first\n"; | 342 | + my $dict_data = ""; |
| 343 | + $dict_data .= " /Length $stream_length\n"; | ||
| 344 | + $dict_data .= " /N $n\n"; | ||
| 345 | + $dict_data .= " /First $first\n"; | ||
| 335 | if ($ostream_extends) | 346 | if ($ostream_extends) |
| 336 | { | 347 | { |
| 337 | - print " /Extends $ostream_extends\n"; | 348 | + $dict_data .= " /Extends $ostream_extends\n"; |
| 338 | } | 349 | } |
| 339 | - print ">>\n"; | 350 | + $dict_data .= ">>\n"; |
| 351 | + $offset_adjust += length($dict_data); | ||
| 352 | + print $dict_data; | ||
| 340 | print "stream\n"; | 353 | print "stream\n"; |
| 341 | print $offsets; | 354 | print $offsets; |
| 342 | foreach (@ostream) | 355 | foreach (@ostream) |
| @@ -344,9 +357,16 @@ sub write_ostream | @@ -344,9 +357,16 @@ sub write_ostream | ||
| 344 | print $_; | 357 | print $_; |
| 345 | } | 358 | } |
| 346 | 359 | ||
| 360 | + for (@ostream_discarded) | ||
| 361 | + { | ||
| 362 | + $offset -= length($_); | ||
| 363 | + } | ||
| 364 | + $offset += $offset_adjust; | ||
| 365 | + | ||
| 347 | $ostream_idx = 0; | 366 | $ostream_idx = 0; |
| 348 | $ostream_id = 0; | 367 | $ostream_id = 0; |
| 349 | @ostream = (); | 368 | @ostream = (); |
| 350 | @ostream_offsets = (); | 369 | @ostream_offsets = (); |
| 370 | + @ostream_discarded = (); | ||
| 351 | $ostream_extends = ""; | 371 | $ostream_extends = ""; |
| 352 | } | 372 | } |