Skip to content

Commit

Permalink
Add validation of stream types and errors for object/xref streams.
Browse files Browse the repository at this point in the history
  • Loading branch information
deven committed Jun 27, 2024
1 parent 73afce5 commit 2b54422
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/PDF/Data.pm
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,16 @@ sub parse_objects {
or warn join(": ", $self->{-file} || (), "Byte offset $offset: Object #$id: Stream length not found in metadata!\n");
s/\A\r?\n//;

# Check for unsupported stream types.
my $type = $stream->{Type} // "";
if ($type eq "/ObjStm") {
croak join(": ", $self->{-file} || (), "Byte offset $offset: PDF 1.5 object streams are not supported!\n");
} elsif ($type eq "/XRef") {
croak join(": ", $self->{-file} || (), "Byte offset $offset: PDF 1.5 cross-reference streams are not supported!\n");
} elsif ($type !~ /^(?:\/(?:Metadata|XObject))?$/) {
croak join(": ", $self->{-file} || (), "Byte offset $offset: Unrecognized stream type \"$type\"!\n");
}

# If the declared stream length is missing or invalid, determine the shortest possible length to make the stream valid.
unless (defined($length) && !ref($length) && substr($_, $length) =~ /\A(\s*endstream$ws)/) {
if (/\A((?>(?:[^e]+|(?!endstream\s)e)*))\s*endstream$ws/) {
Expand Down

0 comments on commit 2b54422

Please sign in to comment.