diff options
author | Junio C Hamano <gitster@pobox.com> | 2013-04-03 08:35:45 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2013-04-03 08:35:45 -0700 |
commit | a134a60d0b6a5aaf92b3cfa04279698fdf359e5e (patch) | |
tree | f90948b97817901804d6ea1947cf5740a4148d8d | |
parent | d7df695d85c28cc21680947b822bcc3bcbddd48d (diff) | |
parent | 712c6adaeece262121c185a55e83a5074e2a8ea6 (diff) | |
download | git-a134a60d0b6a5aaf92b3cfa04279698fdf359e5e.tar.gz |
Merge branch 'jc/perl-cat-blob' into maint-1.8.1
* jc/perl-cat-blob:
Git.pm: fix cat_blob crashes on large files
-rw-r--r-- | perl/Git.pm | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/perl/Git.pm b/perl/Git.pm index a56d1e76f7..57a17160f9 100644 --- a/perl/Git.pm +++ b/perl/Git.pm @@ -965,20 +965,22 @@ sub cat_blob { my $size = $1; my $blob; - my $bytesRead = 0; + my $bytesLeft = $size; while (1) { - my $bytesLeft = $size - $bytesRead; last unless $bytesLeft; my $bytesToRead = $bytesLeft < 1024 ? $bytesLeft : 1024; - my $read = read($in, $blob, $bytesToRead, $bytesRead); + my $read = read($in, $blob, $bytesToRead); unless (defined($read)) { $self->_close_cat_blob(); throw Error::Simple("in pipe went bad"); } - - $bytesRead += $read; + unless (print $fh $blob) { + $self->_close_cat_blob(); + throw Error::Simple("couldn't write to passed in filehandle"); + } + $bytesLeft -= $read; } # Skip past the trailing newline. @@ -993,11 +995,6 @@ sub cat_blob { throw Error::Simple("didn't find newline after blob"); } - unless (print $fh $blob) { - $self->_close_cat_blob(); - throw Error::Simple("couldn't write to passed in filehandle"); - } - return $size; } |