{"record":{"id":"4acd1fe07a1158e7","repo":"fish2018/pansou","slug":"error-4acd1f","errorCode":null,"errorMessage":"填充长度非法","messagePattern":"填充长度非法","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"service/check_mobile_crypto.go","lineNumber":109,"sourceCode":"}\n\nfunc addMobilePadding(data []byte, blockSize int) []byte {\n\tpaddingSize := blockSize - len(data)%blockSize\n\tpadding := make([]byte, paddingSize)\n\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":91,"sourceCodeEnd":120,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/service/check_mobile_crypto.go#L91-L120","documentation":"removeMobilePadding reads the final byte as the padding size and rejects values that are <= 0 or exceed the data length. This means the decrypted data does not carry a valid padding trailer — a strong sign of wrong decryption (bad key/IV/mode) or corrupted ciphertext.","triggerScenarios":"decryptMobilePadding's output's last byte is 0 or larger than len(data): decrypting with the wrong key, wrong cipher mode/IV, or feeding already-decrypted data through decryption again.","commonSituations":"Server rotated its encryption key but client kept the old one; mismatched padding scheme (client expects custom padding, server used PKCS#7 with different byte layout); ciphertext truncated in transit.","solutions":["Verify the decryption key/IV match the server's current values (key rotation).","Dump the last byte of decrypted data to see the actual value and compare with the expected padding scheme.","Confirm both sides use the same padding convention; align client with server's scheme.","Ensure the full ciphertext arrived (check Content-Length vs bytes read)."],"exampleFix":"// before\nplain, err := decryptMobilePayload(payload, staleKey)\n// after\nkey := fetchCurrentKey() // avoid stale rotated key\nplain, err := decryptMobilePayload(payload, key)","handlingStrategy":"validation","validationCode":"last := data[len(data)-1]\nif last == 0 || int(last) > len(data) {\n    return fmt.Errorf(\"data not padded with expected scheme\")\n}","typeGuard":null,"tryCatchPattern":"plain, err := removeMobilePadding(decrypted)\nif err != nil {\n    return refreshKeyAndRetry(decrypted) // likely key/IV drift\n}","preventionTips":["Keep encryption keys in sync with server rotations.","Share padding/decryption test vectors between client and server CI."],"tags":["crypto","padding","decryption"],"backgroundTag":"invalid-argument-value","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"}