[Ssh-sftp-perl-users] Fix for Net::SFTP 'ls' Math::Pari leak
Brought to you by:
dbrobins
From: David R. <dr...@at...> - 2004-12-10 22:13:20
|
I've been delving into the guts of Net::SFTP, Net::SSH::Perl, and = Math::Pari to find out why 'ls' overflows the PARI stack (e.g. = http://www.codecomments.com/message237191.html), and believe I have a = fix. The leak is in Net::SSH::Perl::Util::SSH2MP::bin2mp; when it = creates a Math::Pari 64-bit int for the file size (via = Net::SFTP::Attributes::init and Net::SFTP::Buffer::get_int64): sub bin2mp { my $s =3D shift; my $p =3D PARI(0); for my $b (split //, $s) { $p =3D $p * 256 + ord $b; } $p; } the '256', through no fault of the code, leaks about 12 bytes for each = file listed (I wrote a Math::Pari::dumpStack to check and then moved the = 256 to a $base =3D PARI(256) outside the loop as is done in mp2bin to = check this), so it becomes: sub bin2mp { my $s =3D shift; my $p =3D PARI(0); my $base =3D PARI(256); for my $b (split //, $s) { $p =3D $p * $base + ord $b; } $p; } While this doesn't solve the underlying problem (Math::Pari constants = shouldn't leak), it's a small patch for a decent gain. I will continue = to look into Math::Pari to see if I can fix the underlying problem. For = now, if someone's actively having problems, they can apply my fix = themselves. Problem is reproducible on perl 5.5.3 and 5.8.5, with a simple = connection and looped ls, e.g. (*) perl -MNet::SFTP -we = '$ftp=3DNet::SFTP->new(...connection params...); $ftp->ls("/some/dir") = while 1' (the more files in the dir, the less iterations it takes). * NOTE: do NOT use -l, Net::SSH::Perl is sensitive to it for = transmission - should this be considered a bug? Should I send a patch to this list? Thanks, --=20 Dave Isa. 40:31 |