alphacep / vosk-asterisk

Speech Recognition in Asterisk with Vosk Server
GNU General Public License v2.0
102 stars 40 forks source link

Random segmentation fault #18

Closed serxoz closed 3 years ago

serxoz commented 3 years ago

Hi.

I'm here begging for help or at least some directions. I get sometimes, not always, this segfault:

#0  __memmove_sse2_unaligned_erms () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:489
#1  0x00007f3d8dc41fdd in vosk_recog_write (speech=0x7f3d8800f6b0, data=<optimized out>, len=320)
    at res_speech_vosk.c:156
#2  0x00007f3d8d98055a in speech_background (chan=0x7f3d800056e0, data=<optimized out>) at app_speech_utils.c:855

Don't always get it, it's so random! And to put things more easy, I've modified app_speech_utils.c a little. But, I think my modifications don't have to do with this part of code... I'm not 100% sure.

I attach here my asterisk patch and my vosk-asterisk patch for the braves who want to try. I have tried them with 16.18.0 and git version of asterisk. My modifications try to solve a pair of problems I encounter:

Hope you can at least point me in a good direction to follow. Thank you in advance.

ast-patch.txt vosk-ast-patch.txt core-thread1.txt

serxoz commented 3 years ago

Hi again. I can see in gdb this:

#1  0x00007f3d8dc41fdd in vosk_recog_write (speech=0x7f3d8800f6b0, data=<optimized out>, len=320)
    at res_speech_vosk.c:156
156             memcpy(vosk_speech->buf + vosk_speech->offset, data, len);
(gdb) print vosk_speech->offset
$1 = 11010520

Maybe offset is the cause?

nshmyrev commented 3 years ago

You'd better use strncat in your patch instead of strcat, otherwise you might get buffer overflow.

You also better accumulate text in asterisk variables instead of patching the sources.

serxoz commented 3 years ago

The text is acumulated while the locution in SpeechBackgrond() is playing, I think can't do that in dialplan... :S

serxoz commented 3 years ago

I think the problem is in the assert. Look here: https://github.com/alphacep/vosk-asterisk/pull/19

Although despite correcting the name of the variable, it still allows a large offset to pass. I had another core dump with an offset value of 524616.

nshmyrev commented 3 years ago

I think the problem is in the assert. Look here:

asserts are disabled by default, still, it is a valid fix I think, thank you.

Although despite correcting the name of the variable, it still allows a large offset to pass. I had another core dump with an offset value of 524616.

You can probably add a printf of the offset value every frame and collect logs showing the offset changes.

You still need to fix strcat issue in your code.

serxoz commented 3 years ago

I was thinking assert was enabled... :( I could solve the problem with this: https://github.com/alphacep/vosk-asterisk/pull/20 I've tested it with more than 200 calls and is working OK.

Thank you for your recommendation on strncat().