{"record":{"id":"8a066e3eb663c18e","repo":"peass-ng/PEASS-ng","slug":"enumerated-has-zero-length","errorCode":null,"errorMessage":"ENUMERATED has zero length","messagePattern":"ENUMERATED has zero length","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerEnumerated.cs","lineNumber":141,"sourceCode":"            if (other == null)\n                return false;\n\n            return Arrays.AreEqual(this.bytes, other.bytes);\n        }\n\n        protected override int Asn1GetHashCode()\n        {\n            return Arrays.GetHashCode(bytes);\n        }\n\n        private static readonly DerEnumerated[] cache = new DerEnumerated[12];\n\n        internal static DerEnumerated FromOctetString(byte[] enc)\n        {\n            if (enc.Length > 1)\n                return new DerEnumerated(enc);\n            if (enc.Length == 0)\n                throw new ArgumentException(\"ENUMERATED has zero length\", \"enc\");\n\n            int value = enc[0];\n            if (value >= cache.Length)\n                return new DerEnumerated(enc);\n\n            DerEnumerated possibleMatch = cache[value];\n            if (possibleMatch == null)\n            {\n                cache[value] = possibleMatch = new DerEnumerated(enc);\n            }\n            return possibleMatch;\n        }\n    }\n}\n","sourceCodeStart":123,"sourceCodeEnd":156,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/asn1/DerEnumerated.cs#L123-L156","documentation":"DerEnumerated.FromOctetString builds a DerEnumerated from raw OCTET STRING bytes and requires at least one byte of content, because a valid ASN.1 ENUMERATED value always encodes at least one octet. An empty byte array carries no value, so the library throws ArgumentException instead of producing a meaningless zero-length DER object.","triggerScenarios":"Calling DerEnumerated.FromOctetString with a zero-length byte array, typically the content octets extracted from a decoded ASN.1 object.","commonSituations":"Parsing malformed or truncated DER/BER data where an ENUMERATED element's content bytes were lost; hand-crafted byte arrays passed directly to FromOctetString; decoders that strip content from empty-value elements.","solutions":["Verify the byte array is non-empty before calling FromOctetString: if (enc == null || enc.Length == 0) handle or reject it","Regenerate or re-fetch the source data — a zero-length ENUMERATED indicates corrupt/truncated input","If treating empty as an error is wrong for your protocol, construct DerEnumerated via a different constructor with a valid long/int value"],"exampleFix":"// before\nDerEnumerated val = DerEnumerated.FromOctetString(contentBytes);\n// after\nif (contentBytes == null || contentBytes.Length == 0)\n    throw new FormatException(\"ENUMERATED content is empty\");\nDerEnumerated val = DerEnumerated.FromOctetString(contentBytes);","handlingStrategy":"validation","validationCode":"if (enc == null || enc.Length == 0)\n    throw new FormatException(\"ENUMERATED content octets are empty\");\nDerEnumerated val = DerEnumerated.FromOctetString(enc);","typeGuard":"static bool IsValidEnumeratedBytes(byte[] enc) => enc != null && enc.Length > 0;","tryCatchPattern":"try { var val = DerEnumerated.FromOctetString(enc); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"zero length\")) {\n    // treat input as malformed ASN.1\n}","preventionTips":["Never pass byte[] content extracted from empty-valued ASN.1 elements straight to FromOctetString","Validate content octets when writing custom DER parsers","Prefer DerEnumerated.GetInstance(Asn1Object) over raw byte constructors when possible"],"tags":["asn1","bouncycastle","argument-validation","der-encoding"],"backgroundTag":"invalid-asn1-encoding","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}