Skip to content

Commit

Permalink
8312535: MidiSystem.getSoundbank() throws unexpected SecurityException
Browse files Browse the repository at this point in the history
Backport-of: 87298d2ade41c689d3140981a123b0e9130fc651
  • Loading branch information
mrserb committed Oct 18, 2023
1 parent c851317 commit 1e9eb53
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 7 deletions.
19 changes: 12 additions & 7 deletions jdk/src/share/classes/com/sun/media/sound/JARSoundbankReader.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2023, 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
Expand Down Expand Up @@ -31,13 +31,15 @@
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.AccessController;
import java.util.ArrayList;
import java.util.Objects;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.Soundbank;
import javax.sound.midi.spi.SoundbankReader;

import sun.reflect.misc.ReflectUtil;
import sun.security.action.GetBooleanAction;

/**
* JarSoundbankReader is used to read soundbank object from jar files.
Expand All @@ -46,12 +48,15 @@
*/
public final class JARSoundbankReader extends SoundbankReader {

/*
* Name of the system property that enables the Jar soundbank loading
* true if jar sound bank is allowed to be loaded
* default is false
/**
* Value of the system property that enables the Jar soundbank loading
* {@code true} if jar sound bank is allowed to be loaded default is
* {@code false}.
*/
private final static String JAR_SOUNDBANK_ENABLED = "jdk.sound.jarsoundbank";
@SuppressWarnings("removal")
private static final boolean JAR_SOUNDBANK_ENABLED =
AccessController.doPrivileged(
new GetBooleanAction("jdk.sound.jarsoundbank"));

private static boolean isZIP(URL url) {
boolean ok = false;
Expand All @@ -77,7 +82,7 @@ private static boolean isZIP(URL url) {
public Soundbank getSoundbank(URL url)
throws InvalidMidiDataException, IOException {
Objects.requireNonNull(url);
if (!Boolean.getBoolean(JAR_SOUNDBANK_ENABLED) || !isZIP(url))
if (!JAR_SOUNDBANK_ENABLED || !isZIP(url))
return null;

ArrayList<Soundbank> soundbanks = new ArrayList<Soundbank>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright Amazon.com Inc. 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.
*/

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiSystem;

/**
* @test
* @bug 8312535
* @summary MidiSystem.getSoundbank() throws unexpected SecurityException
* @run main/othervm/policy=security.policy GetSoundBankSecurityException
*/
public final class GetSoundBankSecurityException {

public static void main(String[] args) throws Exception {
File tempFile = new File("sound.bank");
tempFile.createNewFile();
try {
MidiSystem.getSoundbank(tempFile);
throw new RuntimeException("InvalidMidiDataException is expected");
} catch (InvalidMidiDataException ignore) {
} finally {
Files.delete(Paths.get(tempFile.getAbsolutePath()));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
grant {
permission java.io.FilePermission "*", "read,write,delete";
permission java.util.PropertyPermission "user.dir", "read";
};

1 comment on commit 1e9eb53

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.