{"thread":{"id":"32975","subject":"[PATCH] Fix in Git.pm cat_blob crashes on large files (reviewed by Jeff King)","startedAt":"2013-02-22T17:03:56Z","lastAt":"2013-02-22T17:10:07Z","messageCount":2,"participants":["Joshua Clayton","Erik Faye-Lund"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"210034","messageId":"CAMB+bfLjewgKjSN6WNHGkwpRx9OaWipi_-TDa0MnJMDN+6tPZA@mail.gmail.com","threadId":"32975","inReplyTo":null,"subject":"[PATCH] Fix in Git.pm cat_blob crashes on large files (reviewed by Jeff King)","fromName":"Joshua Clayton","fromEmail":"stillcompiling@gmail.com","sentAt":"2013-02-22T17:03:56Z","receivedAt":"2013-02-22T17:03:56Z","isPatch":true,"sender":{"key":"stillcompiling@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1380815?v=4"},"body":"Read and write each 1024 byte buffer, rather than trying to buffer\nthe entire content of the file.\nPrevious code would crash on all files > 2 Gib, when the offset variable\nbecame negative (perhaps below the level of perl), resulting in a crash.\nOn a 32 bit system, or a system with low memory it might crash before\nreaching 2 GiB due to memory exhaustion.\n\nSigned-off-by: Joshua Clayton <stillcompiling@gmail.com>\n---\n perl/Git.pm |   12 +++++-------\n 1 file changed, 5 insertions(+), 7 deletions(-)\n\ndiff --git a/perl/Git.pm b/perl/Git.pm\nindex 931047c..cc91288 100644\n--- a/perl/Git.pm\n+++ b/perl/Git.pm\n@@ -949,13 +949,16 @@ sub cat_blob {\n \t\tlast unless $bytesLeft;\n\n \t\tmy $bytesToRead = $bytesLeft < 1024 ? $bytesLeft : 1024;\n-\t\tmy $read = read($in, $blob, $bytesToRead, $bytesRead);\n+\t\tmy $read = read($in, $blob, $bytesToRead);\n \t\tunless (defined($read)) {\n \t\t\t$self->_close_cat_blob();\n \t\t\tthrow Error::Simple(\"in pipe went bad\");\n \t\t}\n-\n \t\t$bytesRead += $read;\n+\t\tunless (print $fh $blob) {\n+\t\t\t$self->_close_cat_blob();\n+\t\t\tthrow Error::Simple(\"couldn't write to passed in filehandle\");\n+\t\t}\n \t}\n\n \t# Skip past the trailing newline.\n@@ -970,11 +973,6 @@ sub cat_blob {\n \t\tthrow Error::Simple(\"didn't find newline after blob\");\n \t}\n\n-\tunless (print $fh $blob) {\n-\t\t$self->_close_cat_blob();\n-\t\tthrow Error::Simple(\"couldn't write to passed in filehandle\");\n-\t}\n-\n \treturn $size;\n }\n\n-- \n1.7.10.4\n"},{"id":"210035","messageId":"CABPQNSaGSOio1Sn=--jdCfOkw4N+L_khH3Z6AZAQ=aaUg_OGig@mail.gmail.com","threadId":"32975","inReplyTo":"CAMB+bfLjewgKjSN6WNHGkwpRx9OaWipi_-TDa0MnJMDN+6tPZA@mail.gmail.com","subject":"Re: [PATCH] Fix in Git.pm cat_blob crashes on large files (reviewed by Jeff King)","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@gmail.com","sentAt":"2013-02-22T17:10:07Z","receivedAt":"2013-02-22T17:10:07Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"On Fri, Feb 22, 2013 at 6:03 PM, Joshua Clayton\n<stillcompiling@gmail.com> wrote:\n> Read and write each 1024 byte buffer, rather than trying to buffer\n> the entire content of the file.\n> Previous code would crash on all files > 2 Gib, when the offset variable\n> became negative (perhaps below the level of perl), resulting in a crash.\n> On a 32 bit system, or a system with low memory it might crash before\n> reaching 2 GiB due to memory exhaustion.\n>\n> Signed-off-by: Joshua Clayton <stillcompiling@gmail.com>\n\nWe usually put \"Reviewed-by: Name <email>\" right below the SoB-line,\nrather than in the subject. And then we CC the people who were\ninvolved in the previous round :)\n"}]}