Subject: | File::MimeInfo::Magic and range-length with mask |
Date: | Thu, 02 Aug 2007 14:41:14 -0400 |
To: | bug-File-MimeInfo [...] rt.cpan.org |
From: | Chapman Flack <jflack [...] math.purdue.edu> |
The regular expression that _hash_magic builds will work right
for any rule that has a >1 range, OR has a mask, OR neither,
but it won't work for a rule with both a >1 range and a mask.
For that case, the match would have to be tried at each position
in the range, first applying the mask to the original data at
that position, and then comparing the value.
The regular expression (.{0,$r}?)(.{$l}) will simply grab $l
bytes starting at the first offset in the range (because .{0,$r}?
is nongreedy), and so the match will only succeed if the pattern
is found at the first offset (just the same as if a range had
not been given).
As there isn't now any rule in the database that has both a
mask and a range, there is no urgency to implement support,
but it is probably good to add a warning such as
warn "match rule with range and mask won't work" if $r and $m;
just before the "my $end = $o + $l + $r;" line (and just after
the $r--; line suggested in
http://rt.cpan.org/Ticket/Display.html?id=28634), so if such
a rule is ever added, the failure won't be silent and unexplained.
Chapman Flack
mathematics
Purdue