Skip to content

Commit 2aa8fa3

Browse files
committed
Implement overflow protection during hash calculation
1 parent 7ead60f commit 2aa8fa3

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/TagEdit.pas

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,9 @@ function TTagEdit.RandTagColor(const TagName: string; BrightnessPercent: integer
616616

617617
// Generate stable hash (FNV-1a)
618618
Hash := 2166136267;
619-
for i := 1 to Length(TagName) do
620-
Hash := (Hash xor Ord(TagName[i])) * 16777619;
619+
if TagName <> string.Empty then
620+
for i := 1 to Length(TagName) do
621+
Hash := longword(uint64(Hash xor Ord(TagName[i])) * 16777619);
621622

622623
// Extract RGB components from hash
623624
R := (Hash and $FF);

0 commit comments

Comments
 (0)