@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+8 -6
+5 -4
src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php
··· 119 119 foreach ($list as $file) { 120 120 $map['alphanumeric/'.$file] = $root.$file; 121 121 } 122 + 122 123 return $map; 123 124 } 124 125 ··· 138 139 $border_seed = $username.'_border'; 139 140 140 141 $pack_key = 141 - PhabricatorHash::digestToRange($pack_seed, 1, $pack_count); 142 + PhabricatorHash::digestToRange($pack_seed, 0, $pack_count - 1); 142 143 $color_key = 143 - PhabricatorHash::digestToRange($color_seed, 1, $color_count); 144 + PhabricatorHash::digestToRange($color_seed, 0, $color_count - 1); 144 145 $border_key = 145 - PhabricatorHash::digestToRange($border_seed, 1, $border_count); 146 + PhabricatorHash::digestToRange($border_seed, 0, $border_count - 1); 146 147 147 148 $pack = $pack_map[$pack_key]; 148 149 $icon = 'alphanumeric/'.$pack.'/'.$file.'.png'; ··· 188 189 ->withFollowSymlinks(false) 189 190 ->find(); 190 191 191 - return $map; 192 + return array_values($map); 192 193 } 193 194 194 195 public static function getBorderMap() {
+3 -2
src/infrastructure/util/PhabricatorHash.php
··· 88 88 } 89 89 90 90 $hash = sha1($string, $raw_output = true); 91 - $value = head(unpack('L', $hash)); 91 + // Make sure this ends up positive, even on 32-bit machines. 92 + $value = head(unpack('L', $hash)) & 0x7FFFFFFF; 92 93 93 - return $min + ($value % ($max - $min)); 94 + return $min + ($value % (1 + $max - $min)); 94 95 } 95 96 96 97