fish2018/pansou · error
填充校验失败
Error message
填充校验失败
What it means
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.
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.
Example fix
// test to isolate the fault
padded := addMobilePadding([]byte("hello"))
got, err := removeMobilePadding(padded)
if err != nil || string(got) != "hello" {
t.Fatalf("padding round-trip broken: %v", err)
} Defensive patterns
Strategy: try-catch
Try / catch
plain, err := removeMobilePadding(decrypted)
if err != nil {
log.Printf("padding integrity failed, last bytes: %v", tail(decrypted, 8))
return fmt.Errorf("corrupt payload: %w", err)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Checksum mismatch errors: "checksum verification failed", "digest mismatch", "expected vs actual checksum" — what they mean and how to fix them — this error's family across 41 libraries.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/cd4caf01df068a15.
Report an issue: GitHub.
Appendix: source
Thrown at service/check_mobile_crypto.go:114
for index := range padding {
padding[index] = byte(paddingSize)
}
return append(data, padding...)
}
func removeMobilePadding(data []byte) ([]byte, error) {
if len(data) == 0 {
return nil, fmt.Errorf("空响应无法去填充")
}
paddingSize := int(data[len(data)-1])
if paddingSize <= 0 || paddingSize > len(data) {
return nil, fmt.Errorf("填充长度非法")
}
for index := len(data) - paddingSize; index < len(data); index++ {
if data[index] != byte(paddingSize) {
return nil, fmt.Errorf("填充校验失败")
}
}
return data[:len(data)-paddingSize], nil
}
View on GitHub (pinned to beaa561337)