Open-source speech recognition toolkit for training, inference, streaming ASR, VAD, punctuation, speaker diarization pipelines, and OpenAI-compatible/MCP serving.
Python asraudiochineseemotion-recognitionfunasrmcp-servermultilingual-asropenai-compatible-apiparaformerpunctuationpytorchreal-time-asrspeaker-diarizationspeech-recognitionspeech-to-textstreaming-asrtranscriptionvllmvoice-activity-detectionwhisper-alternative
Revert "fix(runtime): 4 memory safety bugs in onnxruntime C++ code"
游雁aad31f5e02e6
diff --git a/runtime/onnxruntime/src/audio.cpp b/runtime/onnxruntime/src/audio.cppindex e7b64643e..98899170a 100644--- a/runtime/onnxruntime/src/audio.cpp+++ b/runtime/onnxruntime/src/audio.cpp@@ -156,14 +156,6 @@ AudioFrame::AudioFrame(const AudioFrame &other)end = other.end;len = other.len;is_final = other.is_final;- global_start = other.global_start;- global_end = other.global_end;- if (other.data != nullptr && other.len > 0) {- data = (float*)malloc(other.len * sizeof(float));- memcpy(data, other.data, other.len * sizeof(float));- } else {- data = nullptr;- }}AudioFrame::AudioFrame(int start, int end, bool is_final):start(start),end(end),is_final(is_final){len = end - start;@@ -480,7 +472,6 @@ bool Audio::FfmpegLoad(const char* buf, int n_file_len){formatContext->pb = avio_ctx;if (avformat_open_input(&formatContext, "", nullptr, nullptr) != 0) {LOG(ERROR) << "Error: Could not open input file.";- av_freep(&avio_ctx->buffer);avio_context_free(&avio_ctx);avformat_close_input(&formatContext);avformat_free_context(formatContext);@@ -489,7 +480,6 @@ bool Audio::FfmpegLoad(const char* buf, int n_file_len){if (avformat_find_stream_info(formatContext, nullptr) < 0) {LOG(ERROR) << "Error: Could not find stream information.";- av_freep(&avio_ctx->buffer);avio_context_free(&avio_ctx);avformat_close_input(&formatContext);avformat_free_context(formatContext);@@ -504,7 +494,6 @@ bool Audio::FfmpegLoad(const char* buf, int n_file_len){AVCodecContext* codecContext = avcodec_alloc_context3(codec);if (!codecContext) {LOG(ERROR) << "Failed to allocate codec context";- av_freep(&avio_ctx->buffer);avio_context_free(&avio_ctx);avformat_close_input(&formatContext);avformat_free_context(formatContext);@@ -512,7 +501,6 @@ bool Audio::FfmpegLoad(const char* buf, int n_file_len){}if (avcodec_parameters_to_context(codecContext, codecParameters) != 0) {LOG(ERROR) << "Error: Could not copy codec parameters to codec context.";- av_freep(&avio_ctx->buffer);avio_context_free(&avio_ctx);avformat_close_input(&formatContext);avformat_free_context(formatContext);@@ -521,7 +509,6 @@ bool Audio::FfmpegLoad(const char* buf, int n_file_len){}if (avcodec_open2(codecContext, codec, nullptr) < 0) {LOG(ERROR) << "Error: Could not open audio decoder.";- av_freep(&avio_ctx->buffer);avio_context_free(&avio_ctx);avformat_close_input(&formatContext);avformat_free_context(formatContext);@@ -541,7 +528,6 @@ bool Audio::FfmpegLoad(const char* buf, int n_file_len){);if (swr_ctx == nullptr) {LOG(ERROR) << "Could not initialize resampler";- av_freep(&avio_ctx->buffer);avio_context_free(&avio_ctx);avformat_close_input(&formatContext);avformat_free_context(formatContext);@@ -550,7 +536,6 @@ bool Audio::FfmpegLoad(const char* buf, int n_file_len){}if (swr_init(swr_ctx) != 0) {LOG(ERROR) << "Could not initialize resampler";- av_freep(&avio_ctx->buffer);avio_context_free(&avio_ctx);avformat_close_input(&formatContext);avformat_free_context(formatContext);@@ -597,8 +582,7 @@ bool Audio::FfmpegLoad(const char* buf, int n_file_len){av_packet_unref(packet);}- //av_freep(&avio_ctx->buffer);- avio_context_free(&avio_ctx);+ //avio_context_free(&avio_ctx);av_freep(&avio_ctx ->buffer);av_freep(&avio_ctx);avformat_close_input(&formatContext);diff --git a/runtime/onnxruntime/src/funasrruntime.cpp b/runtime/onnxruntime/src/funasrruntime.cppindex a024939b0..580c93422 100644--- a/runtime/onnxruntime/src/funasrruntime.cpp+++ b/runtime/onnxruntime/src/funasrruntime.cpp@@ -548,8 +548,6 @@}else if(mode == ASR_TWO_PASS){p_result->msg += msg;}- delete[] buff;- delete[] len;if(frame != nullptr){delete frame;frame = nullptr;@@ -623,8 +621,6 @@if (!(p_result->stamp).empty()){p_result->stamp_sents = funasr::TimestampSentence(p_result->tpass_msg, p_result->stamp);}- delete[] buff;- delete[] len;if(frame != nullptr){delete frame;frame = nullptr;diff --git a/runtime/onnxruntime/src/paraformer.cpp b/runtime/onnxruntime/src/paraformer.cppindex eb9c75243..7e1fe9671 100644--- a/runtime/onnxruntime/src/paraformer.cpp+++ b/runtime/onnxruntime/src/paraformer.cpp@@ -509,14 +509,7 @@ std::vector<std::string> Paraformer::Forward(float** din, int* len, bool input_fint64_t outputCount = std::accumulate(outputShape.begin(), outputShape.end(), 1, std::multiplies<int64_t>());float* floatData = outputTensor[0].GetTensorMutableData<float>();- auto enc_lens_type = outputTensor[1].GetTensorTypeAndShapeInfo().GetElementType();- int64_t encoder_out_lens_val;- if (enc_lens_type == ONNX_TENSOR_ELEMENT_DATA_TYPE_INT32) {- encoder_out_lens_val = static_cast<int64_t>(*outputTensor[1].GetTensorMutableData<int32_t>());- } else {- encoder_out_lens_val = *outputTensor[1].GetTensorMutableData<int64_t>();- }- auto encoder_out_lens = &encoder_out_lens_val;+ auto encoder_out_lens = outputTensor[1].GetTensorMutableData<int64_t>();// timestampif(outputTensor.size() == 4){std::vector<int64_t> us_alphas_shape = outputTensor[2].GetTensorTypeAndShapeInfo().GetShape();