git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Fix in Git.pm cat_blob crashes on large files (resubmit with reviewed-by)

From
Jeff King <peff@peff.net>
Date
Feb 22, 2013, 18:34 UTC
Message-ID
<20130222183419.GB18934@sigill.intra.peff.net>
In-Reply-To
<CAMB+bfLvpKNLaEUyUUYsO5n2y+9tyd_QcnPVzX0s2Z2t3Fr9=g@mail.gmail.com>
On Fri, Feb 22, 2013 at 09:30:57AM -0800, Joshua Clayton wrote:
> Read and write each 1024 byte buffer, rather than trying to buffer
> the entire content of the file.

OK. Did you ever repeat your timing with a larger symmetric buffer? That should probably be a separate patch on top, but it might be worth doing while we are thinking about it.

> Previous code would crash on all files > 2 Gib, when the offset variable
> became negative (perhaps below the level of perl), resulting in a crash.

I'm still slightly dubious of this, just because it doesn't match my knowledge of perl (which is admittedly imperfect). I'm curious how you diagnosed it?

Show 5 quoted lines
> On a 32 bit system, or a system with low memory it might crash before
> reaching 2 GiB due to memory exhaustion.
> 
> Signed-off-by: Joshua Clayton <stillcompiling@gmail.com>
> Reviewed-by: Jeff King <peff@peff.net>

The commit message is a good place to mention any side effects, and why they are not a problem. Something like:

  The previous code buffered the whole blob before writing, so any error
  reading from cat-file would result in zero bytes being written to the
  output stream.  After this change, the output may be left in a
  partially written state (or even fully written, if we fail when
  parsing the final newline from cat-file). However, it's not reasonable
  for callers to expect anything about the state of the output when we
  return an error (after all, even with full buffering, we might fail
  during the writing process).  So any caller which cares about this is
  broken already, and we do not have to worry about them.
> ---
>  perl/Git.pm |   12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
The patch itself looks fine to me.
-Peff
Previous: Joshua ClaytonNext: Joshua Clayton
Message 2 of 5 in “Fix in Git.pm cat_blob crashes on large files (resubmit with reviewed-by)”
  1. Fix in Git.pm cat_blob crashes on large files (resubmit with reviewed-by)Joshua Clayton, Feb 22, 2013
  2. Jeff KingFeb 22, 2013
  3. Joshua ClaytonFeb 22, 2013
  4. Jeff KingFeb 22, 2013
  5. Junio C HamanoFeb 22, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.