{"record":{"id":"c6c93a377efac71f","repo":"dotnet/machinelearning","slug":"strings-inconsistentnullbitmapandlength","errorCode":null,"errorMessage":"Strings.InconsistentNullBitMapAndLength","messagePattern":"Strings\\.InconsistentNullBitMapAndLength","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.Data.Analysis/PrimitiveColumnContainer.cs","lineNumber":92,"sourceCode":"                    bitMap.IncreaseSize(bitMapBufferLength);\n\n                    var span = bitMap.Span;\n                    span.Fill(255);\n                    int lastByte = 1 << (length - (bitMapBufferLength - 1) * 8);\n                    span[bitMapBufferLength - 1] = (byte)(lastByte - 1);\n\n                    nullDataFrameBuffer = bitMap;\n                }\n                else\n                {\n                    nullDataFrameBuffer = new DataFrameBuffer<byte>();\n                }\n            }\n            else\n            {\n                if (nullBitMap.Length < bitMapBufferLength)\n                {\n                    throw new ArgumentException(Strings.InconsistentNullBitMapAndLength, nameof(nullBitMap));\n                }\n                nullDataFrameBuffer = new ReadOnlyDataFrameBuffer<byte>(nullBitMap, bitMapBufferLength);\n            }\n            NullBitMapBuffers.Add(nullDataFrameBuffer);\n            Length = length;\n            NullCount = nullCount;\n        }\n\n        public PrimitiveColumnContainer(long length = 0, T? defaulValue = null)\n        {\n            AppendMany(defaulValue, length);\n        }\n\n        public void Resize(long length)\n        {\n            if (length < Length)\n                throw new ArgumentException(Strings.CannotResizeDown, nameof(length));\n            AppendMany(default, length - Length);","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/dotnet/machinelearning/blob/7b76e69cf964daeca3f1377af6bc5543284d56c6/src/Microsoft.Data.Analysis/PrimitiveColumnContainer.cs#L74-L110","documentation":"Microsoft.Data.Analysis throws this ArgumentException when constructing a PrimitiveColumnContainer from a raw Apache Arrow-style null bit map whose byte length is shorter than required for the declared number of rows. The validity bitmap must have at least `bitMapBufferLength` bytes (ceil(length/8) padded per buffer); a shorter buffer would cause out-of-bounds reads when reading validity bits. The parameter name `nullBitMap` is attached to the exception.","triggerScenarios":"Calling the PrimitiveColumnContainer constructor that accepts a prebuilt nullBitMap byte array plus a length, where nullBitMap.Length < bitMapBufferLength (e.g. passing a bitmap computed for fewer rows than the `length` argument, or a bitmap missing Arrow's 8-byte-per-buffer alignment padding).","commonSituations":"Interoperating with Arrow IPC data where the caller miscomputes the bitmap buffer length (forgetting per-record-buffer padding to 64 bytes), deserializing a truncated/older file format, or hand-crafting a bitmap for a subset of rows while claiming the full column length.","solutions":["Compute bitMapBufferLength the same way the library does (padded per MaxCapacity buffer) and ensure nullBitMap.Length >= bitMapBufferLength before constructing.","If the bitmap covers fewer rows, either grow it (allocate a new byte array of the correct size and copy) or reduce the `length` argument to match the bitmap.","Check the producer of the bitmap: truncation during I/O or a version skew in the Arrow serialization is a common cause; re-serialize the source data."],"exampleFix":"// before\ncontainer = new PrimitiveColumnContainer<T>(values, nullBitMap, length: 1000); // bitmap only for 500 rows\n// after\nint bitMapBufferLength = (int)(((length + 63) / 64) * 8); // match library padding\nif (nullBitMap.Length < bitMapBufferLength)\n{\n    var grown = new byte[bitMapBufferLength];\n    Array.Copy(nullBitMap, grown, nullBitMap.Length);\n    nullBitMap = grown;\n}\ncontainer = new PrimitiveColumnContainer<T>(values, nullBitMap, length: 1000);","handlingStrategy":"validation","validationCode":"static bool IsValidNullBitMap(byte[] nullBitMap, long length, long bitMapBufferLength) => nullBitMap != null && nullBitMap.Length >= bitMapBufferLength && length >= 0;","typeGuard":"if (nullBitMap == null || nullBitMap.Length < bitMapBufferLength) return; // reject before constructing container","tryCatchPattern":"try { var c = new PrimitiveColumnContainer<T>(values, nullBitMap, length); }\ncatch (ArgumentException ex) when (ex.ParamName == \"nullBitMap\")\n{\n    // grow or recompute the bitmap, then retry\n}","preventionTips":["Derive bitmap buffer length from the same formula the library uses, including padding","Never cache bitmaps across datasets with different row counts","Validate bitmap length immediately after deserializing Arrow buffers","Add a unit test round-tripping containers through their raw bitmap representation"],"tags":["argumentexception","null-bitmap","arrow","dataframe"],"backgroundTag":"invalid-argument-value","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"}