{"record":{"id":"9975bb18036331c5","repo":"getsops/sops","slug":"threshold-cannot-exceed-255","errorCode":null,"errorMessage":"threshold cannot exceed 255","messagePattern":"threshold cannot exceed 255","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shamir/shamir.go","lineNumber":206,"sourceCode":"\n// Split takes an arbitrarily long secret and generates a `parts`\n// number of shares, `threshold` of which are required to reconstruct\n// the secret. The parts and threshold must be at least 2, and less\n// than 256. The returned shares are each one byte longer than the secret\n// as they attach a tag used to reconstruct the secret.\nfunc Split(secret []byte, parts, threshold int) ([][]byte, error) {\n\t// Sanity check the input\n\tif parts < threshold {\n\t\treturn nil, fmt.Errorf(\"parts cannot be less than threshold\")\n\t}\n\tif parts > 255 {\n\t\treturn nil, fmt.Errorf(\"parts cannot exceed 255\")\n\t}\n\tif threshold < 2 {\n\t\treturn nil, fmt.Errorf(\"threshold must be at least 2\")\n\t}\n\tif threshold > 255 {\n\t\treturn nil, fmt.Errorf(\"threshold cannot exceed 255\")\n\t}\n\tif len(secret) == 0 {\n\t\treturn nil, fmt.Errorf(\"cannot split an empty secret\")\n\t}\n\n\t// Allocate the output array, initialize the final byte\n\t// of the output with the offset. The representation of each\n\t// output is {y1, y2, .., yN, x}.\n\tout := make([][]byte, parts)\n\tfor idx := range out {\n\t\t// Store the x coordinate for each part as its last byte\n\t\t// Add 1 to the xCoordinate because if the x coordinate is 0,\n\t\t// then the result of evaluating the polynomial at that point\n\t\t// will be our secret\n\t\tout[idx] = make([]byte, len(secret)+1)\n\t\tout[idx][len(secret)] = uint8(idx) + 1\n\t}\n","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/getsops/sops/blob/13442bb98183887d7a9ac09ec8ab0564673a59d8/shamir/shamir.go#L188-L224","documentation":"Like parts, the threshold is encoded in the polynomial degree and share tags as a single byte, so it cannot exceed 255. Split() rejects larger thresholds.","triggerScenarios":"Calling Split(secret, parts, threshold) with threshold > 255 (and implicitly parts >= threshold > 255).","commonSituations":"Very large quorums computed from cluster size, or validation done only on parts but not threshold.","solutions":["Reduce threshold to <= 255 (and to <= parts).","Validate both parts and threshold ranges at the call site.","Use multiple independent splits for larger quorum schemes."],"exampleFix":"// before\nshares, err := shamir.Split(secret, 400, 300)\n// after\nshares, err := shamir.Split(secret, 255, 128)","handlingStrategy":"validation","validationCode":"if threshold > 255 {\n    return fmt.Errorf(\"threshold must be <= 255, got %d\", threshold)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate both parts and threshold against the 1..255 range","Cap quorum settings in configuration schema"],"tags":["shamir","validation","limits","go"],"backgroundTag":"shamir-split-invalid-args","analyzedSha":"13442bb98183887d7a9ac09ec8ab0564673a59d8","analyzedAt":"2026-09-01T03:53:00.447Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}