shithub: opus

Download patch

ref: 4eca11c001294a2495f405773795b6d919605ca5
parent: 32d4d874accd322f7e237b734678542fea88393b
author: Jean-Marc Valin <jmvalin@jmvalin.ca>
date: Sat Mar 2 21:55:37 EST 2024

Avoid OSCE crash if weights aren't loaded

--- a/dnn/osce.c
+++ b/dnn/osce.c
@@ -927,6 +927,7 @@
     float numbits[2];
     int periods[4];
     int i;
+    int method;
 
     /* enhancement only implemented for 20 ms frame at 16kHz */
     if (psDec->fs_kHz != 16 || psDec->nb_subfr != 4)
@@ -943,7 +944,11 @@
         in_buffer[i] = ((float) xq[i]) * (1.f/32768.f);
     }
 
-    switch(psDec->osce.method)
+    if (model->loaded)
+        method = psDec->osce.method;
+    else
+        method = OSCE_METHOD_NONE;
+    switch(method)
     {
         case OSCE_METHOD_NONE:
             OPUS_COPY(out_buffer, in_buffer, 320);
--- a/dnn/osce_structs.h
+++ b/dnn/osce_structs.h
@@ -104,6 +104,7 @@
 
 /* OSCEModel */
 typedef struct {
+   int loaded;
 #ifndef DISABLE_LACE
     LACE lace;
 #endif
--- a/silk/dec_API.c
+++ b/silk/dec_API.c
@@ -64,7 +64,7 @@
     opus_int ret = SILK_NO_ERROR;
 
     ret = osce_load_models(&((silk_decoder *)decState)->osce_model, data, len);
-
+    ((silk_decoder *)decState)->osce_model.loaded = (ret == 0);
     return ret;
 #else
     (void) decState;
@@ -110,7 +110,9 @@
 {
     opus_int n, ret = SILK_NO_ERROR;
     silk_decoder_state *channel_state = ((silk_decoder *)decState)->channel_state;
-
+#ifdef ENABLE_OSCE
+    ((silk_decoder *)decState)->osce_model.loaded = 0;
+#endif
 #ifndef USE_WEIGHTS_FILE
     /* load osce models */
     silk_LoadOSCEModels(decState, NULL, 0);
--