News for hackers. Stuff that matters.
Re:Ask HN: md5 + size = file UID? by paulgb on Monday August 09, 2010 @10:54AM (#1588134)
No, for the same reason you can't fit n+1 pigeons in n holes.

http://en.wikipedia.org/wiki/Pigeonhole_principle

Re:Ask HN: md5 + size = file UID? by mooism2 on Monday August 09, 2010 @10:56AM (#1588142)
No, it isn't.

MD5 gives 16 bytes of output, so consider all possible 17 byte files and their MD5 checksums. On average, each checksum will be shared by 256 17 byte files.

If you're worried about MD5 collisions between files, adding the file size isn't going to do much to help. Better to use SHA1 or some other algorithm in addition to MD5. E.g. 16 bytes of MD5 + 20 bytes of SHA1 = 36 bytes total output.

Re:Ask HN: md5 + size = file UID? by mfukar on Monday August 09, 2010 @10:58AM (#1588153)
No, because all hashing algorithms suffer from collisions. A perfect hash function for files would require space of at least a number of bits proportional to the size of your problem space.

In practice, you can go with SHA-2, for which no collisions have been found yet.

Re:Ask HN: md5 + size = file UID? by _0ffh on Monday August 09, 2010 @11:33AM (#1588276)
No matter which hash function you use, you will _not_ get 100% unique identifiers, because you _can't_! Just do the freaking math, and you'll see for yourself - it's quite obvious, actually!
Re:Ask HN: md5 + size = file UID? by alexrodygin on Wednesday August 11, 2010 @05:35AM (#1594280)
Yeah, I was confused. I'm a product guy, so math isn't my strongest point. It looks like combining Md5 + size + Sha1 should be enough to get a almost unique file id. Thank you all for the replies.
Re:Ask HN: md5 + size = file UID? by cperciva on Monday August 09, 2010 @10:52AM (#1588127)
Is md5 checksum plus the file's size is absolutely unique identifier for a file across the universe?

No. Use SHA256.