fish2018/pansou · error
填充长度非法
Error message
填充长度非法
What it means
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.
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).
Example fix
// before plain, err := decryptMobilePayload(payload, staleKey) // after key := fetchCurrentKey() // avoid stale rotated key plain, err := decryptMobilePayload(payload, key)
Defensive patterns
Strategy: validation
Validate before calling
last := data[len(data)-1]
if last == 0 || int(last) > len(data) {
return fmt.Errorf("data not padded with expected scheme")
} Try / catch
plain, err := removeMobilePadding(decrypted)
if err != nil {
return refreshKeyAndRetry(decrypted) // likely key/IV drift
} Prevention
- Keep encryption keys in sync with server rotations.
- Share padding/decryption test vectors between client and server CI.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/4acd1fe07a1158e7.
Report an issue: GitHub.
Appendix: source
Thrown at service/check_mobile_crypto.go:109
}
func addMobilePadding(data []byte, blockSize int) []byte {
paddingSize := blockSize - len(data)%blockSize
padding := make([]byte, paddingSize)
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)