{"record":{"id":"4f635e940ec14594","repo":"peass-ng/PEASS-ng","slug":"a-hexadecimal-encoding-must-have-an-even-number-of","errorCode":null,"errorMessage":"a hexadecimal encoding must have an even number of characters","messagePattern":"a hexadecimal encoding must have an even number of characters","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/util/encoders/HexEncoder.cs","lineNumber":223,"sourceCode":"                length++;\n            }\n\n            if (bufOff > 0)\n            {\n                outStream.Write(buf, 0, bufOff);\n            }\n\n            return length;\n        }\n\n        internal byte[] DecodeStrict(string str, int off, int len)\n        {\n            if (null == str)\n                throw new ArgumentNullException(\"str\");\n            if (off < 0 || len < 0 || off > (str.Length - len))\n                throw new IndexOutOfRangeException(\"invalid offset and/or length specified\");\n            if (0 != (len & 1))\n                throw new ArgumentException(\"a hexadecimal encoding must have an even number of characters\", \"len\");\n\n            int resultLen = len >> 1;\n            byte[] result = new byte[resultLen];\n\n            int strPos = off;\n            for (int i = 0; i < resultLen; ++i)\n            {\n                byte b1 = decodingTable[str[strPos++]];\n                byte b2 = decodingTable[str[strPos++]];\n\n                if ((b1 | b2) >= 0x80)\n                    throw new IOException(\"invalid characters encountered in Hex data\");\n\n                result[i] = (byte)((b1 << 4) | b2);\n            }\n            return result;\n        }\n    }","sourceCodeStart":205,"sourceCodeEnd":241,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/util/encoders/HexEncoder.cs#L205-L241","documentation":"HexEncoder.DecodeStrict requires the decoded region to contain an even number of characters because hex encodes two characters per byte. A odd len throws ArgumentException('a hexadecimal encoding must have an even number of characters', 'len').","triggerScenarios":"Calling strict decode with an odd len value — e.g. slicing a hex string at the wrong boundary, or the source string itself has odd length (truncated hex).","commonSituations":"Truncated hex from cut-and-paste or log truncation; string slicing with off-by-one; a leading '0x' stripped only partially leaving odd count.","solutions":["Check len % 2 == 0 (and the underlying string length parity) before decoding.","Fix the slice computation so off/len land on 2-character byte boundaries.","If the source is truncated, re-fetch or repair the data instead of decoding half a byte.","Strip prefixes/suffixes (0x, whitespace) so the remaining character count is even."],"exampleFix":"// before\nDecodeStrict(s, 0, s.Length); // s.Length == 11 -> throws\n// after\nif (s.Length % 2 != 0) throw new FormatException(\"odd-length hex\");\nDecodeStrict(s, 0, s.Length);","handlingStrategy":"validation","validationCode":"if ((len & 1) != 0 || off + len > str.Length) throw new FormatException(\"hex slice must be even-length and in bounds\");","typeGuard":"static bool IsEvenHexSlice(string s, int off, int len) => off >= 0 && len >= 0 && (len & 1) == 0 && off + len <= s.Length;","tryCatchPattern":"try { DecodeStrict(s, off, len); } catch (ArgumentException ex) when (ex.ParamName == \"len\") { padOrRejectInput(); }","preventionTips":["Check parity of hex strings at ingestion","Fix slicing so offsets advance in steps of 2","Reject or repair truncated hex at the source"],"tags":["csharp","hex","encoding","argument"],"backgroundTag":"odd-length-hex-string","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}