Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added one more check for stream length.

  • Loading branch information...
commit 7127e21d428cb72281d520cea99e18bcee6e28d1 1 parent 0680c37
@finnkuusisto authored
Showing with 10 additions and 0 deletions.
  1. +10 −0 src/kuusisto/tinysound/TinySound.java
View
10 src/kuusisto/tinysound/TinySound.java
@@ -382,6 +382,11 @@ else if (numChannels == 2) {
//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);
@@ -412,6 +417,11 @@ else if (numChannels == 2) {
//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;
Please sign in to comment.
Something went wrong with that request. Please try again.