{"thread":{"id":"28413","subject":"[PATCH] Prevent users from adding the file that has all-zero SHA-1","startedAt":"2011-09-17T11:39:34Z","lastAt":"2011-09-20T10:13:05Z","messageCount":5,"participants":["Nguyễn Thái Ngọc Duy","Mikael Magnusson","Nguyen Thai Ngoc Duy","Ramkumar Ramachandra"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"175686","messageId":"1316259574-1291-1-git-send-email-pclouds@gmail.com","threadId":"28413","inReplyTo":null,"subject":"[PATCH] Prevent users from adding the file that has all-zero SHA-1","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-09-17T11:39:34Z","receivedAt":"2011-09-17T11:39:34Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"This particular SHA-1 has special meaning to git, very much like NULL\nin C. If a user adds a file that has this SHA-1, unexpected things can\nhappen.\n\nGranted, the chance is probably near zero because the content must\nalso start with valid blob header. But extra safety does not harm.\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n Another way than die() is to detect this situation and update header a\n little to give different SHA-1 (for example a leading 0 in object\n size in header). Older git versions may not be happy with such an\n approach.\n\n The same check can be added to commit, tree, tag creation and fsck.\n Maybe I'm too paranoid.\n\n By the way, are any other SHA-1s sensitive to git like this one?\n\n sha1_file.c |    5 +++++\n 1 files changed, 5 insertions(+), 0 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 064a330..76be0dd 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -2748,6 +2748,11 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st,\n \telse\n \t\tret = index_stream(sha1, fd, size, type, path, flags);\n \tclose(fd);\n+\tif (!ret && is_null_sha1(sha1))\n+\t\tdie(_(\"You are very unluckly.\\n\"\n+\t\t      \"You cannot add '%s' because this particular SHA-1 is used internally by git.\\n\"\n+\t\t      \"Any chance you can modify this file just a little to give different SHA-1?\"),\n+\t\t    path);\n \treturn ret;\n }\n \n-- \n1.7.3.1.256.g2539c.dirty\n"},{"id":"175724","messageId":"CAHYJk3TRHu0whbdPQXzs2ELpoiEqZPxeWmz_V4HQzj5XfAJDBA@mail.gmail.com","threadId":"28413","inReplyTo":"1316259574-1291-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] Prevent users from adding the file that has all-zero SHA-1","fromName":"Mikael Magnusson","fromEmail":"mikachu@gmail.com","sentAt":"2011-09-18T17:06:06Z","receivedAt":"2011-09-18T17:06:06Z","isPatch":true,"sender":{"key":"mikachu@gmail.com","avatar":null},"body":"2011/9/17 Nguyễn Thái Ngọc Duy <pclouds@gmail.com>:\n> This particular SHA-1 has special meaning to git, very much like NULL\n> in C. If a user adds a file that has this SHA-1, unexpected things can\n> happen.\n>\n> Granted, the chance is probably near zero because the content must\n> also start with valid blob header. But extra safety does not harm.\n>\n> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n> ---\n>  Another way than die() is to detect this situation and update header a\n>  little to give different SHA-1 (for example a leading 0 in object\n>  size in header). Older git versions may not be happy with such an\n>  approach.\n>\n>  The same check can be added to commit, tree, tag creation and fsck.\n>  Maybe I'm too paranoid.\n>\n>  By the way, are any other SHA-1s sensitive to git like this one?\n\nBad things will happen if you get an object with the same hash as any\nalready existing one, and AFAIK, there are no checks for this. I don't\nthink there's much point in treating 000...0 more specially than\nHEAD^0 for example. The only two hashes that mean something in an\nempty repo I guess are this one and the empty tree hash though.\n\nPS there's a typo in your error message, \"unluckly\".\n\n-- \nMikael Magnusson\n"},{"id":"175779","messageId":"CACsJy8Dc2mUPU5x=stRo+Hx+A4ZuVpVWvQAT2-Mq4VMmNywTAQ@mail.gmail.com","threadId":"28413","inReplyTo":"CAHYJk3TRHu0whbdPQXzs2ELpoiEqZPxeWmz_V4HQzj5XfAJDBA@mail.gmail.com","subject":"Re: [PATCH] Prevent users from adding the file that has all-zero SHA-1","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-09-19T09:26:43Z","receivedAt":"2011-09-19T09:26:43Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"2011/9/19 Mikael Magnusson <mikachu@gmail.com>:\n> Bad things will happen if you get an object with the same hash as any\n> already existing one, and AFAIK, there are no checks for this.\n\nRight. Forgot this, thanks.\n-- \nDuy\n"},{"id":"175836","messageId":"CALkWK0n9kJtUPrpxTmtfH7kVd7CksULjt7bo3cFhOrS_NBVbMw@mail.gmail.com","threadId":"28413","inReplyTo":"1316259574-1291-1-git-send-email-pclouds@gmail.com","subject":"Re: [PATCH] Prevent users from adding the file that has all-zero SHA-1","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2011-09-20T06:25:47Z","receivedAt":"2011-09-20T06:25:47Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi Nguyễn,\n\nNguyễn Thái Ngọc Duy writes:\n> This particular SHA-1 has special meaning to git, very much like NULL\n> in C. If a user adds a file that has this SHA-1, unexpected things can\n> happen.\n> [...]\n\nInteresting patch.  Is it possible to write some sort of testcase?\n\n-- Ram\n"},{"id":"175850","messageId":"CACsJy8BU=WnhcHquO0520NR2T6y-OS9RDzCSaE_KyQVCp_uh4A@mail.gmail.com","threadId":"28413","inReplyTo":"CALkWK0n9kJtUPrpxTmtfH7kVd7CksULjt7bo3cFhOrS_NBVbMw@mail.gmail.com","subject":"Re: [PATCH] Prevent users from adding the file that has all-zero SHA-1","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2011-09-20T10:13:05Z","receivedAt":"2011-09-20T10:13:05Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"2011/9/20 Ramkumar Ramachandra <artagnon@gmail.com>:\n> Hi Nguyễn,\n>\n> Nguyễn Thái Ngọc Duy writes:\n>> This particular SHA-1 has special meaning to git, very much like NULL\n>> in C. If a user adds a file that has this SHA-1, unexpected things can\n>> happen.\n>> [...]\n>\n> Interesting patch.  Is it possible to write some sort of testcase?\n\nNaah. I tested it by explicitly clear the result hash, just before it\ngets to my changes, then do \"git add <blah>\".\n-- \nDuy\n"}]}