-
Bug
-
Resolution: Fixed
-
P4
-
1.3.0
-
beta2
-
x86
-
windows_nt
-
Verified
Name: krC82822 Date: 02/07/2001
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)
The program below captures audio continuously from a JavaSound TargetDataLine
obtained from AudioSystem.getLine, printing the number of bytes captured to
System.out every 100000 bytes. It throws an ArrayIndexOutOfBoundsException
after printing 2147400000, the largest multiple of 100000 less than 2^31. The
problem appears to be in com.sun.media.sound.CircularBuffer, which maintains
int counts of the number of bytes written to and read from it. These counts
overflow at 2^31.
Here is a stack trace for the ArrayIndexOutOfBoundsException:
java.lang.ArrayIndexOutOfBoundsException
at java.lang.System.arraycopy(Native Method)
at com.sun.media.sound.CircularBuffer.read(CircularBuffer.java:127)
at com.sun.media.sound.SimpleInputDevice$InputDeviceDataLine.read
(SimpleInputDevice.java:669)
at JavaSoundCaptureTester.main(JavaSoundCaptureTester.java:49)
at java.lang.reflect.Method.invoke(Native Method)
at com.borland.jbuilder.util.BootStrap.invokeMain(Unknown Source)
at com.borland.jbuilder.util.BootStrap.main(Unknown Source)
Here is the program:
import javax.sound.sampled.*;
public class JavaSoundCaptureTester {
public static void main(String[] inArgs) {
final int sampleRate = 48000; // Hz
final int sampleSize = 16; // bits
final int numChannels = 2;
final boolean samplesSigned = true;
final boolean samplesBigEndian = true;
final int bytesPerFrame = numChannels * sampleSize / 8;
final int inputBufferSize = 5 * sampleRate * bytesPerFrame; //
bytes
final int inputReadSize = 1000 * bytesPerFrame; //
bytes
final long maxInputSize = 50L * 1000 * 1000 * 1000; //
bytes
final int reportPeriod = 100 * 1000; //
bytes
try {
AudioFormat audioFormat = new AudioFormat(
sampleRate,
sampleSize,
numChannels,
samplesSigned,
samplesBigEndian);
DataLine.Info lineInfo = new DataLine.Info(
TargetDataLine.class,
audioFormat,
inputBufferSize);
if (!AudioSystem.isLineSupported(lineInfo)) {
throw new Exception("Audio input for requested format not
supported.");
}
TargetDataLine line = (TargetDataLine) AudioSystem.getLine
(lineInfo);
line.open(audioFormat, inputBufferSize);
line.start();
byte[] bytes = new byte[inputReadSize];
long byteCount = 0;
long nextReportCount = reportPeriod;
while (byteCount <= maxInputSize) {
int readSize = line.read(bytes, 0, inputReadSize);
if (readSize != inputReadSize) {
System.out.println("got " + readSize + " bytes when
requested " + inputReadSize);
break;
}
byteCount += readSize;
if (byteCount >= nextReportCount) {
System.out.println(byteCount);
nextReportCount += reportPeriod;
}
}
line.stop();
line.close();
} catch (Exception e) {
e.printStackTrace();;
}
}
}
(Review ID: 109588)
=====================================================================