Skip to content

Commit

Permalink
Fix enumerate_shared_objects() ancestor check.
Browse files Browse the repository at this point in the history
  • Loading branch information
deven committed Nov 25, 2020
1 parent 4838aa8 commit f28b517
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/PDF/Data.pm
Original file line number Diff line number Diff line change
Expand Up @@ -643,17 +643,20 @@ sub enumerate_shared_objects {
return;
}

# Return if this object is an ancestor of itself.
return if $ancestors->{$object};

# Add this object to the lookup hash of ancestors.
$ancestors->{$object}++;

# Recurse to check entire object tree.
if (is_hash $object) {
foreach my $key (sort { fc($a) cmp fc($b) || $a cmp $b; } keys %{$object}) {
$self->enumerate_shared_objects($objects, $seen, $ancestors, $object->{$key}) if ref $object->{$key} and not $ancestors->{$object->{$key}};
$self->enumerate_shared_objects($objects, $seen, $ancestors, $object->{$key}) if ref $object->{$key};
}
} elsif (is_array $object) {
foreach my $obj (@{$object}) {
$self->enumerate_shared_objects($objects, $seen, $ancestors, $obj) if ref $obj and not $ancestors->{$obj};
$self->enumerate_shared_objects($objects, $seen, $ancestors, $obj) if ref $obj;
}
}

Expand Down

0 comments on commit f28b517

Please sign in to comment.