{"record":{"id":"cd4caf01df068a15","repo":"fish2018/pansou","slug":"error-cd4caf","errorCode":null,"errorMessage":"填充校验失败","messagePattern":"填充校验失败","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/check_mobile_crypto.go","lineNumber":114,"sourceCode":"\tfor index := range padding {\n\t\tpadding[index] = byte(paddingSize)\n\t}\n\treturn append(data, padding...)\n}\n\nfunc removeMobilePadding(data []byte) ([]byte, error) {\n\tif len(data) == 0 {\n\t\treturn nil, fmt.Errorf(\"空响应无法去填充\")\n\t}\n\n\tpaddingSize := int(data[len(data)-1])\n\tif paddingSize <= 0 || paddingSize > len(data) {\n\t\treturn nil, fmt.Errorf(\"填充长度非法\")\n\t}\n\n\tfor index := len(data) - paddingSize; index < len(data); index++ {\n\t\tif data[index] != byte(paddingSize) {\n\t\t\treturn nil, fmt.Errorf(\"填充校验失败\")\n\t\t}\n\t}\n\n\treturn data[:len(data)-paddingSize], nil\n}\n","sourceCodeStart":96,"sourceCodeEnd":120,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/service/check_mobile_crypto.go#L96-L120","documentation":"After reading the padding size, removeMobilePadding verifies that all padding bytes equal the padding size and rejects mismatches. This is an integrity check: the decrypted plaintext's trailing bytes don't form a consistent padding block, indicating corrupt or wrongly decrypted data.","triggerScenarios":"The last paddingSize bytes of decrypted data are not all equal to paddingSize — wrong key producing plausible-looking garbage, bit-flip corruption, or mismatched padding implementations.","commonSituations":"Key/IV drift after server update (decryption yields near-valid output failing the final check), manual transport mangling (proxies, encoding conversions), or a server that changed padding conventions.","solutions":["Treat as an integrity failure: log the trailing bytes and confirm the decryption pipeline with a known-good test vector.","Re-sync the encryption key/IV with the server.","Verify no middleware rewrites the response body (compression/encoding proxies).","Add a round-trip unit test: pad → unpad the same bytes to isolate whether padding or decryption is at fault."],"exampleFix":"// test to isolate the fault\npadded := addMobilePadding([]byte(\"hello\"))\ngot, err := removeMobilePadding(padded)\nif err != nil || string(got) != \"hello\" {\n    t.Fatalf(\"padding round-trip broken: %v\", err)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"plain, err := removeMobilePadding(decrypted)\nif err != nil {\n    log.Printf(\"padding integrity failed, last bytes: %v\", tail(decrypted, 8))\n    return fmt.Errorf(\"corrupt payload: %w\", err)\n}","preventionTips":["Add pad→unpad round-trip unit tests for the padding implementation.","Verify decryption with known-good vectors before blaming padding.","Guard against middleboxes rewriting response bodies."],"tags":["crypto","padding","integrity"],"backgroundTag":"checksum-mismatch","analyzedSha":"beaa56133755a548ebc51b090b3816e2ae044aa6","analyzedAt":"2026-09-07T00:31:18.025Z","contentChangedAt":"2026-09-07T00:31:18.025Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}