--- pdftops-1.10 2007-12-06 18:08:44.000000000 +0100 +++ pdftops-1.20 2007-12-03 16:33:37.000000000 +0100 @@ -5,6 +5,8 @@ # Initial implementation # 1.10 - 2006-09-27/Bl # Alternatively, use Adobe Reader in place of Xpdf's pdftops +# 1.20 - 2007-12-03/Bl +# Safe temp file creation (fix gentoo bug # 201042) # # Copyright: Helge Blischke / SRZ Berlin 2004-2006 # This program is free seoftware and governed by the GNU Public License Version 2. @@ -93,7 +95,7 @@ $default_app = 'use-pdftops'; # the default if both are configured # ---------------------------------------------------------------------------------- -use File::Copy; +use File::Temp qw( tempfile ); # # Check which app to use - pdftops or acroread @@ -149,15 +151,21 @@ # as the PDF consumer needs a seekable input. if (! defined $pdffile) { - my $tmpfile = $ENV{TMPDIR} . "pdfin.$$.tmp"; - open (TEMP, ">$tmpfile") || die ("ERROR: pdftops wrapper: $tmpfile: $!\n"); - if (! copy (STDIN, TEMP)) + my $template = "pdfinXXXXXX"; + my $tmpdir = $ENV{TMPDIR}; + my ($bytes, $buffer); + my ($tmpfh, $tmpfile) = tempfile ($template, OPEN => 1, DIR => $tmpdir, UNLINK => 0, SUFFIX => '.tmp'); + while (($bytes = read (STDIN, $buffer, 1024)) > 0) { - close (TEMP); + print $tmpfh "$buffer"; + } + if ($bytes < 0) + { + close ($tmpfh); unlink $tmpfile; die ("ERROR: pdftops wrapper: $tmpfile: $!\n"); } - close (TEMP); + close ($tmpfh); $pdffile = $tmpfile; $delete_input = 1; # for deleting the temp file after converting }