git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael Haggerty <mhagger@alum.mit.edu>
To: git discussion list <git@vger.kernel.org>
Subject: Bug in "git rev-parse --verify"
Date: Thu, 28 Mar 2013 14:04:27 +0100	[thread overview]
Message-ID: <51543FDB.9010109@alum.mit.edu> (raw)

On Junio's master, "git rev-parse --verify" accepts *any* 40-digit
hexadecimal number.  For example, pass it 40 "1" characters, and it
accepts the argument:

$ git rev-parse --verify 1111111111111111111111111111111111111111
1111111111111111111111111111111111111111
$ echo $?
0

Obviously, my repo doesn't have an object with this hash :-) so I think
this argument should be rejected.

If you add or remove a digit (to make the length different than 40), it
is correctly rejected:

$ git rev-parse --verify 111111111111111111111111111111111111111
fatal: Needed a single revision
$ echo $?
128

I believe that "git rev-parse --verify" is meant to verify that the
argument is an actual object, and that it should reject fictional SHA1s.
 (If not then the documentation should be clarified.)  The same problem
also exists in 1.8.2 but I haven't checked how much older it is.

The behavior presumably comes from the following clause in get_sha1_basic():

	if (len == 40 && !get_sha1_hex(str, sha1))
		return 0;

I won't have time to pursue this.

Michael

-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/

             reply	other threads:[~2013-03-28 13:12 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-28 13:04 Michael Haggerty [this message]
2013-03-28 14:05 ` Bug in "git rev-parse --verify" Jeff King
2013-03-28 14:55   ` Junio C Hamano
     [not found] ` <CAPc5daUqzz=9TBmj2Q0MHqEc6gMHxXoGr9+JV3hq76zDKJAyCw@mail.gmail.com>
2013-03-28 15:34   ` Michael Haggerty
2013-03-28 15:38     ` Jeff King
2013-03-28 15:52       ` Michael Haggerty
2013-03-28 16:38         ` Jeff King
2013-03-28 16:52       ` Junio C Hamano
2013-03-30  3:44         ` Michael Haggerty
2013-03-30  4:09           ` Junio C Hamano
2013-03-30  4:15             ` Junio C Hamano
2013-03-30  5:29             ` Michael Haggerty
2013-03-30  6:38               ` Junio C Hamano
2013-03-30  7:05                 ` Junio C Hamano
2013-03-30  8:09                   ` Michael Haggerty
2013-03-30  8:14                   ` Elia Pinto
2013-03-31 22:38                   ` [PATCH 1/2] peel_onion: disambiguate to favor tree-ish when we want a tree-ish Junio C Hamano
2013-03-31 22:38                   ` [PATCH 2/2] peel_onion(): teach $foo^{object} peeler Junio C Hamano
2013-04-02  8:20                     ` Michael Haggerty
2013-04-02 15:45                       ` Junio C Hamano
2013-04-02 16:32                         ` Michael Haggerty
2013-04-02 16:56                           ` Junio C Hamano

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=51543FDB.9010109@alum.mit.edu \
    --to=mhagger@alum.mit.edu \
    --cc=git@vger.kernel.org \
    /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).