{"record":{"id":"a14b8287e01c8d2e","repo":"microsoft/garnet","slug":"err-value-is-not-an-integer-or-out-of-range-a14b82","errorCode":null,"errorMessage":"ERR value is not an integer or out of range.","messagePattern":"ERR value is not an integer or out of range\\.","errorType":"exception","errorClass":"GarnetException","httpStatus":null,"severity":"error","filePath":"libs/server/Resp/Bitmap/BitmapManagerBitfield.cs","lineNumber":329,"sourceCode":"            if (curr < cend) *curr++ = (byte)((tmp >> 24) & 0xFF);\n            if (curr < cend) *curr++ = (byte)((tmp >> 16) & 0xFF);\n            if (curr < cend) *curr++ = (byte)((tmp >> 8) & 0xFF);\n            if (curr < cend) *curr++ = (byte)((tmp >> 0) & 0xFF);\n        }\n\n        /// <summary>\n        /// Implementation of bitfield GET operation.\n        /// </summary>\n        /// <param name=\"bitmap\"></param>\n        /// <param name=\"bitmapLength\"></param>\n        /// <param name=\"offset\"></param>\n        /// <param name=\"encoding\"></param>\n        /// <param name=\"signed\"></param>\n        /// <returns></returns>\n        private static long GetBitfield(byte* bitmap, long bitmapLength, long offset, byte encoding, bool signed)\n        {\n            if (!TryValidateBitfieldOffset(offset, encoding, multiplyOffset: false, out offset, out var endOffset))\n                throw new GarnetException(\"ERR value is not an integer or out of range.\");\n\n            var byteIndexStart = Index(offset);\n            var byteIndexEnd = Index(endOffset) + 1;\n            var buf = stackalloc byte[8];\n            *(ulong*)buf = 0;\n\n            // Simple case value is beyond current length\n            if (byteIndexStart >= bitmapLength) return 0;\n\n            var vend = bitmap + bitmapLength;\n            var curr = bitmap + byteIndexStart;\n            var cend = bitmap + byteIndexEnd < vend ? (bitmap + byteIndexEnd) : vend;\n            var returnValue = GetValue(ref buf, ref curr, cend, vend, bitmapLength, offset, encoding, signed);\n\n            return returnValue;\n        }\n\n        /// <summary>","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/microsoft/garnet/blob/951b0fc6838721f89d102c2bbe1b914e8d39d700/libs/server/Resp/Bitmap/BitmapManagerBitfield.cs#L311-L347","documentation":"Thrown by GetBitfield when TryValidateBitfieldOffset(offset, encoding, ...) fails - the offset/encoding combination is invalid (zero bit count, negative offset, overflow, or end-offset beyond the 512 MiB-payload bit limit). The message is the standard Redis range error. The BITFIELD command parser already runs the same validation (BitmapCommands.cs) and rejects bad offsets with a RESP error before reaching here, so this throw is a defensive backstop for an internal path that bypassed parsing validation.","triggerScenarios":"GetBitfield is called with an offset/encoding that TryValidateBitfieldOffset rejects (e.g., u0 encoding, negative offset, or #-multiplied offset that overflows past the bitmap limit).","commonSituations":"A client BITFIELD GET with a malformed type (zero width) or an enormous offset; an internal caller invoking GetBitfield directly without the parser's validation.","solutions":["Use a valid encoding (e.g., u8, i16, width 1-64, non-zero).","Keep offsets non-negative and within the bitmap limit; watch #-multiplied offsets.","Update Garnet - older builds routed more cases through this throw."],"exampleFix":"# before\nBITFIELD key GET u0 0          # invalid: zero-width type\n# after\nBITFIELD key GET u8 0","handlingStrategy":"validation","validationCode":"// Validate bitfield encoding + offset before issuing BITFIELD\nif (bitCount < 1 || bitCount > 64) throw new ArgumentException(\"bad bitfield width\");\nif (offset < 0) throw new ArgumentException(\"negative offset\");\n// for #-multiplied: ensure offset*bitCount stays under the 512MiB*8-1 bit limit","typeGuard":null,"tryCatchPattern":"catch (GarnetException ex) when (ex.Message == \"ERR value is not an integer or out of range.\") {\n    return BadRequest(ex.Message); // standard client-side range error\n}","preventionTips":["Validate bitfield type tokens (width 1-64, signed/unsigned) on the client.","Bound #-multiplied offsets against the bitmap size limit."],"tags":["bitmap","bitfield","validation","offset","redis-error"],"backgroundTag":null,"analyzedSha":"951b0fc6838721f89d102c2bbe1b914e8d39d700","analyzedAt":"2026-08-13T19:01:32.939Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}