{"record":{"id":"6307e90f24ff1dee","repo":"AlistGo/alist","slug":"bad-cid-s-body-s","errorCode":null,"errorMessage":"bad cid: %s, body: %s","messagePattern":"bad cid: (.+?), body: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"drivers/halalcloud/util.go","lineNumber":261,"sourceCode":"\tif addr.Encrypt > 0 {\n\t\tcd := uint8(addr.Encrypt)\n\t\tfor idx := 0; idx < len(body); idx++ {\n\t\t\tbody[idx] = body[idx] ^ cd\n\t\t}\n\t}\n\n\tif addr.StoreType != 10 {\n\n\t\tsourceCid, err := cid.Decode(addr.Identity)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tcheckCid, err := sourceCid.Prefix().Sum(body)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif !checkCid.Equals(sourceCid) {\n\t\t\treturn nil, fmt.Errorf(\"bad cid: %s, body: %s\", checkCid.String(), body)\n\t\t}\n\t}\n\n\treturn body, nil\n\n}\n\ntype openObject struct {\n\tctx     context.Context\n\tmu      sync.Mutex\n\td       []*pubUserFile.SliceDownloadInfo\n\tid      int\n\tskip    int64\n\tchunk   *[]byte\n\tchunks  *[]chunkSize\n\tclosed  bool\n\tsha     string\n\tshaTemp hash.Hash","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/AlistGo/alist/blob/843d9dc8149126976b2625911e45a4d3ffd6f2f5/drivers/halalcloud/util.go#L243-L279","documentation":"Returned by HalalCloud after downloading (and XOR-decrypting, when Encrypt > 0) a slice: the CID recomputed from the bytes does not equal the CID stored in addr.Identity. This is content-integrity failure — the bytes on the wire do not match what the provider committed to, indicating corruption or wrong decryption. Skipped entirely for StoreType == 10 (raw storage).","triggerScenarios":"Encrypt value wrong/stale so the XOR 'decryption' produces garbage (correct-length but wrong bytes); a corrupted storage node; a truncated or tampered response (proxy, captive portal injecting bytes); CID field parsed incorrectly.","commonSituations":"Caching proxy mangling slice responses; driver version mismatch with the provider's encryption scheme; rare bit-rot on the provider's storage; address metadata fetched for a different file/slice.","solutions":["Re-fetch the download address for the slice and download again — transient corruption is the most common cause.","Bypass HTTP proxies/middleboxes for these requests and retry; injected HTML error pages are a classic cause.","If it reproduces for the same slice every time, the stored object itself is corrupt server-side — re-upload the file.","Check the driver is current in case the Encrypt scheme changed."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"body, err := fetchAndVerify(client, addr)\nif err != nil && strings.Contains(err.Error(), \"bad cid\") {\n    body, err = fetchAndVerify(client, addr) // one retry, no proxy\n    if err != nil { return fmt.Errorf(\"slice corrupt after retry: %w\", err) }\n}","preventionTips":["Bypass HTTP caches/proxies for slice downloads","Retry once on CID mismatch before declaring corruption","Track slices that fail repeatedly — server-side corruption needs re-upload"],"tags":["halalcloud","cid","integrity","corruption","xor-decrypt"],"backgroundTag":null,"analyzedSha":"843d9dc8149126976b2625911e45a4d3ffd6f2f5","analyzedAt":"2026-08-15T12:14:11.722Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}