{"record":{"id":"b9806de10ecb3855","repo":"chenhg5/cc-connect","slug":"invalid-message-length-d-in-decrypted-data-total","errorCode":null,"errorMessage":"invalid message length %d in decrypted data (total %d)","messagePattern":"invalid message length (.+?) in decrypted data \\(total (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/wecom/wecom.go","lineNumber":777,"sourceCode":"\n\tif len(cipherData) < aes.BlockSize || len(cipherData)%aes.BlockSize != 0 {\n\t\treturn \"\", fmt.Errorf(\"invalid ciphertext length %d\", len(cipherData))\n\t}\n\n\tiv := p.aesKey[:16]\n\tmode := cipher.NewCBCDecrypter(block, iv)\n\tplain := make([]byte, len(cipherData))\n\tmode.CryptBlocks(plain, cipherData)\n\n\tplain = pkcs7Unpad(plain)\n\n\tif len(plain) < 20 {\n\t\treturn \"\", fmt.Errorf(\"decrypted data too short\")\n\t}\n\n\tmsgLen := int(binary.BigEndian.Uint32(plain[16:20]))\n\tif 20+msgLen > len(plain) {\n\t\treturn \"\", fmt.Errorf(\"invalid message length %d in decrypted data (total %d)\", msgLen, len(plain))\n\t}\n\n\tmsg := string(plain[20 : 20+msgLen])\n\tcorpID := string(plain[20+msgLen:])\n\n\tif corpID != p.corpID {\n\t\treturn \"\", fmt.Errorf(\"corp_id mismatch: expected %s, got %s\", p.corpID, corpID)\n\t}\n\n\treturn msg, nil\n}\n\nfunc pkcs7Unpad(data []byte) []byte {\n\tif len(data) == 0 {\n\t\treturn data\n\t}\n\tpad := int(data[len(data)-1])\n\tif pad < 1 || pad > 32 || pad > len(data) {","sourceCodeStart":759,"sourceCodeEnd":795,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/wecom/wecom.go#L759-L795","documentation":"Consistency guard on the embedded message length: the 4-byte big-endian msg_len read from plaintext bytes 16..20 plus the 20-byte header exceeds the total plaintext length, so the declared message would run past the buffer. Like the other post-decrypt guards, this pattern arises when decrypting with the wrong EncodingAESKey — the length field is then random garbage.","triggerScenarios":"Thrown at platform/wecom/wecom.go:777 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the EncodingAESKey matches the app that signed the callback — wrong keys produce incoherent length fields","Reject the callback rather than retrying","Log both numbers (already included) to confirm the garbage-length signature of a key mismatch"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}