src/share/classes/com/sun/media/sound/WaveFileReader.java

Print this page

        

@@ -51,17 +51,10 @@
 public final class WaveFileReader extends SunFileReader {
 
     private static final int MAX_READ_LENGTH = 12;
 
     /**
-     * Constructs a new WaveFileReader object.
-     */
-    public WaveFileReader() {
-    }
-
-
-    /**
      * Obtains the audio file format of the input stream provided.  The stream must
      * point to valid audio file data.  In general, audio file providers may
      * need to read some data from the stream before determining whether they
      * support it.  These parsers must
      * be able to mark the stream, read enough data to determine whether they

@@ -302,10 +295,13 @@
             // we don't support any other WAVE formats....
             throw new UnsupportedAudioFileException("Not a supported WAV file");
         }
         // channels
         channels = rlshort(dis); nread += 2;
+        if (channels <= 0) {
+            throw new UnsupportedAudioFileException("Invalid number of channels");
+        }
 
         // sample rate.
         sampleRate = rllong(dis); nread += 4;
 
         // this is the avgBytesPerSec

@@ -314,10 +310,13 @@
         // this is blockAlign value
         blockAlign = rlshort(dis); nread += 2;
 
         // this is the PCM-specific value bitsPerSample
         sampleSizeInBits = (int)rlshort(dis); nread += 2;
+        if (sampleSizeInBits <= 0) {
+            throw new UnsupportedAudioFileException("Invalid bitsPerSample");
+        }
 
         // if sampleSizeInBits==8, we need to use PCM_UNSIGNED
         if ((sampleSizeInBits==8) && encoding.equals(AudioFormat.Encoding.PCM_SIGNED))
             encoding = AudioFormat.Encoding.PCM_UNSIGNED;
 

@@ -371,7 +370,6 @@
         return new WaveFileFormat(AudioFileFormat.Type.WAVE,
                                   totallength,
                                   format,
                                   dataLength / format.getFrameSize());
     }
-
 }