提交 1f711967 编写于 作者: A amenkov

6992523: FindBugs scan - Malicious code vulnerability Warnings in com.sun.media.sound.*

Reviewed-by: alexp
上级 4a345228
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
package com.sun.media.sound; package com.sun.media.sound;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -439,10 +440,10 @@ public class DLSInstrument extends ModelInstrument { ...@@ -439,10 +440,10 @@ public class DLSInstrument extends ModelInstrument {
} }
public byte[] getGuid() { public byte[] getGuid() {
return guid; return guid == null ? null : Arrays.copyOf(guid, guid.length);
} }
public void setGuid(byte[] guid) { public void setGuid(byte[] guid) {
this.guid = guid; this.guid = guid == null ? null : Arrays.copyOf(guid, guid.length);
} }
} }
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
package com.sun.media.sound; package com.sun.media.sound;
import java.io.InputStream; import java.io.InputStream;
import java.util.Arrays;
import javax.sound.midi.Soundbank; import javax.sound.midi.Soundbank;
import javax.sound.midi.SoundbankResource; import javax.sound.midi.SoundbankResource;
import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioFormat;
...@@ -113,10 +114,10 @@ public class DLSSample extends SoundbankResource { ...@@ -113,10 +114,10 @@ public class DLSSample extends SoundbankResource {
} }
public byte[] getGuid() { public byte[] getGuid() {
return guid; return guid == null ? null : Arrays.copyOf(guid, guid.length);
} }
public void setGuid(byte[] guid) { public void setGuid(byte[] guid) {
this.guid = guid; this.guid = guid == null ? null : Arrays.copyOf(guid, guid.length);
} }
} }
...@@ -24,6 +24,8 @@ ...@@ -24,6 +24,8 @@
*/ */
package com.sun.media.sound; package com.sun.media.sound;
import java.util.Arrays;
/** /**
* Connection blocks are used to connect source variable * Connection blocks are used to connect source variable
* to a destination variable. * to a destination variable.
...@@ -117,19 +119,17 @@ public class ModelConnectionBlock { ...@@ -117,19 +119,17 @@ public class ModelConnectionBlock {
} }
public ModelSource[] getSources() { public ModelSource[] getSources() {
return sources; return Arrays.copyOf(sources, sources.length);
} }
public void setSources(ModelSource[] source) { public void setSources(ModelSource[] source) {
this.sources = source; this.sources = source == null ? no_sources : Arrays.copyOf(source, source.length);
} }
public void addSource(ModelSource source) { public void addSource(ModelSource source) {
ModelSource[] oldsources = sources; ModelSource[] oldsources = sources;
sources = new ModelSource[oldsources.length + 1]; sources = new ModelSource[oldsources.length + 1];
for (int i = 0; i < oldsources.length; i++) { System.arraycopy(oldsources, 0, sources, 0, oldsources.length);
sources[i] = oldsources[i];
}
sources[sources.length - 1] = source; sources[sources.length - 1] = source;
} }
} }
...@@ -503,7 +503,7 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer { ...@@ -503,7 +503,7 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer {
firstVoice = true; firstVoice = true;
voiceNo = 0; voiceNo = 0;
int tunedKey = (int)(Math.round(tuning.getTuning()[noteNumber]/100.0)); int tunedKey = (int)(Math.round(tuning.getTuning(noteNumber)/100.0));
play_noteNumber = noteNumber; play_noteNumber = noteNumber;
play_velocity = velocity; play_velocity = velocity;
play_delay = delay; play_delay = delay;
...@@ -607,7 +607,7 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer { ...@@ -607,7 +607,7 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer {
firstVoice = true; firstVoice = true;
voiceNo = 0; voiceNo = 0;
int tunedKey = (int)(Math.round(tuning.getTuning()[noteNumber]/100.0)); int tunedKey = (int)(Math.round(tuning.getTuning(noteNumber)/100.0));
play_noteNumber = noteNumber; play_noteNumber = noteNumber;
play_velocity = lastVelocity[noteNumber]; play_velocity = lastVelocity[noteNumber];
play_releasetriggered = true; play_releasetriggered = true;
...@@ -632,7 +632,7 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer { ...@@ -632,7 +632,7 @@ public class SoftChannel implements MidiChannel, ModelDirectedPlayer {
int delay = play_delay; int delay = play_delay;
boolean releasetriggered = play_releasetriggered; boolean releasetriggered = play_releasetriggered;
SoftPerformer p = current_instrument.getPerformers()[performerIndex]; SoftPerformer p = current_instrument.getPerformer(performerIndex);
if (firstVoice) { if (firstVoice) {
firstVoice = false; firstVoice = false;
......
...@@ -76,7 +76,12 @@ public class SoftInstrument extends Instrument { ...@@ -76,7 +76,12 @@ public class SoftInstrument extends Instrument {
return data; return data;
} }
/* am: currently getPerformers() is not used (replaced with getPerformer(int))
public SoftPerformer[] getPerformers() { public SoftPerformer[] getPerformers() {
return performers; return performers;
} }
*/
public SoftPerformer getPerformer(int index) {
return performers[index];
}
} }
...@@ -505,7 +505,7 @@ public abstract class SoftMixingDataLine implements DataLine { ...@@ -505,7 +505,7 @@ public abstract class SoftMixingDataLine implements DataLine {
} }
public Control[] getControls() { public Control[] getControls() {
return controls; return Arrays.copyOf(controls, controls.length);
} }
public boolean isControlSupported(Type control) { public boolean isControlSupported(Type control) {
......
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
*/ */
package com.sun.media.sound; package com.sun.media.sound;
import java.util.Arrays;
import javax.sound.midi.MidiDevice; import javax.sound.midi.MidiDevice;
import javax.sound.midi.MidiDevice.Info; import javax.sound.midi.MidiDevice.Info;
import javax.sound.midi.spi.MidiDeviceProvider; import javax.sound.midi.spi.MidiDeviceProvider;
...@@ -39,7 +40,7 @@ public class SoftProvider extends MidiDeviceProvider { ...@@ -39,7 +40,7 @@ public class SoftProvider extends MidiDeviceProvider {
private static Info[] softinfos = {softinfo}; private static Info[] softinfos = {softinfo};
public MidiDevice.Info[] getDeviceInfo() { public MidiDevice.Info[] getDeviceInfo() {
return softinfos; return Arrays.copyOf(softinfos, softinfos.length);
} }
public MidiDevice getDevice(MidiDevice.Info info) { public MidiDevice getDevice(MidiDevice.Info info) {
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
package com.sun.media.sound; package com.sun.media.sound;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import javax.sound.midi.Patch; import javax.sound.midi.Patch;
...@@ -234,8 +235,10 @@ public class SoftTuning { ...@@ -234,8 +235,10 @@ public class SoftTuning {
} }
} }
// am: getTuning(int) is more effective.
// currently getTuning() is used only by tests
public double[] getTuning() { public double[] getTuning() {
return tuning; return Arrays.copyOf(tuning, tuning.length);
} }
public double getTuning(int noteNumber) { public double getTuning(int noteNumber) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册