Subject: | Shouldn't crash if index beyond end |
Date: | Thu, 26 Feb 2009 16:00:19 -0500 |
To: | bug-Tie-FlatFile-Array [...] rt.cpan.org |
From: | Daniel Macks <dmacks [...] netspace.org> |
Tie::FlatFile::Array (version 0.03) on OS X 10.4 using fink's
perl5.8.8 or apple's perl5.8.6 and fink-supplied Class::Accessor
(version 0.31), I get unexpected and undesireable crash when reading
beyond the last defined element:
#!/sw/bin/perl5.8.8 -w
use strict;
use Data::Dumper;
use Tie::FlatFile::Array;
use Fcntl;
tie my @tied, 'Tie::FlatFile::Array',
'data.file', O_RDWR | O_CREAT, 0644,
{ packformat => 'AL'};
$tied[1] = ["A", 10];
print Dumper($tied[0]);
print Dumper($tied[1]);
print Dumper($tied[2]);
gives:
$VAR1 = [
'',
0
];
$VAR1 = [
'A',
10
];
Index 2: Invalid access of FileHandle=GLOB(0x182defc) at /sw/lib/perl5-core/5.8.8/darwin-thread-multi-2level/Data/Dumper.pm line 511
The autovivification of values before vs after one defined in the
middle of the array should not be different, and especially should not
crash my program! If the "uninitialized" state is empty (unpacked
"zero", as $tied[0]), then reading any un-set element should give that
same result (cf $tied[2]). A change like ...Array::FETCH:
-croak("Index $index: Invalid access of $fh") unless $data;
+$data = "\0"x$self->reclen unless $data;
Actually, is "boolean meaning of $data" even correct there? Given that
$data is an arbitrary packed struct, it could well be valid data that
happens to be false. Seems like the intent is to check for (undef)
i.e., reading beyond the end of the file?
dan
--
Daniel Macks
dmacks@netspace.org
http://www.netspace.org/~dmacks