From c56d2c1bbe9e9cada98128a30f777b685d5bdb3e Mon Sep 17 00:00:00 2001 From: atlimit8 Date: Wed, 18 May 2022 23:08:30 -0500 Subject: [PATCH] fix possible underflow in BlowfishKeyProvider.LenBigNum() --- OpenRA.Mods.Cnc/FileFormats/BlowfishKeyProvider.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/OpenRA.Mods.Cnc/FileFormats/BlowfishKeyProvider.cs b/OpenRA.Mods.Cnc/FileFormats/BlowfishKeyProvider.cs index d4ef9f3116..fe93870613 100644 --- a/OpenRA.Mods.Cnc/FileFormats/BlowfishKeyProvider.cs +++ b/OpenRA.Mods.Cnc/FileFormats/BlowfishKeyProvider.cs @@ -90,8 +90,14 @@ namespace OpenRA.Mods.Cnc.FileFormats static uint LenBigNum(uint[] n, uint len) { - var i = len - 1; - while (n[i] == 0) i--; + if (len == 0) + return 0; + + var i = len; + while (n[--i] == 0) + if (i == 0) + return 0; // all zero + return i + 1; }