{"record":{"id":"fe3b7e59d1af1c6c","repo":"fish2018/pansou","slug":"error-fe3b7e","errorCode":null,"errorMessage":"无效的填充字节","messagePattern":"无效的填充字节","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugin/sdso/sdso.go","lineNumber":443,"sourceCode":"\n// removePKCS7Padding 去除PKCS7填充\nfunc removePKCS7Padding(data []byte) ([]byte, error) {\n\tif len(data) == 0 {\n\t\treturn nil, fmt.Errorf(\"数据为空\")\n\t}\n\n\t// 获取填充长度\n\tpaddingLen := int(data[len(data)-1])\n\n\t// 验证填充长度\n\tif paddingLen == 0 || paddingLen > len(data) || paddingLen > aes.BlockSize {\n\t\treturn nil, fmt.Errorf(\"无效的填充长度: %d\", paddingLen)\n\t}\n\n\t// 验证填充字节\n\tfor i := len(data) - paddingLen; i < len(data); i++ {\n\t\tif data[i] != byte(paddingLen) {\n\t\t\treturn nil, fmt.Errorf(\"无效的填充字节\")\n\t\t}\n\t}\n\n\t// 返回去除填充后的数据\n\treturn data[:len(data)-paddingLen], nil\n}\n\n// cleanHTMLTags 清理HTML标签\nfunc cleanHTMLTags(text string) string {\n\t// 移除高亮标签 <span style=\"color: red;\">...</span>\n\tre := regexp.MustCompile(`<span[^>]*>(.*?)</span>`)\n\tcleaned := re.ReplaceAllString(text, \"$1\")\n\t\n\t// 移除其他可能的HTML标签\n\tre2 := regexp.MustCompile(`<[^>]*>`)\n\tcleaned = re2.ReplaceAllString(cleaned, \"\")\n\t\n\treturn strings.TrimSpace(cleaned)","sourceCodeStart":425,"sourceCodeEnd":461,"githubUrl":"https://github.com/fish2018/pansou/blob/beaa56133755a548ebc51b090b3816e2ae044aa6/plugin/sdso/sdso.go#L425-L461","documentation":"After a plausible padding length is read, removePKCS7Padding verifies that all trailing paddingLen bytes equal byte(paddingLen), as PKCS#7 requires. If any padding byte differs, the padding is malformed and the function fails with 无效的填充字节. Like the padding-length error, this usually means the ciphertext was decrypted with the wrong key/IV or the data was altered.","triggerScenarios":"AES-CBC decryption with incorrect AESKey/AESIV produces plaintext whose trailing bytes are not uniform; ciphertext modified during transport (e.g. case-insensitive Base64 handling, encoding round-trips); data encrypted with non-PKCS7 padding such as ISO/ANSI or zero padding.","commonSituations":"SDSO site rotated its encryption key so old hardcoded constants decrypt to noise; cached encrypted URL from an older site format; ciphertext altered by encoding round-trips (URL decoding, charset conversion) during transport.","solutions":["Confirm AESKey/AESIV match the current site parameters — uniform-padding violations after decrypt point to wrong-key garbage.","Re-fetch a fresh encrypted token instead of using cached/stale values.","Dump the decrypted plaintext in hex and check the final block; if trailing bytes are random, fix key/IV rather than relaxing the padding check.","Verify the site truly uses PKCS#7; if it uses zero- or no-padding, replace removePKCS7Padding with the appropriate unpadding routine."],"exampleFix":"// before\nunpaddedText, err := removePKCS7Padding(plaintext)\nif err != nil {\n    return \"\", err\n}\n// after\nunpaddedText, err := removePKCS7Padding(plaintext)\nif err != nil {\n    return \"\", fmt.Errorf(\"bad PKCS7 padding after decrypt (len=%d): %w — verify AESKey/AESIV\", len(plaintext), err)\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"plain, err := DecryptURL(enc)\nif err != nil {\n    if strings.Contains(err.Error(), \"无效的填充字节\") {\n        // decryption produced non-uniform trailing bytes: wrong key/IV or corrupted data\n        return reFetchAndDecrypt(item)\n    }\n    return err\n}","preventionTips":["Never relax the padding-byte check to 'fix' this error; fix the key/IV instead.","Hex-dump decrypted output when this occurs to confirm garbage vs corruption.","Keep encrypted payloads intact end-to-end (no charset/URL re-encoding).","Add an integration test that decrypts a known-good token from the live site."],"tags":["crypto","aes","pkcs7","go"],"backgroundTag":"padding-validation-failed","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"}