On Wed, May 07, 2003 at 11:19:05PM +0900, knok@daionet.gr.jp wrote:
Show quoted text> Thank you for your report. I had got some similar reports, but I
> forgot to fix it.
>
> At Mon, 5 May 2003 21:57:57 -0400 (EDT),
> Guest via RT wrote:
> > Hello,
> >
> > This looks like an old bug which no one bothered to report, but is still present:
> >
http://www.perlmonks.org/index.pl?node_id=27059
> >
> > The bug is that $dataLoc is re-initialized in such a way that in some enviroments such as forking, or under mod_perl, the wrong value is used, causing inaccurate results to be reported.
> >
> > I just discovered File::MMagic and it looks like it's going to be very useful. Thanks for your work on it! (And sorry about the blank bug report a moment ago).
> >
>
> I didn't understand the issue perfectly. Can I fix the bug by
> initializing $dataLoc at all time? If the value of
> *File::MMagic::DATA{IO} will be changed by another process, it
> wouldn't be fixed... (and I suspect it)
I think so. If I understand it correctly, this line:
$dataLoc = $fh->tell() if (! defined $dataLoc);
May just need to become:
$dataLoc = $fh->tell();
So that dataLoc is always initialized.
Actually, I don't understand why dataLoc needs to be a package scoped
variable at all. It appears that it is only referenced in the new()
routine. Would I a patch like the following work? (At least, not break
existing uses. It simply localizes the variable to the new() routine.
Mark
--- /usr/local/lib/perl5/site_perl/5.8.0/File/MMagic.pm Mon Mar 3 05:39:43 2003
+++ /usr/home/mark/tmp/MMagic.pm Wed May 7 21:37:10 2003
@@ -297,7 +297,7 @@
use vars qw(
%TEMPLATES %ESC $VERSION
$magicFile $checkMagic $followLinks $fileList
-$dataLoc $allowEightbit
+ $allowEightbit
);
BEGIN {
@@ -332,7 +332,6 @@
$VERSION = "1.17";
$allowEightbit = 1;
-undef $dataLoc;
}
sub new {
@@ -345,7 +344,7 @@
my $fh = *File::MMagic::DATA{IO};
binmode($fh);
bless $fh, 'FileHandle' if ref $fh ne 'FileHandle';
- $dataLoc = $fh->tell() if (! defined $dataLoc);
+ my $dataLoc = $fh->tell();
$fh->seek($dataLoc, 0);
&readMagicHandle($self, $fh);
} else {