From: John McKown <john.mckown@healthmarkets.com>
To: git@vger.kernel.org
Subject: Re: What about SHA-1 collisions?
Date: Tue, 6 Nov 2012 21:41:29 +0000 (UTC) [thread overview]
Message-ID: <loom.20121106T223000-502@post.gmane.org> (raw)
In-Reply-To: 20121106202643.GF28437@raven.wolf.lan
Josef Wolf <jw <at> raven.inka.de> writes:
>
> Hello,
>
> we all know, the probability for SHA-1 collisions is very, very low, almost
> non-existant. But we also know that they are not impossible.
>
> Just for curiosity: what would happen if such a collision would occur within
> one repository?
>
In a sense, this cannot happen. Suppose you have a new working directory.
You do a "git init" to initialize it for use by git. You then copy in a
bunch of data from elsewhere. By chance, files "a" and "b" have different
content, but the same sha1 (they collide). The "git add ." command is
basically a short cut for doing something like:
for i in *;do git add $i;done
That is, it seems to add each file, one at a time in some order. Suppose
it creates the sha1 for "a" first. It then creates the appropriate
"stuff" for file "a" in the .git subdirectory, based on the sha1 value. Now,
it gets around to processing "b". It gets the sha1 value of b and finds
that it already has an entry for that value. At that point, the "git add" thinks
"Oh, I've already processed this file. No need to do anything!" So the contents
of file "b" are not saved anywhere in git and, bottom line, that version of "b"
will not be in the git repository. Ever. Because "a" already has that SHA1 "tied
up" and it is (theoretically) never released.
I think of the SHA1 value being a unique key into a "write once" database. Once
you've added some content (a file) into the database, then the SHA1 value of
that content (file) is unmodifiable. Attempts to write another record into the
database is rejected (in a read DB, you'd get some sort of DUPLICATE KEY
response). Git considers the "duplicate key" to be just fine because it ASSUMES
that the SHA1 is unique to the first file (content) which generates it.
Hope I made sense.
John
next prev parent reply other threads:[~2012-11-06 21:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-06 20:26 What about SHA-1 collisions? Josef Wolf
2012-11-06 21:41 ` John McKown [this message]
2012-11-06 22:09 ` Josef Wolf
2012-11-07 15:42 ` Shawn Pearce
2012-11-07 23:44 ` Andrew Ardill
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=loom.20121106T223000-502@post.gmane.org \
--to=john.mckown@healthmarkets.com \
--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).