fish2018/pansou · warning
数据为空
Error message
数据为空
What it means
removePKCS7Padding rejects an empty input slice with 数据为空 before inspecting the padding byte. Within DecryptURL's flow this is nearly unreachable because DecryptURL already rejects zero-length ciphertext, so seeing it means removePKCS7Padding was invoked with a nil/empty slice, or plaintext allocation produced zero bytes unexpectedly.
Solutions
- Guard with len(data) > 0 before calling removePKCS7Padding.
- If calling DecryptURL, ensure the Base64 input is non-empty and decodes to at least 16 bytes.
- Treat this as an input-validation bug in the caller rather than a crypto failure; add an early return/log for empty payloads.
Example fix
// before
out, err := removePKCS7Padding(data)
// after
if len(data) == 0 {
return nil, fmt.Errorf("skip: empty payload")
}
out, err := removePKCS7Padding(data) Defensive patterns
Strategy: validation
Validate before calling
if len(data) == 0 {
return fmt.Errorf("refusing to unpad empty payload")
}
out, err := removePKCS7Padding(data) Prevention
- Check for empty/nil byte slices before crypto post-processing.
- Validate payloads at the pipeline boundary (non-empty, block-aligned).
- Log and skip empty payloads instead of passing them to unpadding.
When it happens
Trigger: Calling removePKCS7Padding directly with a nil or empty []byte; DecryptURL given ciphertext that decoded to zero bytes (though that path is guarded earlier by 密文长度为0).
Common situations: A developer unit-testing or reusing removePKCS7Padding passes an empty buffer; upstream data pipeline delivered an empty payload into the padding step.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
AI-assisted analysis of fish2018/pansou@beaa561337 (2026-09-07).
Data as JSON: /api/errors/35b9fad471790dc8.
Report an issue: GitHub.
Appendix: source
Thrown at plugin/sdso/sdso.go:429
mode := cipher.NewCBCDecrypter(block, iv)
// 解密
plaintext := make([]byte, len(ciphertext))
mode.CryptBlocks(plaintext, ciphertext)
// 去除PKCS7填充
unpaddedText, err := removePKCS7Padding(plaintext)
if err != nil {
return "", fmt.Errorf("去除填充失败: %w", err)
}
return string(unpaddedText), nil
}
// removePKCS7Padding 去除PKCS7填充
func removePKCS7Padding(data []byte) ([]byte, error) {
if len(data) == 0 {
return nil, fmt.Errorf("数据为空")
}
// 获取填充长度
paddingLen := int(data[len(data)-1])
// 验证填充长度
if paddingLen == 0 || paddingLen > len(data) || paddingLen > aes.BlockSize {
return nil, fmt.Errorf("无效的填充长度: %d", paddingLen)
}
// 验证填充字节
for i := len(data) - paddingLen; i < len(data); i++ {
if data[i] != byte(paddingLen) {
return nil, fmt.Errorf("无效的填充字节")
}
}
// 返回去除填充后的数据View on GitHub (pinned to beaa561337)