peass-ng/PEASS-ng · error · ArithmeticException
The flag value has more than a single bit set.
Error message
The flag value has more than a single bit set.
What it means
BitPosition<T> throws InvalidEnumArgumentException stating more than a single bit is set when the supplied flags value has multiple bits (e.g. 0x3). The method is only meaningful for a single-bit flag, so a multi-bit combination is the invalid input; the check runs after CheckIsEnum<T>(true) confirms T is a [Flags] enum.
Source
Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/EnumUtil.cs:41
{
var allFlags = 0L;
foreach (T flag in Enum.GetValues(typeof(T)))
allFlags |= Convert.ToInt64(flag);
if ((allFlags & Convert.ToInt64(value)) != 0L)
return;
}
else if (Enum.IsDefined(typeof(T), value))
return;
throw new InvalidEnumArgumentException(argName ?? "value", Convert.ToInt32(value), typeof(T));
}
public static byte BitPosition<T>(this T flags) where T : struct, IConvertible
{
CheckIsEnum<T>(true);
var flagValue = Convert.ToInt64(flags);
if (flagValue == 0) throw new ArgumentException("The flag value is zero and has no bit position.");
var r = Math.Log(flagValue, 2);
if (r % 1 > 0) throw new ArithmeticException("The flag value has more than a single bit set.");
return Convert.ToByte(r);
}
public static bool IsFlagSet<T>(this T flags, T flag) where T : struct, IConvertible
{
CheckIsEnum<T>(true);
var flagValue = Convert.ToInt64(flag);
return (Convert.ToInt64(flags) & flagValue) == flagValue;
}
public static bool IsValidFlagValue<T>(this T flags) where T : struct, IConvertible
{
CheckIsEnum<T>(true);
var found = 0L;
foreach (T flag in Enum.GetValues(typeof(T)))
{
if (flags.IsFlagSet(flag))
found |= Convert.ToInt64(flag);View on GitHub (pinned to 53fb989abc)
Solutions
- Ensure the value has exactly one bit set (e.g. value != 0 && (value & (value - 1)) == 0) before calling.
- Iterate over individual flags and call BitPosition per flag instead of on combinations.
- Catch InvalidEnumArgumentException and decompose the multi-bit value manually if combinations are expected.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/EnumUtil.cs:41 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of peass-ng/PEASS-ng@53fb989abc (2026-09-02).
Data as JSON: /api/errors/223abe0bd0bbcdaa.
Report an issue: GitHub.