Skip to content

Commit 87298d2

Browse files
committed
8312535: MidiSystem.getSoundbank() throws unexpected SecurityException
Reviewed-by: prr
1 parent 78f74bc commit 87298d2

File tree

3 files changed

+66
-7
lines changed

3 files changed

+66
-7
lines changed

src/java.desktop/share/classes/com/sun/media/sound/JARSoundbankReader.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -32,6 +32,7 @@
3232
import java.io.InputStreamReader;
3333
import java.net.URL;
3434
import java.net.URLClassLoader;
35+
import java.security.AccessController;
3536
import java.util.ArrayList;
3637
import java.util.Objects;
3738

@@ -40,6 +41,7 @@
4041
import javax.sound.midi.spi.SoundbankReader;
4142

4243
import sun.reflect.misc.ReflectUtil;
44+
import sun.security.action.GetBooleanAction;
4345

4446
/**
4547
* JarSoundbankReader is used to read soundbank object from jar files.
@@ -48,12 +50,15 @@
4850
*/
4951
public final class JARSoundbankReader extends SoundbankReader {
5052

51-
/*
52-
* Name of the system property that enables the Jar soundbank loading
53-
* true if jar sound bank is allowed to be loaded
54-
* default is false
53+
/**
54+
* Value of the system property that enables the Jar soundbank loading
55+
* {@code true} if jar sound bank is allowed to be loaded default is
56+
* {@code false}.
5557
*/
56-
private final static String JAR_SOUNDBANK_ENABLED = "jdk.sound.jarsoundbank";
58+
@SuppressWarnings("removal")
59+
private static final boolean JAR_SOUNDBANK_ENABLED =
60+
AccessController.doPrivileged(
61+
new GetBooleanAction("jdk.sound.jarsoundbank"));
5762

5863
private static boolean isZIP(URL url) {
5964
boolean ok = false;
@@ -78,7 +83,7 @@ private static boolean isZIP(URL url) {
7883
public Soundbank getSoundbank(URL url)
7984
throws InvalidMidiDataException, IOException {
8085
Objects.requireNonNull(url);
81-
if (!Boolean.getBoolean(JAR_SOUNDBANK_ENABLED) || !isZIP(url))
86+
if (!JAR_SOUNDBANK_ENABLED || !isZIP(url))
8287
return null;
8388

8489
ArrayList<Soundbank> soundbanks = new ArrayList<>();
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright Amazon.com Inc. 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 java.io.File;
25+
import java.nio.file.Files;
26+
import java.nio.file.Paths;
27+
28+
import javax.sound.midi.InvalidMidiDataException;
29+
import javax.sound.midi.MidiSystem;
30+
31+
/**
32+
* @test
33+
* @bug 8312535
34+
* @summary MidiSystem.getSoundbank() throws unexpected SecurityException
35+
* @run main/othervm/policy=security.policy GetSoundBankSecurityException
36+
*/
37+
public final class GetSoundBankSecurityException {
38+
39+
public static void main(String[] args) throws Exception {
40+
File tempFile = new File("sound.bank");
41+
tempFile.createNewFile();
42+
try {
43+
MidiSystem.getSoundbank(tempFile);
44+
throw new RuntimeException("InvalidMidiDataException is expected");
45+
} catch (InvalidMidiDataException ignore) {
46+
} finally {
47+
Files.delete(Paths.get(tempFile.getAbsolutePath()));
48+
}
49+
}
50+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
grant {
2+
permission java.io.FilePermission "*", "read,write,delete";
3+
permission java.util.PropertyPermission "user.dir", "read";
4+
};

0 commit comments

Comments
 (0)