|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. |
| 3 | + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | + * |
| 5 | + * This code is free software; you can redistribute it and/or modify it |
| 6 | + * under the terms of the GNU General Public License version 2 only, as |
| 7 | + * published by the Free Software Foundation. |
| 8 | + * |
| 9 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 10 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 12 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 13 | + * accompanied this code). |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License version |
| 16 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 17 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | + * |
| 19 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 20 | + * or visit www.oracle.com if you need additional information or have any |
| 21 | + * questions. |
| 22 | + */ |
| 23 | + |
| 24 | +import javax.sound.midi.InvalidMidiDataException; |
| 25 | +import javax.sound.midi.MidiSystem; |
| 26 | +import java.io.ByteArrayInputStream; |
| 27 | +import java.io.IOException; |
| 28 | + |
| 29 | +/** |
| 30 | + * @test |
| 31 | + * @bug 8350813 |
| 32 | + * @summary Rendering of bulky sound bank from MIDI sequence can cause OutOfMemoryError. |
| 33 | + * @run main/othervm -Xmx1g BulkSoundBank |
| 34 | + */ |
| 35 | + |
| 36 | +public class BulkSoundBank { |
| 37 | + static final byte[] midi = {77, 84, 104, 100, 0, 0, 0, 6, 0, 0, 0, 1, 1, |
| 38 | + -32, 77, 84, 114, 107, 0, 0, 0, 50, 0, -1, 88, 4, 4, 2, 24, 8, 0, -1, |
| 39 | + 81, 3, 7, -95, 32, 0, -112, 60, 64, -125, 96, -128, 60, 64, -125, -44, |
| 40 | + -51, 32, -112, 48, 64, 1, -128, 48, 64, -127, -64, -45, 127, -112, 60, |
| 41 | + 64, 1, -128, 60, 64, 0, -1, 47, 0}; |
| 42 | + |
| 43 | + public static void main(String[] args) throws IOException { |
| 44 | + try (ByteArrayInputStream bis = new ByteArrayInputStream(midi)) { |
| 45 | + MidiSystem.getSoundbank(bis); |
| 46 | + throw new RuntimeException("Test should throw InvalidMidiDataException" |
| 47 | + + " but it did not."); |
| 48 | + } catch (InvalidMidiDataException imda) { |
| 49 | + System.out.println("Caught InvalidMidiDataException as expected"); |
| 50 | + } |
| 51 | + } |
| 52 | +} |
| 53 | + |
0 commit comments