Program: 61799
Project: 61799
Buggy source:
@Override public boolean setSound(InputStream is,int newSoundFormat){
  int newSoundRate=-1;
  boolean newSoundSize=false;
  boolean newSoundType=false;
  long newSoundSampleCount=-1;
  byte newSoundData[];
switch (newSoundFormat) {
case SoundFormat.FORMAT_UNCOMPRESSED_LITTLE_ENDIAN:
    try (AudioInputStream audioIs=AudioSystem.getAudioInputStream(new BufferedInputStream(is))){
      AudioFormat fmt=audioIs.getFormat();
      newSoundType=fmt.getChannels() == 2;
      newSoundSize=fmt.getSampleSizeInBits() == 16;
      newSoundSampleCount=audioIs.getFrameLength();
      newSoundData=Helper.readStream(audioIs);
      newSoundRate=(int)Math.round(fmt.getSampleRate());
switch (newSoundRate) {
case 5512:
        newSoundRate=0;
      break;
case 11025:
    newSoundRate=1;
  break;
case 22050:
newSoundRate=2;
break;
case 44100:
newSoundRate=3;
break;
default :
return false;
}
}
 catch (UnsupportedAudioFileException|IOException ex) {
return false;
}
break;
case SoundFormat.FORMAT_MP3:
BufferedInputStream bis=new BufferedInputStream(is);
loadID3v2(bis);
byte mp3data[]=Helper.readStream(bis);
final int ID3_V1_LENTGH=128;
final int ID3_V1_EXT_LENGTH=227;
if (mp3data.length > ID3_V1_LENTGH) {
if (mp3data[mp3data.length - ID3_V1_LENTGH] == 'T' && mp3data[mp3data.length - ID3_V1_LENTGH + 1] == 'A' && mp3data[mp3data.length - ID3_V1_LENTGH + 2] == 'G') {
mp3data=Arrays.copyOf(mp3data,mp3data.length - ID3_V1_LENTGH);
if (mp3data.length > ID3_V1_EXT_LENGTH) {
if (mp3data[mp3data.length - ID3_V1_EXT_LENGTH] == 'T' && mp3data[mp3data.length - ID3_V1_EXT_LENGTH + 1] == 'A' && mp3data[mp3data.length - ID3_V1_EXT_LENGTH + 2] == 'G' && mp3data[mp3data.length - ID3_V1_EXT_LENGTH + 3] == '+') {
mp3data=Arrays.copyOf(mp3data,mp3data.length - ID3_V1_EXT_LENGTH);
}
}
}
}
try {
MP3SOUNDDATA snd=new MP3SOUNDDATA(new ByteArrayInputStream(mp3data),true);
if (!snd.frames.isEmpty()) {
MP3FRAME fr=snd.frames.get(0);
newSoundRate=fr.getSamplingRate();
switch (newSoundRate) {
case 11025:
newSoundRate=1;
break;
case 22050:
newSoundRate=2;
break;
case 44100:
newSoundRate=3;
break;
default :
return false;
}
newSoundSize=true;
newSoundType=fr.isStereo();
int len=snd.sampleCount();
if (fr.isStereo()) {
len=len / 2;
}
newSoundSampleCount=len;
}
ByteArrayOutputStream baos=new ByteArrayOutputStream();
SWFOutputStream sos=new SWFOutputStream(baos,SWF.DEFAULT_VERSION);
sos.writeSI16(0);
sos.write(mp3data);
newSoundData=baos.toByteArray();
}
 catch (IOException ex) {
return false;
}
break;
default :
return false;
}
if (newSoundData != null) {
this.soundSize=newSoundSize;
this.soundRate=newSoundRate;
this.soundSampleCount=newSoundSampleCount;
this.soundData=newSoundData;
this.soundType=newSoundType;
this.soundFormat=newSoundFormat;
return true;
}
return false;
}

Fixed version (ground truth):
@Override public boolean setSound(InputStream is,int newSoundFormat){
  int newSoundRate=-1;
  boolean newSoundSize=false;
  boolean newSoundType=false;
  long newSoundSampleCount=-1;
  byte newSoundData[];
switch (newSoundFormat) {
case SoundFormat.FORMAT_UNCOMPRESSED_LITTLE_ENDIAN:
    try (AudioInputStream audioIs=AudioSystem.getAudioInputStream(new BufferedInputStream(is))){
      AudioFormat fmt=audioIs.getFormat();
      newSoundType=fmt.getChannels() == 2;
      newSoundSize=fmt.getSampleSizeInBits() == 16;
      newSoundSampleCount=audioIs.getFrameLength();
      newSoundData=Helper.readStream(audioIs);
      newSoundRate=(int)Math.round(fmt.getSampleRate());
switch (newSoundRate) {
case 5512:
        newSoundRate=0;
      break;
case 11025:
    newSoundRate=1;
  break;
case 22050:
newSoundRate=2;
break;
case 44100:
newSoundRate=3;
break;
default :
return false;
}
}
 catch (UnsupportedAudioFileException|IOException ex) {
return false;
}
break;
case SoundFormat.FORMAT_MP3:
BufferedInputStream bis=new BufferedInputStream(is);
loadID3v2(bis);
byte mp3data[]=Helper.readStream(bis);
final int ID3_V1_LENTGH=128;
final int ID3_V1_EXT_LENGTH=227;
if (mp3data.length > ID3_V1_LENTGH) {
if (mp3data[mp3data.length - ID3_V1_LENTGH] == 'T' && mp3data[mp3data.length - ID3_V1_LENTGH + 1] == 'A' && mp3data[mp3data.length - ID3_V1_LENTGH + 2] == 'G') {
mp3data=Arrays.copyOf(mp3data,mp3data.length - ID3_V1_LENTGH);
if (mp3data.length > ID3_V1_EXT_LENGTH) {
if (mp3data[mp3data.length - ID3_V1_EXT_LENGTH] == 'T' && mp3data[mp3data.length - ID3_V1_EXT_LENGTH + 1] == 'A' && mp3data[mp3data.length - ID3_V1_EXT_LENGTH + 2] == 'G' && mp3data[mp3data.length - ID3_V1_EXT_LENGTH + 3] == '+') {
mp3data=Arrays.copyOf(mp3data,mp3data.length - ID3_V1_EXT_LENGTH);
}
}
}
}
try {
MP3SOUNDDATA snd=new MP3SOUNDDATA(new ByteArrayInputStream(mp3data),true);
if (!snd.frames.isEmpty()) {
MP3FRAME fr=snd.frames.get(0);
newSoundRate=fr.getSamplingRate();
switch (newSoundRate) {
case 11025:
newSoundRate=1;
break;
case 22050:
newSoundRate=2;
break;
case 44100:
newSoundRate=3;
break;
default :
return false;
}
newSoundSize=true;
newSoundType=fr.isStereo();
int len=snd.sampleCount();
if (fr.isStereo()) {
len=len / 2;
}
newSoundSampleCount=len;
}
ByteArrayOutputStream baos=new ByteArrayOutputStream();
SWFOutputStream sos=new SWFOutputStream(baos,SWF.DEFAULT_VERSION);
sos.writeSI16(0);
sos.write(mp3data);
newSoundData=baos.toByteArray();
}
 catch (IOException ex) {
return false;
}
break;
default :
return false;
}
if (newSoundData != null) {
this.soundSize=newSoundSize;
this.soundRate=newSoundRate;
this.soundSampleCount=newSoundSampleCount;
this.soundData=newSoundData;
this.soundType=newSoundType;
this.soundFormat=newSoundFormat;
setModified(true);
return true;
}
return false;
}