From 087c3dcfbb55ad3c0cb9e98d39a906889b76d955 Mon Sep 17 00:00:00 2001 From: Shunkai Yao Date: Fri, 7 Jul 2023 23:53:26 +0000 Subject: [PATCH] Check Visualizer.getWaveForm input array size Bug: 288898397 Test: atest android.media.audio.cts.VisualizerTest (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:6917a11b6f18f3a939b2d82d48311068ce5f1a59) Merged-In: Ie545e2bc7dc8627ad8ffe9f9b611ecb5b6e42eb7 Change-Id: Ie545e2bc7dc8627ad8ffe9f9b611ecb5b6e42eb7 --- media/java/android/media/audiofx/Visualizer.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/media/java/android/media/audiofx/Visualizer.java b/media/java/android/media/audiofx/Visualizer.java index f3dfeb665cc7d..2795cfe4ba610 100644 --- a/media/java/android/media/audiofx/Visualizer.java +++ b/media/java/android/media/audiofx/Visualizer.java @@ -455,11 +455,13 @@ public class Visualizer { * a number of consecutive 8-bit (unsigned) mono PCM samples equal to the capture size returned * by {@link #getCaptureSize()}. *

This method must be called when the Visualizer is enabled. - * @param waveform array of bytes where the waveform should be returned + * @param waveform array of bytes where the waveform should be returned, array length must be + * at least equals to the capture size returned by {@link #getCaptureSize()}. * @return {@link #SUCCESS} in case of success, * {@link #ERROR_NO_MEMORY}, {@link #ERROR_INVALID_OPERATION} or {@link #ERROR_DEAD_OBJECT} * in case of failure. * @throws IllegalStateException + * @throws IllegalArgumentException */ public int getWaveForm(byte[] waveform) throws IllegalStateException { @@ -467,6 +469,12 @@ public class Visualizer { if (mState != STATE_ENABLED) { throw(new IllegalStateException("getWaveForm() called in wrong state: "+mState)); } + int captureSize = getCaptureSize(); + if (captureSize > waveform.length) { + throw(new IllegalArgumentException("getWaveForm() called with illegal size: " + + waveform.length + " expecting at least " + + captureSize + " bytes")); + } return native_getWaveForm(waveform); } }