Skip to content

Commit

Permalink
Added one more check for stream length.
Browse files Browse the repository at this point in the history
  • Loading branch information
finnkuusisto committed Mar 15, 2012
1 parent 0680c37 commit 7127e21
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/kuusisto/tinysound/TinySound.java
Expand Up @@ -382,6 +382,11 @@ private static byte[] readAllBytesOneChannel(AudioInputStream stream) {
//read all the bytes (assuming 1-channel)
int numBytes = (int)stream.getFrameLength() *
stream.getFormat().getFrameSize();
//should only be negative if too large
if (numBytes < 0) {
System.err.println("Audio resource too long!");
return null;
}
byte[] data = new byte[numBytes];
try {
int numRead = stream.read(data);
Expand Down Expand Up @@ -412,6 +417,11 @@ private static byte[][] readAllBytesTwoChannel(AudioInputStream stream) {
//read all the bytes (assuming 16-bit, 2-channel)
int numBytesPerChannel = (int)stream.getFrameLength() *
(stream.getFormat().getFrameSize() / 2);
//should only be negative if too large
if (numBytesPerChannel < 0) {
System.err.println("Audio resource too long!");
return null;
}
byte[] left = new byte[numBytesPerChannel];
byte[] right = new byte[numBytesPerChannel];
byte[][] data = null;
Expand Down

0 comments on commit 7127e21

Please sign in to comment.