{"record":{"id":"223abe0bd0bbcdaa","repo":"peass-ng/PEASS-ng","slug":"the-flag-value-has-more-than-a-single-bit-set","errorCode":null,"errorMessage":"The flag value has more than a single bit set.","messagePattern":"The flag value has more than a single bit set\\.","errorType":"exception","errorClass":"ArithmeticException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/TaskScheduler/EnumUtil.cs","lineNumber":41,"sourceCode":"            {\n                var allFlags = 0L;\n                foreach (T flag in Enum.GetValues(typeof(T)))\n                    allFlags |= Convert.ToInt64(flag);\n                if ((allFlags & Convert.ToInt64(value)) != 0L)\n                    return;\n            }\n            else if (Enum.IsDefined(typeof(T), value))\n                return;\n            throw new InvalidEnumArgumentException(argName ?? \"value\", Convert.ToInt32(value), typeof(T));\n        }\n\n        public static byte BitPosition<T>(this T flags) where T : struct, IConvertible\n        {\n            CheckIsEnum<T>(true);\n            var flagValue = Convert.ToInt64(flags);\n            if (flagValue == 0) throw new ArgumentException(\"The flag value is zero and has no bit position.\");\n            var r = Math.Log(flagValue, 2);\n            if (r % 1 > 0) throw new ArithmeticException(\"The flag value has more than a single bit set.\");\n            return Convert.ToByte(r);\n        }\n\n        public static bool IsFlagSet<T>(this T flags, T flag) where T : struct, IConvertible\n        {\n            CheckIsEnum<T>(true);\n            var flagValue = Convert.ToInt64(flag);\n            return (Convert.ToInt64(flags) & flagValue) == flagValue;\n        }\n\n        public static bool IsValidFlagValue<T>(this T flags) where T : struct, IConvertible\n        {\n            CheckIsEnum<T>(true);\n            var found = 0L;\n            foreach (T flag in Enum.GetValues(typeof(T)))\n            {\n                if (flags.IsFlagSet(flag))\n                    found |= Convert.ToInt64(flag);","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/TaskScheduler/EnumUtil.cs#L23-L59","documentation":"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.","triggerScenarios":"Thrown at winPEAS/winPEASexe/winPEAS/TaskScheduler/EnumUtil.cs:41 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}