{"record":{"id":"00ebbaf6e4edb8c0","repo":"dotnet/machinelearning","slug":"index","errorCode":null,"errorMessage":"index","messagePattern":"index","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/DataFrameColumns/ArrowStringDataFrameColumn.cs","lineNumber":79,"sourceCode":"            _offsetsBuffers.Add(offsetBuffer);\n            _nullBitMapBuffers.Add(nullBitMapBuffer);\n\n            _nullCount = nullCount;\n        }\n\n        private long _nullCount;\n\n        /// <inheritdoc/>\n        public override long NullCount => _nullCount;\n\n        /// <inheritdoc/>\n        public override bool IsValid(long index) => NullCount == 0 || GetValidityBit(index);\n\n        private bool GetValidityBit(long index)\n        {\n            if ((ulong)index > (ulong)Length)\n            {\n                throw new ArgumentOutOfRangeException(nameof(index));\n            }\n            // First find the right bitMapBuffer\n            int bitMapIndex = GetBufferIndexContainingRowIndex(index, out int indexInBuffer);\n            Debug.Assert(_nullBitMapBuffers.Count > bitMapIndex);\n            ReadOnlyDataFrameBuffer<byte> bitMapBuffer = _nullBitMapBuffers[bitMapIndex];\n            int bitMapBufferIndex = (int)((uint)index / 8);\n            Debug.Assert(bitMapBuffer.Length > bitMapBufferIndex);\n            byte curBitMap = bitMapBuffer[bitMapBufferIndex];\n            return ((curBitMap >> (indexInBuffer & 7)) & 1) != 0;\n        }\n\n        private void SetValidityBit(long index, bool value)\n        {\n            if ((ulong)index > (ulong)Length)\n            {\n                throw new ArgumentOutOfRangeException(nameof(index));\n            }\n            // First find the right bitMapBuffer","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/DataFrameColumns/ArrowStringDataFrameColumn.cs#L61-L97","documentation":"GetValidityBit, called from IsValid(index), throws ArgumentOutOfRangeException(nameof(index)) when index is negative or greater than Length. The validity (null) bitmap can only be queried for existing row positions. The bound check uses (ulong)index > (ulong)Length, so both negative and too-large indices are rejected.","triggerScenarios":"Calling column.IsValid(index) (directly or via null-check logic) with index < 0 or index > Length — e.g. iterating to Length inclusive, using a row count from a different column, or checking validity before the column is fully appended.","commonSituations":"Off-by-one loops (for i = 0; i <= col.Length; i++); cross-referencing rows of two columns with different lengths; computed indices from a stale snapshot after the column was truncated.","solutions":["Clamp/verify the index: only call IsValid for 0 <= index < Length (or <= Length as the implementation permits).","Fix loop bounds to use '< Length' instead of '<= Length'.","Use the same column instance to derive iteration bounds rather than another column's length.","Check NullCount first — IsValid short-circuits to true when NullCount == 0, so guard with if (col.NullCount == 0 || (uint)index < (ulong)col.Length)."],"exampleFix":"// before\nfor (long i = 0; i <= column.Length; i++) Use(column.IsValid(i)); // throws at i == Length boundary misuse\n\n// after\nfor (long i = 0; i < column.Length; i++) Use(column.IsValid(i));","handlingStrategy":"validation","validationCode":"bool canCheck = index >= 0 && index <= column.Length;\nif (canCheck) bool valid = column.IsValid(index);","typeGuard":"static bool InRange(ArrowStringDataFrameColumn c, long i) => (ulong)i <= (ulong)c.Length;","tryCatchPattern":"try { ok = column.IsValid(i); }\ncatch (ArgumentOutOfRangeException) { ok = false; /* treat as out of bounds */ }","preventionTips":["Use i < Length in loops, never i <= Length","Derive bounds from the same column instance","Short-circuit on NullCount == 0","Clamp external indices before querying"],"tags":["dotnet","dataframe","argument-out-of-range","indexing"],"backgroundTag":"index-out-of-range","analyzedSha":"7b76e69cf964daeca3f1377af6bc5543284d56c6","analyzedAt":"2026-09-11T12:35:38.930Z","contentChangedAt":"2026-09-11T12:35:38.930Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}