Fix some range issues and 32-bit issues with avatar generation
Summary:
Ref T12444. A few issues:
- x % (y - z) doesn't generate values in the full range: the largest value is never generated. Instead, use x % (1 + y - z).
- digestToRange(1, count) never generates 0. After fixing the first bug, it could generate count. The range of the arrays is 0..(count-1), inclusive. Generate the correct range instead.
- unpack('L', ...) can unpack a negative number on a 32-bit system. Use & 0x7FFFFFFF to mask off the sign bit so the result is always a positive integer.
- FileFinder might return arbitrary keys, but we rely on sequential keys (0, 1, 2, ...)
Test Plan:
- Used bin/people profileimage ... --force to regenerate images.
- Added some debugging to verify that the math seemed to be working.
Reviewers: chad
Reviewed By: chad
Maniphest Tasks: T12444
Differential Revision: https://secure.phabricator.com/D17543