4 ms·
Always use the full hash everywhere. Never store the short hash anywhere. It's good only for immediate commandline use, and nothing else.
by plasticeagle 2y ago
Always use the full hash everywhere.
Never store the short hash anywhere. It's good only for immediate commandline use, and nothing else.
- saagarjha 2y agoThis doesn't really solve the underlying issue, though.
- augusto-moura 2y agoNot technically, but pratically yes. The chance of having a single letter "e" and everything else a number would be very rare for a full SHA1 hash. I'm not interested in doing the calculations but if anyone wants to do it, it sounds like a cool math problem to solve
- Sophira 2y agoWhile I haven't done the math, you're right that it would need to be an exponential of some kind (assuming this is JavaScript-based). In JavaScript, Number.MAX_VALUE (the biggest number that can be represented without returning Infinity) is a 309-digit number, and Git SHA-1 hashes are only 40 characters long. However, this does mean that the chance will be even smaller than you say. Assuming that all other conditions are met (sole "e", every other character is a digit) * if the sole "e" is in any place from the 2nd to the 37th, the resulting number is almost guaranteed to be returned as Infinity, unless the number happens to begin with "0e". (Leading zeroes, either in the significand or the exponent, would be required for this to not be a guarantee. Any number beginning "0e", on the other hand, will evaluate to 0 and not become Infinity.) * if it's in the 37th place, the resulting number (assuming no leading zeroes) has around a 27% chance to be representable without being returned as Infinity. * if it's in the 38th or 39th place, the resulting number is guaranteed to be small enough that it won't be turned into Infinity. * if it's in the 1st or 40th place, it probably won't be parsed as a number so will not return an error. I'm also not interested in doing the full calculations, and in the end this isn't going to make a significant difference to the chances IMO (except in the "0e" case mentioned above, which seems like it'd make a noticeable difference), but it's interesting to think about the edge cases.
- augusto-moura 2y agoDoesn't matter if it hits Infinity or not, if it can be parsed as a number that is a already a bug
- jenadine 2y agoFor a hash of N hex digit. The probably to have a single e and the rest decimal is N*10^(N-1)/16^N With 10 hex digit like on the blog, that'd be 0.9% so about once every 100 builds With full 40 digit: 2.7e-8 so about once every 100M builds Assuming my math is correct.
- imron 2y agoTechnically no, but realistically yes.