{"record":{"id":"fe351474524db897","repo":"peass-ng/PEASS-ng","slug":"invalid-offset-and-or-length-specified","errorCode":null,"errorMessage":"invalid offset and/or length specified","messagePattern":"invalid offset and/or length specified","errorType":"exception","errorClass":"IndexOutOfRangeException","httpStatus":null,"severity":"error","filePath":"winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/util/encoders/HexEncoder.cs","lineNumber":221,"sourceCode":"                }\n\n                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;","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/peass-ng/PEASS-ng/blob/53fb989abc2219826385683a6fee826bd6cd38d6/winPEAS/winPEASexe/winPEAS/3rdParty/BouncyCastle/util/encoders/HexEncoder.cs#L203-L239","documentation":"HexEncoder.DecodeStrict throws IndexOutOfRangeException with 'invalid offset and/or length specified' when off < 0, len < 0, or off > str.Length - len — i.e. the requested slice [off, off+len) falls outside the string. This guards the offset/length pair before any table lookups.","triggerScenarios":"Calling strict decode with off < 0, a negative len, or off+len exceeding the string length (e.g. off computed from a previous parse, or len taken from a length header larger than the actual data).","commonSituations":"Parsing framing protocols where a length field is corrupt or misinterpreted (endianness mismatch); off-by-one on offsets; reusing offsets after string mutation/trimming.","solutions":["Validate off >= 0, len >= 0 and off + len <= str.Length before calling.","Recompute the slice bounds from the actual string length rather than a trusted header.","Clamp or trim len to str.Length - off when the input may be shorter than declared."],"exampleFix":"// before\nvar bytes = DecodeStrict(s, off, len); // off+len > s.Length\n// after\nif (off < 0 || len < 0 || off > s.Length - len)\n    throw new ArgumentOutOfRangeException(nameof(off), \"slice out of bounds\");\nvar bytes = DecodeStrict(s, off, len);","handlingStrategy":"validation","validationCode":"bool sliceValid = off >= 0 && len >= 0 && off <= str.Length - len;","typeGuard":"static bool InBounds(string s, int off, int len) => s != null && off >= 0 && len >= 0 && off <= s.Length - len;","tryCatchPattern":"try { DecodeStrict(s, off, len); } catch (IndexOutOfRangeException ex) when (ex.Message.Contains(\"invalid offset\")) { /* re-parse framing */ }","preventionTips":["Always compute len from the actual string length","Distrust length headers; clamp to available bytes","Write unit tests for boundary offsets (0, off+1, len-1)"],"tags":["csharp","bounds","argument","hex"],"backgroundTag":"argument-out-of-range","analyzedSha":"53fb989abc2219826385683a6fee826bd6cd38d6","analyzedAt":"2026-09-02T04:25:09.259Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T11:17:12.671Z"}