/* * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /** * @test * @bug 7088367 * @summary SourceDataLine.write and TargetDataLine.read don't throw ArrayIndexOutOfBoundsException * @author Alex Menkov */ import javax.sound.sampled.AudioSystem; import javax.sound.sampled.DataLine; import javax.sound.sampled.Line; import javax.sound.sampled.LineUnavailableException; import javax.sound.sampled.Mixer; import javax.sound.sampled.SourceDataLine; import javax.sound.sampled.TargetDataLine; public class DataLine_ArrayIndexOutOfBounds { static int total = 0; static int failed = 0; // shared buffer for all tests static final byte[] buffer = new byte[5000000]; // the class describes different test scenarios (buffer properties) static abstract class Scenario { abstract int getBufferOffset(DataLine line); abstract int getBufferLength(DataLine line); } // scenarios to tests static Scenario[] scenarios = new Scenario[]{ new Scenario() { public String toString() { return "offset is near Integer.MAX_VALUE"; } public int getBufferOffset(DataLine line) { return Integer.MAX_VALUE - 4096; } public int getBufferLength(DataLine line) { return 65536; } }, new Scenario() { public String toString() { return "offset is less than buffer.length, length is large"; } int getBufferOffset(DataLine line) { return buffer.length / 10; } int getBufferLength(DataLine line) { return Integer.MAX_VALUE - getBufferOffset(line) + 4096; } } }; public static void main(String[] args) throws Exception { Mixer.Info[] infos = AudioSystem.getMixerInfo(); log("" + infos.length + " mixers detected"); for (int i=0; i