git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Joey Hess <joey@kitenet.net>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] drop support for "experimental" loose objects
Date: Sun, 24 Nov 2013 04:07:43 -0500	[thread overview]
Message-ID: <20131124090743.GA495@sigill.intra.peff.net> (raw)
In-Reply-To: <20131124084444.GA23238@sigill.intra.peff.net>

On Sun, Nov 24, 2013 at 03:44:44AM -0500, Jeff King wrote:

> In any code path where we call parse_object, we double-check that the
> result matches the sha1 we asked for. But low-level commands like
> cat-file just call read_sha1_file directly, and do not have such a
> check. We could add it, but I suspect the processing cost would be
> noticeable.

Curious, I tested this. It is noticeable. Here's the best-of-five
timings for the patch below when running a --batch cat-file on every
object in my git.git repo, using the patch below:

  [before]
  real    0m12.941s
  user    0m12.700s
  sys     0m0.244s

  [after]
  real    0m15.800s
  user    0m15.472s
  sys     0m0.344s

So it's about 20% slower. I don't know what the right tradeoff is. It's
cool to check the data each time we look at it, but it does carry a
performance penalty. I notice elsewhere in git we are inconsistent. If
you call parse_object() on an object, you get the sha1 check. But if you
just call parse_commit() on something you know to be a commit (e.g.,
because you are traversing the history and looked it up as a parent
pointer), you do not. I don't know if that is oversight, or an
intentional performance decision.

-Peff

---
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index b2ca775..2b09773 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -199,6 +199,8 @@ static void print_object_or_die(int fd, const unsigned char *sha1,
 	if (type == OBJ_BLOB) {
 		if (stream_blob_to_fd(fd, sha1, NULL, 0) < 0)
 			die("unable to stream %s to stdout", sha1_to_hex(sha1));
+		if (check_sha1_signature(sha1, NULL, 0, NULL) < 0)
+			die("object %s sha1 mismatch", sha1_to_hex(sha1));
 	}
 	else {
 		enum object_type rtype;
@@ -208,6 +210,8 @@ static void print_object_or_die(int fd, const unsigned char *sha1,
 		contents = read_sha1_file(sha1, &rtype, &rsize);
 		if (!contents)
 			die("object %s disappeared", sha1_to_hex(sha1));
+		if (check_sha1_signature(sha1, contents, rsize, typename(rtype)) < 0)
+			die("object %s sha1 mismatch", sha1_to_hex(sha1));
 		if (rtype != type)
 			die("object %s changed type!?", sha1_to_hex(sha1));
 		if (rsize != size)

  reply	other threads:[~2013-11-24  9:08 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-20 20:33 corrupt object memory allocation error Joey Hess
2013-11-20 21:33 ` Jeff King
2013-11-20 22:28   ` Joey Hess
2013-11-21 11:41     ` [PATCH] drop support for "experimental" loose objects Jeff King
2013-11-21 11:48       ` Jeff King
2013-11-21 12:43         ` Duy Nguyen
2013-11-21 14:42           ` Keshav Kini
2013-11-21 22:41           ` Jeff King
2013-11-21 19:44         ` Junio C Hamano
2013-11-23  0:24         ` Jonathan Nieder
2013-11-23  0:30           ` Jeff King
2013-11-23  0:47             ` Jonathan Nieder
2013-11-21 16:04       ` Joey Hess
2013-11-21 20:19         ` Christian Couder
2013-11-22  9:58           ` Jeff King
2013-11-22 11:04             ` Christian Couder
2013-11-22 11:24               ` Jeff King
2013-11-22 14:23                 ` Christian Couder
2013-11-22 16:15                   ` Jeff King
2013-11-22 17:23             ` Junio C Hamano
2013-11-22  2:09         ` Jeff King
2013-11-22 17:28           ` Joey Hess
2013-11-24  8:44             ` Jeff King
2013-11-24  9:07               ` Jeff King [this message]
2013-11-25 18:35                 ` Junio C Hamano
2013-11-27  9:30                   ` Jeff King
2013-11-27 18:57                     ` Junio C Hamano
2013-11-27 19:03                       ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131124090743.GA495@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=joey@kitenet.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).