{"record":{"id":"01251127b69b5720","repo":"getsops/sops","slug":"parts-cannot-exceed-255","errorCode":null,"errorMessage":"parts cannot exceed 255","messagePattern":"parts cannot exceed 255","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shamir/shamir.go","lineNumber":200,"sourceCode":"// add combines two numbers in GF(2^8)\n// This can also be used for subtraction since it is symmetric.\nfunc add(a, b uint8) uint8 {\n\t// Addition in GF(2^8) equals XOR:\n\treturn a ^ b\n}\n\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,","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/getsops/sops/blob/13442bb98183887d7a9ac09ec8ab0564673a59d8/shamir/shamir.go#L182-L218","documentation":"Split() internally stores each share's x-coordinate in a single byte, so the total number of parts is capped at 255. Requesting more parts than a byte can index is rejected.","triggerScenarios":"Calling Split(secret, parts, threshold) with parts > 255, e.g. Split(secret, 300, 5).","commonSituations":"Mass-distributing shares to hundreds of nodes, misconfigured replica counts, or a parts value read from user input without bounds checking.","solutions":["Reduce parts to <= 255; split into multiple independent shards if more are needed.","Validate the parts value before calling Split.","Re-architect to nested splitting (split shares again) if >255 holders are truly required."],"exampleFix":"// before\nshares, err := shamir.Split(secret, 300, 5)\n// after\nif parts > 255 { parts = 255 }\nshares, err := shamir.Split(secret, parts, 5)","handlingStrategy":"validation","validationCode":"if parts > 255 {\n    return fmt.Errorf(\"parts must be <= 255, got %d\", parts)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cap distribution lists at 255 shares","Validate numeric config inputs against library limits","Remember the 1-byte x-coordinate design constraint"],"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"}