Bugfix for unbounded memory use

33 views
Skip to first unread message

mcrawfor

unread,
Mar 25, 2011, 12:17:37 AM3/25/11
to bra...@googlegroups.com
I believe I have a fix for this issue: http://code.google.com/p/brackup/issues/detail?id=5

The problem is that many of the targets use a file-slurp idiom that confuses IO::InnerFile.

Here is some example code that illustrates the problem:

use strict;
use warnings;
use IO::File;
use IO::InnerFile;

my $fullpath = 'path/to/4gb-file';
my $fh = IO::File->new($fullpath, 'r');
binmode($fh);
my $ifh = IO::InnerFile->new($fh, 0, 20971520);

# Proposed method of reading chunk
my $chunkref;
while(<$ifh>){
$chunkref .= $_;
}
warn length $chunkref; # outputs 20971520 

# Old method
my $chunkref2 = do { local $/; <$fh> };
warn length $chunkref2; # never gets here, grows to size of file


My proposed diff is attached.

Let me know how to go about getting it integrated - this bug blocks me backing up my videos, so I'm excited to get it moving. :)

Thanks for the cool backup tool,
-m
brackup-memory.patch

mcrawfor

unread,
Mar 25, 2011, 12:23:24 AM3/25/11
to bra...@googlegroups.com
I'm sorry, I realized my code sample was confusing after posting: The old method is a replacement for the proposed, not a continuation of the same script - so the current, failing version in whole looks like this:

use strict;
use warnings;

use IO::File;
use IO::InnerFile;

my $fullpath = 'path/to/4gb-file';

my $fh = IO::File->new($fullpath, 'r');
binmode($fh);
my $ifh = IO::InnerFile->new($fh, 0, 20971520);

# Old method
my $chunkref2 = do { local $/; <$ifh> };
Reply all
Reply to author
Forward
0 new messages