speechutils icon indicating copy to clipboard operation
speechutils copied to clipboard

ArrayIndexOutOfBounds in AbstractAudioRecorder.java

Open syedtalha opened this issue 8 years ago • 9 comments

Library crashes when we try to call isPausing() on AudioRecorder

Caused by: java.lang.ArrayIndexOutOfBoundsException: length=1120000; index=1120000 at ee.ioc.phon.android.speechutils.AbstractAudioRecorder.getRms(AbstractAudioRecorder.java:342) at ee.ioc.phon.android.speechutils.AbstractAudioRecorder.getPauseScore(AbstractAudioRecorder.java:252) at ee.ioc.phon.android.speechutils.AbstractAudioRecorder.isPausing(AbstractAudioRecorder.java:220)

syedtalha avatar Oct 07 '16 18:10 syedtalha

I've seen this too. Specifically with newer OS's like Nexus 6P OS: 7.0. My Samsung Galaxy s5 OS 6.0.1 doesn't have this problem. I really like using this library so hopefully its resolved soon. :)

sindaco09 avatar Oct 11 '16 03:10 sindaco09

If possible, can you provide more details? Under which conditions does this error occur? Is it easy to reproduce? Which extension of AbstractAudioRecorder are you using (RawAudioRecorder or EncodedAudioRecorder)?

Kaljurand avatar Oct 11 '16 22:10 Kaljurand

Unfortunately i received a crash report via crashlytics from another user's device (Nexus 6p OS 7.0). So i'll have to wait until tomorrow before i can get my hands on that type of phone for a more detailed report. I'm using AbstractAudioRecorder RawAudioRecorder

Fatal Exception: java.lang.ArrayIndexOutOfBoundsException: src.length=2560 srcPos=0 dst.length=1120000 dstPos=87040 length=-1
       at java.lang.System.arraycopy(System.java)
       at ee.ioc.phon.android.speechutils.AbstractAudioRecorder.read(AbstractAudioRecorder.java:143)
       at ee.ioc.phon.android.speechutils.AbstractAudioRecorder.recorderLoop(AbstractAudioRecorder.java:321)
       at ee.ioc.phon.android.speechutils.AbstractAudioRecorder$1.run(AbstractAudioRecorder.java:287)

#0. Crashed: Thread-18: 0 0 0x0000000000000000
       at java.lang.System.arraycopy(System.java)
       at ee.ioc.phon.android.speechutils.AbstractAudioRecorder.read(AbstractAudioRecorder.java:143)
       at ee.ioc.phon.android.speechutils.AbstractAudioRecorder.recorderLoop(AbstractAudioRecorder.java:321)
       at ee.ioc.phon.android.speechutils.AbstractAudioRecorder$1.run(AbstractAudioRecorder.java:287) 

I'm using willblashko's AlexaAndroid application https://github.com/willblaschko/AlexaAndroid (within my own application) but tracked the error to this library (although may very well be an error in the AlexaAndroid app)

I've only seen this with OS 7.+, I have a Samsung Galaxy s5 OS 6.0.1 which works fine. The general behavior is that the user speaks into the microphone, stops speaking into the microphone, and followed by a crash. A way to reproduce it is by downloading this application https://play.google.com/store/apps/details?id=com.willblaschko.android.alexavoicelibrary (or clone from git repo above), pressing the microphone button, speaking, finish speaking, and then every now and then it will crash. the report i received suggested that the error originates from the AbstractAudioRecorder class, if you would like i can send the full report via direct message. thanks for getting back so quickly, i'll be able to try more devices with your library directly tomorrow to hopefully narrow this down

sindaco09 avatar Oct 12 '16 04:10 sindaco09

10-12 11:19:44.194 15450-20577/com.stefan.project E/AndroidRuntime: FATAL EXCEPTION: Thread-23
                                                                              Process: com.stefan.project, PID: 15450
                                                                              java.lang.ArrayIndexOutOfBoundsException: src.length=2560 srcPos=0 dst.length=1120000 dstPos=66560 length=-1
                                                                                  at java.lang.System.arraycopy(Native Method)
                                                                                  at ee.ioc.phon.android.speechutils.AbstractAudioRecorder.read(AbstractAudioRecorder.java:143)
                                                                                  at ee.ioc.phon.android.speechutils.AbstractAudioRecorder.recorderLoop(AbstractAudioRecorder.java:321)
                                                                                  at ee.ioc.phon.android.speechutils.AbstractAudioRecorder$1.run(AbstractAudioRecorder.java:287)

So using nexus 6p OS7.0, i get this error when the microphone stops recording

sindaco09 avatar Oct 12 '16 18:10 sindaco09

I could reproduce it now with Kõnele 1.5.20 (which uses speechutils) running on Nexus 5X / Android v7.0. (I did update all the gradle/SDK/buildtools/etc. dependencies first, not sure if this is relevant.) It seems that the problem was that AudioRecord-JNI sometimes returned Error -4 which was not anticipated by speechutils (which is obviously a bug). I guess it started doing that in Android v7.

It should be fixed in a278b8a03cfecc5c51750c545f8b6280da8c3188

Thanks for reporting!

Kaljurand avatar Oct 12 '16 21:10 Kaljurand

This fixed the issue I was seeing in Android v7, thanks!

willblaschko avatar Oct 12 '16 22:10 willblaschko

I was able to reproduce this again, in the new version. Is it the final iteration of += 2 in the for loop that's throwing the the ArrayIndexOutOfBoundsException?

syedtalha avatar Oct 22 '16 03:10 syedtalha

OK, reopening. The iteration in getRms does look too complicated and should be refactored anyway.

In case you have any more details on under which conditions this happens, please let me know.

Kaljurand avatar Oct 22 '16 21:10 Kaljurand

` while (recorder != null && !recorder.isPausing()) { if (recorder != null) { if (sink != null && recorder != null) { sink.write(recorder.consumeRecording()); }

            }

            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }`

This is the context withing which the isPausing() is called.

sink is a BufferedSink from okhttp

syedtalha avatar Dec 21 '16 06:12 syedtalha