{"record":{"id":"bcd698428d195635","repo":"microsoft/FASTER","slug":"size-0-is-not-32-bit","errorCode":null,"errorMessage":"Size {0} is not 32-bit","messagePattern":"Size (.+?) is not 32-bit","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"cs/src/core/Index/FASTER/FASTERBase.cs","lineNumber":404,"sourceCode":"            if (state[version].tableHandle.IsAllocated)\n                state[version].tableHandle.Free();\n#endif\n        }\n\n        /// <summary>\n        /// Initialize\n        /// </summary>\n        /// <param name=\"size\"></param>\n        /// <param name=\"sector_size\"></param>\n        public void Initialize(long size, int sector_size)\n        {\n            if (!Utility.IsPowerOfTwo(size))\n            {\n                throw new ArgumentException(\"Size {0} is not a power of 2\");\n            }\n            if (!Utility.Is32Bit(size))\n            {\n                throw new ArgumentException(\"Size {0} is not 32-bit\");\n            }\n\n            minTableSize = size;\n            resizeInfo = default;\n            resizeInfo.status = ResizeOperationStatus.DONE;\n            resizeInfo.version = 0;\n            Initialize(resizeInfo.version, size, sector_size);\n        }\n\n        /// <summary>\n        /// Initialize\n        /// </summary>\n        /// <param name=\"version\"></param>\n        /// <param name=\"size\"></param>\n        /// <param name=\"sector_size\"></param>\n        internal void Initialize(int version, long size, int sector_size)\n        {\n            long size_bytes = size * sizeof(HashBucket);","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/microsoft/FASTER/blob/321d872eabda6a0345c8bd76419f89723ed864ae/cs/src/core/Index/FASTER/FASTERBase.cs#L386-L422","documentation":"FASTER's hash table size must be both a power of 2 and representable so that index arithmetic fits in 32 bits; this check in FASTERBase verifies Utility.Is32Bit(size). The library throws ArgumentException because a size violating this invariant cannot be used as the index table size. It is a constructor-argument validation failure, thrown before any store state is created.","triggerScenarios":"Calling the FasterKV/index constructor (Initialize size path in FASTERBase.cs) with a size that is a power of 2 but exceeds the 32-bit constraint (e.g. size >= 2^31 or values whose derived table size overflows int).","commonSituations":"Configuring very large in-memory indexes (e.g. '1:1' memory sizing with a huge entry count) or computing size programmatically from available memory and passing a long that exceeds the 32-bit limit.","solutions":["Reduce the index size argument so Utility.Is32Bit(size) holds (size below the 2^31 boundary).","Check size with Utility.Is32Bit(size) && Utility.IsPowerOfTwo(size) before constructing the store.","If a larger index is required, use multiple store instances or overflow to disk (ReadCopyOptions/segments) instead of one oversized index."],"exampleFix":"// before\nvar store = new FasterKV<long, long>(1L << 40);\n// after\nlong size = 1L << 28; // power of 2 and 32-bit safe\nif (!Utility.Is32Bit(size) || !Utility.IsPowerOfTwo(size))\n    throw new InvalidOperationException(\"Index size must be a 32-bit power of 2\");\nvar store = new FasterKV<long, long>(size);","handlingStrategy":"validation","validationCode":"long size = /* configured index size */;\nif (!Utility.IsPowerOfTwo(size) || !Utility.Is32Bit(size))\n    throw new ArgumentException($\"Index size {size} must be a power of 2 and 32-bit representable\");\nvar store = new FasterKV<long, long>(size);","typeGuard":"bool IsValidIndexSize(long size) => size > 0 && Utility.IsPowerOfTwo(size) && Utility.Is32Bit(size);","tryCatchPattern":"try { store = new FasterKV<long, long>(size); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"not 32-bit\") || ex.Message.Contains(\"power of 2\"))\n{ logger.LogError(ex, \"Invalid index size {Size}\", size); throw new ConfigurationException(\"Index size must be a 32-bit power of 2\", ex); }","preventionTips":["Clamp user-supplied index sizes to a known-safe maximum (e.g. 2^28) in configuration code.","Always validate IsPowerOfTwo and Is32Bit before constructing FasterKV.","Document the 32-bit sizing constraint next to the config key that feeds index size."],"tags":["faster","configuration","argument-validation","csharp"],"backgroundTag":"invalid-argument-value","analyzedSha":"321d872eabda6a0345c8bd76419f89723ed864ae","analyzedAt":"2026-09-15T22:18:00.693Z","contentChangedAt":"2026-09-15T22:18:00.693Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}