Skip Menu |

This queue is for tickets about the File-MMagic CPAN distribution.

Report information
The Basics
Id: 2499
Status: open
Priority: 0/
Queue: File-MMagic

People
Owner: Nobody in particular
Requestors: mark [...] summersault.com
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.17
Fixed in: (no value)



Subject: wrong file type sometimes reported with forked files and under mod_perl
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).
From: knok [...] daionet.gr.jp
Date: Wed, 07 May 2003 23:19:05 +0900
To: bug-File-MMagic [...] rt.cpan.org, mark [...] summersault.com
Subject: Re: [cpan #2499] wrong file type sometimes reported with forked files and under mod_perl
RT-Send-Cc:
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: Show quoted text
> 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 got an another solution using IO::Scalar module, but it is hard to accept because I want to keep indepnedecy about another modules. *File::MMagic::DATA{IO} is an IO handle about the module file itself, so I think that I can fix with re-seeking to the position of __DATA__. Is that right? Unfortunately I don't have any environment or code to reproduce the issue. If you have such code, send me please. -- NOKUBI Takatsugu E-mail: knok@daionet.gr.jp knok@namazu.org / knok@debian.org
Date: Wed, 7 May 2003 21:40:13 -0500
To: knok [...] daionet.gr.jp
CC: bug-File-MMagic [...] rt.cpan.org
Subject: Re: [cpan #2499] wrong file type sometimes
From: Mark Stosberg <mark [...] summersault.com>
RT-Send-Cc:
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 {
From: knok [...] daionet.gr.jp
Date: Thu, 08 May 2003 22:25:23 +0900
To: Mark Stosberg <mark [...] summersault.com>
CC: knok [...] daionet.gr.jp, bug-File-MMagic [...] rt.cpan.org
Subject: Re: [cpan #2499] wrong file type sometimes
RT-Send-Cc:
At Wed, 7 May 2003 21:40:13 -0500, Mark Stosberg wrote: Show quoted text
> 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.
It should be good. I don't remember why $dataLoc is not scoped in local, but I think it is not necessary. I'll release the new version with the patch, and wait some response about the issue. Thank you for your advice. -- NOKUBI Takatsugu E-mail: knok@daionet.gr.jp knok@namazu.org / knok@debian.org
From: mark [...] summersault.com
[knok@daionet.gr.jp - Thu May 8 09:25:29 2003]: Show quoted text
> At Wed, 7 May 2003 21:40:13 -0500, > Mark Stosberg wrote:
> > 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. > > It should be good. I don't remember why $dataLoc is not scoped in > local, but I think it is not necessary. > > I'll release the new version with the patch, and wait some response > about the issue. > > Thank you for your advice.
It seems that this bug has been fixed now, and this ticket can be closed. Thanks for your help.
A modperl bug appears to still be present in 1.27. There is discussion about it and some recommendations for possible fixes over here: http://comments.gmane.org/gmane.comp.apache.mod-perl/26821 Thanks, Mark