git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Bug in "git rev-parse --verify"
@ 2013-03-28 13:04 Michael Haggerty
  2013-03-28 14:05 ` Jeff King
       [not found] ` <CAPc5daUqzz=9TBmj2Q0MHqEc6gMHxXoGr9+JV3hq76zDKJAyCw@mail.gmail.com>
  0 siblings, 2 replies; 22+ messages in thread
From: Michael Haggerty @ 2013-03-28 13:04 UTC (permalink / raw)
  To: git discussion list

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/

^ permalink raw reply	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2013-04-02 16:57 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-28 13:04 Bug in "git rev-parse --verify" Michael Haggerty
2013-03-28 14:05 ` 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

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).