1 /*
2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
57 0x43, 0x4f, 0x4d, 0x4d, // chunkName
58 0, 0, 0, 100, // chunkLen
59 0, 10, // channels
60 0, 0, 0, 0, //
61 0, 0 // sampleSize
62 , 0, 0, 0, 0};
63 // big sampleSize
64 static byte[] wrongAIFFSSH =
65 {0x46, 0x4f, 0x52, 0x4d, //AiffFileFormat.AIFF_MAGIC
66 0, 0, 0, 0, // length
67 0, 0, 0, 0, // iffType
68 0x43, 0x4f, 0x4d, 0x4d, // chunkName
69 0, 0, 0, 100, // chunkLen
70 0, 10, // channels
71 0, 0, 0, 0, //
72 0, 33 // sampleSize
73 , 0, 0, 0, 0};
74 // empty channels
75 static byte[] wrongAUCh =
76 {0x2e, 0x73, 0x6e, 0x64,//AiffFileFormat.AU_SUN_MAGIC
77 0, 0, 0, 0, // headerSize
78 0, 0, 0, 0, // dataSize
79 0, 0, 0, 1, // encoding_local AuFileFormat.AU_ULAW_8
80 0, 0, 0, 0, // sampleRate
81 0, 0, 0, 0 // channels
82 };
83 // empty channels
84 static byte[] wrongWAVCh =
85 {0x52, 0x49, 0x46, 0x46, // WaveFileFormat.RIFF_MAGIC
86 1, 1, 1, 1, // fileLength
87 0x57, 0x41, 0x56, 0x45, // waveMagic
88 0x66, 0x6d, 0x74, 0x20, // FMT_MAGIC
89 3, 0, 0, 0, // length
90 1, 0, // wav_type WAVE_FORMAT_PCM
91 0, 0, // channels
92 0, 0, 0, 0, // sampleRate
93 0, 0, 0, 0, // avgBytesPerSec
94 0, 0, // blockAlign
95 1, 0, // sampleSizeInBits
96 0x64, 0x61, 0x74, 0x61, // WaveFileFormat.DATA_MAGIC
97 0, 0, 0, 0, // dataLength
98 };
99 // empty sampleSizeInBits
100 static byte[] wrongWAVSSB =
101 {0x52, 0x49, 0x46, 0x46, // WaveFileFormat.RIFF_MAGIC
102 1, 1, 1, 1, // fileLength
103 0x57, 0x41, 0x56, 0x45, // waveMagic
104 0x66, 0x6d, 0x74, 0x20, // FMT_MAGIC
105 3, 0, 0, 0, // length
106 1, 0, // wav_type WAVE_FORMAT_PCM
107 1, 0, // channels
108 0, 0, 0, 0, // sampleRate
109 0, 0, 0, 0, // avgBytesPerSec
110 0, 0, // blockAlign
111 0, 0, // sampleSizeInBits
112 0x64, 0x61, 0x74, 0x61, // WaveFileFormat.DATA_MAGIC
113 0, 0, 0, 0, // dataLength
114 };
115
116 static byte[][] data = {wrongAIFFCh, wrongAIFFSSL, wrongAIFFSSH, wrongAUCh,
117 wrongWAVCh, wrongWAVSSB};
118
119 public static void main(final String[] args) throws IOException {
120 for (final byte[] bytes : data) {
121 testAS(bytes);
122 testAFR(bytes);
123 }
124 }
125
126 private static void testAS(final byte[] buffer) throws IOException {
127 // AudioSystem API
128 final InputStream is = new ByteArrayInputStream(buffer);
129 try {
130 AudioSystem.getAudioFileFormat(is);
131 } catch (UnsupportedAudioFileException ignored) {
132 // Expected.
133 return;
134 }
135 throw new RuntimeException("Test Failed");
136 }
137
|
1 /*
2 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
57 0x43, 0x4f, 0x4d, 0x4d, // chunkName
58 0, 0, 0, 100, // chunkLen
59 0, 10, // channels
60 0, 0, 0, 0, //
61 0, 0 // sampleSize
62 , 0, 0, 0, 0};
63 // big sampleSize
64 static byte[] wrongAIFFSSH =
65 {0x46, 0x4f, 0x52, 0x4d, //AiffFileFormat.AIFF_MAGIC
66 0, 0, 0, 0, // length
67 0, 0, 0, 0, // iffType
68 0x43, 0x4f, 0x4d, 0x4d, // chunkName
69 0, 0, 0, 100, // chunkLen
70 0, 10, // channels
71 0, 0, 0, 0, //
72 0, 33 // sampleSize
73 , 0, 0, 0, 0};
74 // empty channels
75 static byte[] wrongAUCh =
76 {0x2e, 0x73, 0x6e, 0x64,//AiffFileFormat.AU_SUN_MAGIC
77 0, 0, 0, 24, // headerSize
78 0, 0, 0, 0, // dataSize
79 0, 0, 0, 1, // encoding_local AuFileFormat.AU_ULAW_8
80 0, 0, 0, 1, // sampleRate
81 0, 0, 0, 0 // channels
82 };
83 // empty sample rate
84 static byte[] wrongAUSR =
85 {0x2e, 0x73, 0x6e, 0x64,//AiffFileFormat.AU_SUN_MAGIC
86 0, 0, 0, 24, // headerSize
87 0, 0, 0, 0, // dataSize
88 0, 0, 0, 1, // encoding_local AuFileFormat.AU_ULAW_8
89 0, 0, 0, 0, // sampleRate
90 0, 0, 0, 1 // channels
91 };
92 // empty header size
93 static byte[] wrongAUEmptyHeader =
94 {0x2e, 0x73, 0x6e, 0x64,//AiffFileFormat.AU_SUN_MAGIC
95 0, 0, 0, 0, // headerSize
96 0, 0, 0, 0, // dataSize
97 0, 0, 0, 1, // encoding_local AuFileFormat.AU_ULAW_8
98 0, 0, 0, 1, // sampleRate
99 0, 0, 0, 1 // channels
100 };
101 // small header size
102 static byte[] wrongAUSmallHeader =
103 {0x2e, 0x73, 0x6e, 0x64,//AiffFileFormat.AU_SUN_MAGIC
104 0, 0, 0, 7, // headerSize
105 0, 0, 0, 0, // dataSize
106 0, 0, 0, 1, // encoding_local AuFileFormat.AU_ULAW_8
107 0, 0, 0, 1, // sampleRate
108 0, 0, 0, 1 // channels
109 };
110 // frame size overflow, when result negative
111 static byte[] wrongAUFrameSizeOverflowNegativeResult =
112 {0x2e, 0x73, 0x6e, 0x64,//AiffFileFormat.AU_SUN_MAGIC
113 0, 0, 0, 24, // headerSize
114 0, 0, 0, 0, // dataSize
115 0, 0, 0, 5, // encoding_local AuFileFormat.AU_LINEAR_32
116 0, 0, 0, 1, // sampleRate
117 0x7F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF // channels
118 };
119 // frame size overflow, when result positive
120 static byte[] wrongAUFrameSizeOverflowPositiveResult =
121 {0x2e, 0x73, 0x6e, 0x64,//AiffFileFormat.AU_SUN_MAGIC
122 0, 0, 0, 24, // headerSize
123 0, 0, 0, 0, // dataSize
124 0, 0, 0, 4, // encoding_local AuFileFormat.AU_LINEAR_24
125 0, 0, 0, 1, // sampleRate
126 0x7F, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF // channels
127 };
128 // empty channels
129 static byte[] wrongWAVCh =
130 {0x52, 0x49, 0x46, 0x46, // WaveFileFormat.RIFF_MAGIC
131 1, 1, 1, 1, // fileLength
132 0x57, 0x41, 0x56, 0x45, // waveMagic
133 0x66, 0x6d, 0x74, 0x20, // FMT_MAGIC
134 3, 0, 0, 0, // length
135 1, 0, // wav_type WAVE_FORMAT_PCM
136 0, 0, // channels
137 0, 0, 0, 0, // sampleRate
138 0, 0, 0, 0, // avgBytesPerSec
139 0, 0, // blockAlign
140 1, 0, // sampleSizeInBits
141 0x64, 0x61, 0x74, 0x61, // WaveFileFormat.DATA_MAGIC
142 0, 0, 0, 0, // dataLength
143 };
144 // empty sampleSizeInBits
145 static byte[] wrongWAVSSB =
146 {0x52, 0x49, 0x46, 0x46, // WaveFileFormat.RIFF_MAGIC
147 1, 1, 1, 1, // fileLength
148 0x57, 0x41, 0x56, 0x45, // waveMagic
149 0x66, 0x6d, 0x74, 0x20, // FMT_MAGIC
150 3, 0, 0, 0, // length
151 1, 0, // wav_type WAVE_FORMAT_PCM
152 1, 0, // channels
153 0, 0, 0, 0, // sampleRate
154 0, 0, 0, 0, // avgBytesPerSec
155 0, 0, // blockAlign
156 0, 0, // sampleSizeInBits
157 0x64, 0x61, 0x74, 0x61, // WaveFileFormat.DATA_MAGIC
158 0, 0, 0, 0, // dataLength
159 };
160
161 static byte[][] data = {
162 wrongAIFFCh, wrongAIFFSSL, wrongAIFFSSH, wrongAUCh, wrongAUSR,
163 wrongAUEmptyHeader, wrongAUSmallHeader,
164 wrongAUFrameSizeOverflowNegativeResult,
165 wrongAUFrameSizeOverflowPositiveResult, wrongWAVCh, wrongWAVSSB
166 };
167
168 public static void main(final String[] args) throws IOException {
169 for (final byte[] bytes : data) {
170 testAS(bytes);
171 testAFR(bytes);
172 }
173 }
174
175 private static void testAS(final byte[] buffer) throws IOException {
176 // AudioSystem API
177 final InputStream is = new ByteArrayInputStream(buffer);
178 try {
179 AudioSystem.getAudioFileFormat(is);
180 } catch (UnsupportedAudioFileException ignored) {
181 // Expected.
182 return;
183 }
184 throw new RuntimeException("Test Failed");
185 }
186
|