OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 { | 178 { |
179 uint32_t W_lower, W_upper; | 179 uint32_t W_lower, W_upper; |
180 uint32_t W_tmp; | 180 uint32_t W_tmp; |
181 uint32_t W_upper_LSB, W_upper_MSB; | 181 uint32_t W_upper_LSB, W_upper_MSB; |
182 uint32_t streamval; | 182 uint32_t streamval; |
183 const uint8_t *stream_ptr; | 183 const uint8_t *stream_ptr; |
184 uint32_t cdf_tmp; | 184 uint32_t cdf_tmp; |
185 int16_t candQ7; | 185 int16_t candQ7; |
186 int k; | 186 int k; |
187 | 187 |
| 188 // Position just past the end of the stream. STREAM_SIZE_MAX_60 instead of |
| 189 // STREAM_SIZE_MAX (which is the size of the allocated buffer) because that's |
| 190 // the limit to how much data is filled in. |
| 191 const uint8_t* const stream_end = streamdata->stream + STREAM_SIZE_MAX_60; |
| 192 |
188 stream_ptr = streamdata->stream + streamdata->stream_index; | 193 stream_ptr = streamdata->stream + streamdata->stream_index; |
189 W_upper = streamdata->W_upper; | 194 W_upper = streamdata->W_upper; |
190 if (streamdata->stream_index == 0) /* first time decoder is called for this
stream */ | 195 if (streamdata->stream_index == 0) /* first time decoder is called for this
stream */ |
191 { | 196 { |
192 /* read first word from bytestream */ | 197 /* read first word from bytestream */ |
| 198 if (stream_ptr + 3 >= stream_end) |
| 199 return -1; // Would read out of bounds. Malformed input? |
193 streamval = *stream_ptr << 24; | 200 streamval = *stream_ptr << 24; |
194 streamval |= *++stream_ptr << 16; | 201 streamval |= *++stream_ptr << 16; |
195 streamval |= *++stream_ptr << 8; | 202 streamval |= *++stream_ptr << 8; |
196 streamval |= *++stream_ptr; | 203 streamval |= *++stream_ptr; |
197 } else { | 204 } else { |
198 streamval = streamdata->streamval; | 205 streamval = streamdata->streamval; |
199 } | 206 } |
200 | 207 |
201 | 208 |
202 for (k = 0; k < N; k++) | 209 for (k = 0; k < N; k++) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 /* shift interval to start at zero */ | 277 /* shift interval to start at zero */ |
271 W_upper -= ++W_lower; | 278 W_upper -= ++W_lower; |
272 | 279 |
273 /* add integer to bitstream */ | 280 /* add integer to bitstream */ |
274 streamval -= W_lower; | 281 streamval -= W_lower; |
275 | 282 |
276 /* renormalize interval and update streamval */ | 283 /* renormalize interval and update streamval */ |
277 while ( !(W_upper & 0xFF000000) ) /* W_upper < 2^24 */ | 284 while ( !(W_upper & 0xFF000000) ) /* W_upper < 2^24 */ |
278 { | 285 { |
279 /* read next byte from stream */ | 286 /* read next byte from stream */ |
| 287 if (stream_ptr + 1 >= stream_end) |
| 288 return -1; // Would read out of bounds. Malformed input? |
280 streamval = (streamval << 8) | *++stream_ptr; | 289 streamval = (streamval << 8) | *++stream_ptr; |
281 W_upper <<= 8; | 290 W_upper <<= 8; |
282 } | 291 } |
283 } | 292 } |
284 | 293 |
285 streamdata->stream_index = (int)(stream_ptr - streamdata->stream); | 294 streamdata->stream_index = (int)(stream_ptr - streamdata->stream); |
286 streamdata->W_upper = W_upper; | 295 streamdata->W_upper = W_upper; |
287 streamdata->streamval = streamval; | 296 streamdata->streamval = streamval; |
288 | 297 |
289 /* find number of bytes in original stream (determined by current interval wid
th) */ | 298 /* find number of bytes in original stream (determined by current interval wid
th) */ |
290 if ( W_upper > 0x01FFFFFF ) | 299 if ( W_upper > 0x01FFFFFF ) |
291 return streamdata->stream_index - 2; | 300 return streamdata->stream_index - 2; |
292 else | 301 else |
293 return streamdata->stream_index - 1; | 302 return streamdata->stream_index - 1; |
294 } | 303 } |
OLD | NEW |