ssimms / pdfapi2

Create, modify, and examine PDF files in Perl
Other
15 stars 20 forks source link

PDF::API2->from_string causes for action "page1-to-thumbnail" an OOM (memory-leak, loop) #78

Open neffets opened 5 months ago

neffets commented 5 months ago

We have normal pdf created with "Acrobat PDFMaker for Word". It has only 6 pages.

We try to generate a Thumbnail from the PDF per PDF::API2

$file = '2024_Q1_-digitale-Veranstaltungen_de.pdf';
my $data = do {
    local $/ = undef;
    open my $fh, "<", $file or die "could not open $file: $!";
    <$fh>;
};

$pdf = PDF::API2->from_string($data);
# never gets here

my $sp_pdf = new PDF::API2;
eval {
    $sp_pdf->import_page($pdf,1,0);
};
if ($@) {
    warn $@;
}
my $image = Image::Magick->new;
$error = $image->BlobToImage($sp_pdf->stringify);

It hangs on line 1 (first from_string()) forever, increasing the use resident-memory over time (using 1GB per 300 seconds more) 2024Q1-digitale-Veranstaltungen_de.pdf

Workaround is to encapsulate the "from_string" method with an POSIX::sigaction and alarm(10).