From 78e4f729be82b515480759addb64bd8d4e124dca Mon Sep 17 00:00:00 2001
From: 雾聪 <wucong.lyb@alibaba-inc.com>
Date: 星期二, 24 十月 2023 19:52:44 +0800
Subject: [PATCH] add check for chunk_size_vec
---
funasr/runtime/websocket/bin/websocket-server-2pass.cpp | 21 +++++++++++++++++----
1 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/funasr/runtime/websocket/bin/websocket-server-2pass.cpp b/funasr/runtime/websocket/bin/websocket-server-2pass.cpp
index b64cecb..a637471 100644
--- a/funasr/runtime/websocket/bin/websocket-server-2pass.cpp
+++ b/funasr/runtime/websocket/bin/websocket-server-2pass.cpp
@@ -356,7 +356,14 @@
unique_lock guard_decoder(*(thread_lock_p)); // mutex for one connection
switch (msg->get_opcode()) {
case websocketpp::frame::opcode::text: {
- nlohmann::json jsonresult = nlohmann::json::parse(payload);
+ nlohmann::json jsonresult;
+ try{
+ jsonresult = nlohmann::json::parse(payload);
+ }catch (std::exception const &e)
+ {
+ LOG(ERROR)<<e.what();
+ break;
+ }
if (jsonresult.contains("wav_name")) {
msg_data->msg["wav_name"] = jsonresult["wav_name"];
@@ -401,9 +408,15 @@
if (msg_data->tpass_online_handle == NULL) {
std::vector<int> chunk_size_vec =
jsonresult["chunk_size"].get<std::vector<int>>();
- FUNASR_HANDLE tpass_online_handle =
- FunTpassOnlineInit(tpass_handle, chunk_size_vec);
- msg_data->tpass_online_handle = tpass_online_handle;
+ // check chunk_size_vec
+ if(chunk_size_vec.size() == 3 && chunk_size_vec[1] != 0){
+ FUNASR_HANDLE tpass_online_handle =
+ FunTpassOnlineInit(tpass_handle, chunk_size_vec);
+ msg_data->tpass_online_handle = tpass_online_handle;
+ }else{
+ LOG(ERROR) << "Wrong chunk_size!";
+ break;
+ }
}
}
if (jsonresult.contains("itn")) {
--
Gitblit v1.9.1