{"record":{"id":"8d31c3c42e9005b4","repo":"kubernetes/kops","slug":"unhandled-sha-length-for-q","errorCode":null,"errorMessage":"unhandled sha length for %q","messagePattern":"unhandled sha length for %q","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/assets/assetcopy/copyfile.go","lineNumber":54,"sourceCode":"type CopyFile struct {\n\tName       string\n\tSourceFile string\n\tTargetFile string\n\tSHA        string\n\tVFSContext *vfs.VFSContext\n\tCluster    *kops.Cluster\n}\n\n// fileExtensionForSHA returns the expected extension for the given hash\n// If the hash length is not recognized, it returns an error.\nfunc fileExtensionForSHA(sha string) (string, error) {\n\tswitch len(sha) {\n\tcase 40:\n\t\treturn \".sha1\", nil\n\tcase 64:\n\t\treturn \".sha256\", nil\n\tdefault:\n\t\treturn \"\", fmt.Errorf(\"unhandled sha length for %q\", sha)\n\t}\n}\n\nfunc (e *CopyFile) Run() error {\n\tctx := context.TODO()\n\n\texpectedSHA := strings.TrimSpace(e.SHA)\n\n\tshaExtension, err := fileExtensionForSHA(expectedSHA)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\ttargetSHAFile := e.TargetFile + shaExtension\n\n\ttargetSHABytes, err := e.VFSContext.ReadFile(targetSHAFile)\n\tif err != nil {\n\t\tif os.IsNotExist(err) {","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/assets/assetcopy/copyfile.go#L36-L72","documentation":"fileExtensionForSHA maps a hex hash string to its checksum-file extension: 40 hex chars -> .sha1, 64 -> .sha256. Any other length (short, truncated, or non-standard hash) returns this error, aborting the CopyFile task.","triggerScenarios":"A FileAsset whose SHAValue, when hex-encoded, is neither 40 nor 64 characters — e.g. SHAValue parsed from a corrupt or wrong-algorithm .sha file (md5=32 chars), an empty sha, or a truncated entry in the asset list.","commonSituations":"A custom file repository publishes checksum files generated with md5 or crc32; a manually edited assets spec contains a cut-off hash; a mirror serves a wrong .sha1 file that kops parses as the expected sha.","solutions":["Inspect the sha in the error message and count its length to identify the wrong algorithm.","Regenerate or fix the checksum source so it is sha1 (40 hex) or sha256 (64 hex).","If the sha comes from a file repository .sha file, correct that file's contents.","Re-run `kops get assets --copy` after the sha is corrected."],"exampleFix":"// before (bad sha in repo)\n5d41402abc4b2a76b9719d911017c592  file.tar.gz   # md5, 32 chars\n// after\n2aae6c35c94fcfb415dbe95f408b9ce91ee846ed  file.tar.gz   # sha1, 40 chars","handlingStrategy":"validation","validationCode":"sha := strings.TrimSpace(fileAsset.SHAValue.Hex())\nif len(sha) != 40 && len(sha) != 64 {\n    return fmt.Errorf(\"asset sha must be sha1 (40) or sha256 (64) hex chars, got %d: %q\", len(sha), sha)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Publish only sha1/sha256 checksum files in your file repository","Validate checksum files with `shasum -a 256 -c` before using them with kops","Avoid md5/crc32 checksums in custom mirrors","Sanity-check sha lengths in generated asset specs before running copy"],"tags":["go","sha","validation","asset-copy"],"backgroundTag":"unhandled-sha-length","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}