mirror of
https://github.com/samsonjs/media.git
synced 2026-04-07 11:35:46 +00:00
Avoid potential ArrayStoreException with audio processors
The app is able to pass a more specialized array type, so the Arrays.copyOf call produces an array into which it's not valid to store arbitrary AudioProcessors. Create a new array and copy into it to avoid this problem. PiperOrigin-RevId: 264779164
This commit is contained in:
parent
9e3bee89e1
commit
886fe910a8
2 changed files with 16 additions and 2 deletions
|
|
@ -37,7 +37,6 @@ import java.nio.ByteBuffer;
|
|||
import java.nio.ByteOrder;
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
|
|
@ -122,7 +121,15 @@ public final class DefaultAudioSink implements AudioSink {
|
|||
* audioProcessors} applied before silence skipping and playback parameters.
|
||||
*/
|
||||
public DefaultAudioProcessorChain(AudioProcessor... audioProcessors) {
|
||||
this.audioProcessors = Arrays.copyOf(audioProcessors, audioProcessors.length + 2);
|
||||
// The passed-in type may be more specialized than AudioProcessor[], so allocate a new array
|
||||
// rather than using Arrays.copyOf.
|
||||
this.audioProcessors = new AudioProcessor[audioProcessors.length + 2];
|
||||
System.arraycopy(
|
||||
/* src= */ audioProcessors,
|
||||
/* srcPos= */ 0,
|
||||
/* dest= */ this.audioProcessors,
|
||||
/* destPos= */ 0,
|
||||
/* length= */ audioProcessors.length);
|
||||
silenceSkippingAudioProcessor = new SilenceSkippingAudioProcessor();
|
||||
sonicAudioProcessor = new SonicAudioProcessor();
|
||||
this.audioProcessors[audioProcessors.length] = silenceSkippingAudioProcessor;
|
||||
|
|
|
|||
|
|
@ -67,6 +67,13 @@ public final class DefaultAudioSinkTest {
|
|||
/* enableConvertHighResIntPcmToFloat= */ false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlesSpecializedAudioProcessorArray() {
|
||||
defaultAudioSink =
|
||||
new DefaultAudioSink(
|
||||
AudioCapabilities.DEFAULT_AUDIO_CAPABILITIES, new TeeAudioProcessor[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlesBufferAfterReset() throws Exception {
|
||||
configureDefaultAudioSink(CHANNEL_COUNT_STEREO);
|
||||
|
|
|
|||
Loading…
Reference in a new issue