sipeed/picoclaw · error
ciphertext length is not a multiple of block size
Error message
ciphertext length %d is not a multiple of block size
What it means
Guard in decryptAESCBC: the ciphertext length is not a multiple of the AES block size (16 bytes), which AES-CBC cryptically requires. The %d placeholder shows the offending length, usually meaning the payload was truncated or mixed with non-ciphertext bytes during extraction.
Solutions
- Verify the ciphertext extraction offsets — extra headers or a stripped byte shifts the length
- Re-download the media payload to rule out truncation
- Confirm the payload is actually AES-CBC encrypted WeCom media and not plaintext or a different encoding
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at pkg/channels/wecom/media.go:109 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15).
Data as JSON: /api/errors/65e89f1043949f61.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/channels/wecom/media.go:109
if err == nil && len(key) == 32 {
return key, nil
}
key, err = base64.StdEncoding.DecodeString(value + "=")
if err != nil {
return nil, fmt.Errorf("decode AES key: %w", err)
}
if len(key) != 32 {
return nil, fmt.Errorf("invalid AES key length %d", len(key))
}
return key, nil
}
func decryptAESCBC(key, ciphertext []byte) ([]byte, error) {
if len(ciphertext) == 0 {
return nil, fmt.Errorf("ciphertext is empty")
}
if len(ciphertext)%aes.BlockSize != 0 {
return nil, fmt.Errorf("ciphertext length %d is not a multiple of block size", len(ciphertext))
}
block, err := aes.NewCipher(key)
if err != nil {
return nil, fmt.Errorf("create cipher: %w", err)
}
plaintext := make([]byte, len(ciphertext))
iv := key[:aes.BlockSize]
cipher.NewCBCDecrypter(block, iv).CryptBlocks(plaintext, ciphertext)
return pkcs7Unpad(plaintext)
}
func pkcs7Unpad(data []byte) ([]byte, error) {
if len(data) == 0 {
return nil, fmt.Errorf("empty plaintext")
}
padding := int(data[len(data)-1])
if padding == 0 || padding > 32 || padding > len(data) {
return nil, fmt.Errorf("invalid padding size %d", padding)View on GitHub (pinned to 49183d7e8d)