{"record":{"id":"8442085e3a9a055f","repo":"peass-ng/PEASS-ng","slug":"asn-1-enumerated-out-of-int-range","errorCode":null,"errorMessage":"ASN.1 Enumerated out of int range","messagePattern":"ASN\\.1 Enumerated out of int range","errorType":"validation","errorClass":"ArithmeticException","httpStatus":null,"severity":"warning","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerEnumerated.cs","lineNumber":109,"sourceCode":"        {\n            get { return new BigInteger(bytes); }\n        }\n\n        public bool HasValue(BigInteger x)\n        {\n            return null != x\n                // Fast check to avoid allocation\n                && DerInteger.IntValue(bytes, start, DerInteger.SignExtSigned) == x.IntValue\n                && Value.Equals(x);\n        }\n\n        public int IntValueExact\n        {\n            get\n            {\n                int count = bytes.Length - start;\n                if (count > 4)\n                    throw new ArithmeticException(\"ASN.1 Enumerated out of int range\");\n\n                return DerInteger.IntValue(bytes, start, DerInteger.SignExtSigned);\n            }\n        }\n\n        internal override void Encode(DerOutputStream derOut)\n        {\n            derOut.WriteEncoded(Asn1Tags.Enumerated, bytes);\n        }\n\n        protected override bool Asn1Equals(Asn1Object asn1Object)\n        {\n            DerEnumerated other = asn1Object as DerEnumerated;\n            if (other == null)\n                return false;\n\n            return Arrays.AreEqual(this.bytes, other.bytes);\n        }","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerEnumerated.cs#L91-L127","documentation":"IntValueExact returns the enumerated value as an int and throws ArithmeticException (not ArgumentException) when the magnitude requires more than 4 content bytes, since it cannot fit in an int without truncation. This is a deliberate lossless-conversion guard.","triggerScenarios":"Calling derEnumerated.IntValueExact on an ENUMERATED whose encoded length (bytes.Length - start) exceeds 4 bytes, e.g. a maliciously or mistakenly oversized enumerated in a parsed certificate.","commonSituations":"Parsing untrusted PKI data containing absurdly large ENUMERATED encodings; assuming enumerated values are small ints while an encoder wrote a big-number encoding.","solutions":["Use the Value property (BigInteger) instead of IntValueExact when large values are possible","Check (bytes.Length - start) <= 4 / check Value.BitLength before calling IntValueExact","Reject out-of-range values as invalid input since legal enumerations are small","Catch ArithmeticException and fall back to BigInteger handling"],"exampleFix":"// before\nint v = enumerated.IntValueExact;\n// after\nBigInteger big = enumerated.Value;\nif (!big.fitsInt) /* handle */ else int v = enumerated.IntValueExact;","handlingStrategy":"try-catch","validationCode":"bool fitsInt = (enumerated.bytes.Length - enumerated.start) <= 4; // or check enumerated.Value via BigInteger range","typeGuard":null,"tryCatchPattern":"try { int v = enumerated.IntValueExact; }\ncatch (ArithmeticException) { BigInteger big = enumerated.Value; /* handle big value */ }","preventionTips":["Prefer .Value (BigInteger) for untrusted input","Check bit length <= 31 before IntValueExact","Bound input sizes when parsing untrusted PKI data","Treat oversized enumerateds as protocol violations"],"tags":["asn1","bouncycastle","enumerated","arithmeticexception","overflow"],"backgroundTag":"asn1-value-out-of-range","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}