Skip to content

Commit

Permalink
Guard against invalid EstimatedSize values
Browse files Browse the repository at this point in the history
Fixes #394
  • Loading branch information
Klocman committed Aug 7, 2022
1 parent eee57a8 commit 1528c2c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions source/UninstallTools/Factory/RegistryFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,16 @@ private static ApplicationUninstallerEntry GetBasicInformation(RegistryKey unins

private static FileSize GetEstimatedSize(RegistryKey uninstallerKey)
{
var tempSize = (int)uninstallerKey.GetValue(RegistryNameEstimatedSize, 0);
return FileSize.FromKilobytes(tempSize);
try
{
// Use Convert.ToInt64 because some applications put a string in here instead of a number
var tempSize = Convert.ToInt64(uninstallerKey.GetValue(RegistryNameEstimatedSize, 0));
return FileSize.FromKilobytes(tempSize);
}
catch (SystemException e) when (e is FormatException or InvalidCastException)
{
return FileSize.Empty;
}
}

private static Guid GetGuid(RegistryKey uninstallerKey)
Expand Down

0 comments on commit 1528c2c

Please sign in to comment.