CC: | john [...] humyo.com |
Subject: | error conditions can leave $/ changed |
Hi,
I'm afraid that I don't have a concrete failure case to hand, but at
least one of the Image/ExifTool handlers (Postscript.pm) sets the input
record seperator ($/) and doesn't set it back to the old value in some
cases.
We do see this problem on our live data. We typically call ->ExtractInfo
on a filehandle and so, with no file extension, exiftool has to run
through a list of possible handler, which probably means we hit more
error paths.
Here is one potentially problematic snippet:
my $oldsep = SetInputRecordSeparator($raf);
$oldsep or return PSErr($exifTool, 'invalid PS data');
# set file type (PostScript or EPS)
$raf->ReadLine($data) or return 0;
$exifTool->SetFileType($data =~ /EPSF/ ? 'EPS' : 'PS');
if we take the 'return 0' error return we'll have left $/ set to
whatever SetInputRecordSeparator decided.
Some suggested fixes:
- never assign to $/ with a 'local' qualifier. You could do this
reasonably cleanly by changing SetInputRecordSeperator to
'chooseInputRecordSeperator' (return the desired seperator) and writing
code like this:
local $/ = ChooseInputRecordSeperator($raf);
the localisation will then take care of everything.
- have top-level 'local $/ = $/' at the entry points into your module,
to ensure we get back the value of $/ we entered with.
Thanks for the great module, hope this feedback helps.