{"record":{"id":"773b2ed62a6760fc","repo":"k3s-io/k3s","slug":"fields-for-file-s-d-smaller-than-required-inde","errorCode":null,"errorMessage":"fields for file %s (%d) smaller than required index (key: %d, val: %d)","messagePattern":"fields for file (.+?) \\((.+?)\\) smaller than required index \\(key: (.+?), val: (.+?)\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/dataverify/dataverify.go","lineNumber":99,"sourceCode":"\t}\n\treturn nil\n}\n\nfunc fileMapFields(fileName string, key, val int) (map[string]string, error) {\n\tfile, err := os.Open(fileName)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer file.Close()\n\tresult := map[string]string{}\n\tscanner := bufio.NewScanner(file)\n\tfor scanner.Scan() {\n\t\tfields := strings.Fields(scanner.Text())\n\t\tif len(fields) == 0 {\n\t\t\tcontinue\n\t\t}\n\t\tif len(fields) <= key || len(fields) <= val {\n\t\t\treturn nil, fmt.Errorf(\"fields for file %s (%d) smaller than required index (key: %d, val: %d)\", fileName, len(fields), key, val)\n\t\t}\n\t\tresult[fields[key]] = fields[val]\n\t}\n\treturn result, scanner.Err()\n}\n\nfunc sha256Sum(filePath string) (string, error) {\n\tfile, err := os.Open(filePath)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tdefer file.Close()\n\thash := sha256.New()\n\tif _, err := io.Copy(hash, file); err != nil {\n\t\treturn \"\", err\n\t}\n\treturn hex.EncodeToString(hash.Sum(nil)), nil\n}","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/k3s-io/k3s/blob/6ba341e396edc16b8dcae978a7c5e3ac7ee5606e/pkg/dataverify/dataverify.go#L81-L117","documentation":"fileMapFields splits each non-blank line of .sha256sums (key index 1, val index 0) or .links (key 0, val 1) on whitespace. A non-empty line with fewer fields than the required indices - i.e. a single bare token instead of '<a> <b>' - aborts parsing with this error naming the file and the field count.","triggerScenarios":"A malformed line in .sha256sums or .links inside the extracted bundle: a lone hash with no filename, or a lone path with no target (pkg/dataverify/dataverify.go:91-100).","commonSituations":"Hand-edited or hand-regenerated manifest where a line lost its second column; concatenation of files with headers/footers; encoding issues that remove the separating whitespace; wrapping that split one entry across lines.","solutions":["Inspect the named file and fix or remove the malformed line - every entry must have exactly the two whitespace-separated columns (sum + path, or link + target).","Regenerate the sums file properly: `cd <dir> && sha256sum $(cat .sha256sums | awk '{print $2}') > .sha256sums` rather than editing by hand.","For a shipped k3s bundle, do not repair it - delete <data-dir>/data/<version>-tmp and reinstall/re-extract so the original manifests are restored."],"exampleFix":"# before (.sha256sums contains a bare token line)\n1f0e...dad  kubectl\ne38ad2...(no filename)\n\n# after\n1f0e...dad  kubectl\ne38ad214943...91f  containerd","handlingStrategy":"validation","validationCode":"// Validate manifest line shape before use:\nfunc validManifest(fileName string, key, val int) error {\n    sc := bufio.NewScanner(mustOpen(fileName))\n    for sc.Scan() {\n        f := strings.Fields(sc.Text())\n        if len(f) == 0 { continue }\n        if len(f) <= key || len(f) <= val {\n            return fmt.Errorf(\"malformed line in %s: %q\", fileName, sc.Text())\n        }\n    }\n    return sc.Err()\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate .sha256sums with the sha256sum tool, never by hand.","Never concatenate logs or headers into checksum/link manifests.","Treat a manifest parse failure as a broken artifact: re-extract, don't patch."],"tags":["integrity","parsing","sha256","manifest"],"backgroundTag":null,"analyzedSha":"6ba341e396edc16b8dcae978a7c5e3ac7ee5606e","analyzedAt":"2026-08-15T16:27:54.286Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}