forked from len0rd/rockbox
make WavPack library check the extent of the block that it is parsing so that it cannot run into the next block; also enhance the metadata code to handle the case of files with non-audio blocks at the beginning (which can happen if the source WAV file has lots of RIFF data)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28736 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
271441eb9d
commit
516693fcc9
4 changed files with 81 additions and 49 deletions
|
@ -19,15 +19,16 @@ int read_metadata_buff (WavpackContext *wpc, WavpackMetadata *wpmd)
|
|||
uint32_t bytes_to_read;
|
||||
uchar tchar;
|
||||
|
||||
if (!wpc->infile (&wpmd->id, 1) || !wpc->infile (&tchar, 1))
|
||||
if (wpc->stream.block_bytes_left < 2 || !wpc->infile (&wpmd->id, 1) || !wpc->infile (&tchar, 1))
|
||||
return FALSE;
|
||||
|
||||
wpmd->byte_length = tchar << 1;
|
||||
wpc->stream.block_bytes_left -= 2;
|
||||
|
||||
if (wpmd->id & ID_LARGE) {
|
||||
wpmd->id &= ~ID_LARGE;
|
||||
|
||||
if (!wpc->infile (&tchar, 1))
|
||||
if (wpc->stream.block_bytes_left < 2 || !wpc->infile (&tchar, 1))
|
||||
return FALSE;
|
||||
|
||||
wpmd->byte_length += (int32_t) tchar << 9;
|
||||
|
@ -36,8 +37,12 @@ int read_metadata_buff (WavpackContext *wpc, WavpackMetadata *wpmd)
|
|||
return FALSE;
|
||||
|
||||
wpmd->byte_length += (int32_t) tchar << 17;
|
||||
wpc->stream.block_bytes_left -= 2;
|
||||
}
|
||||
|
||||
if ((wpc->stream.block_bytes_left -= wpmd->byte_length) < 0)
|
||||
return FALSE;
|
||||
|
||||
if (wpmd->id & ID_ODD_SIZE) {
|
||||
wpmd->id &= ~ID_ODD_SIZE;
|
||||
wpmd->byte_length--;
|
||||
|
|
|
@ -205,6 +205,7 @@ typedef struct {
|
|||
|
||||
int num_terms, mute_error;
|
||||
uint32_t sample_index, crc;
|
||||
int32_t block_bytes_left;
|
||||
|
||||
uchar int32_sent_bits, int32_zeros, int32_ones, int32_dups;
|
||||
uchar float_flags, float_shift, float_max_exp, float_norm_exp;
|
||||
|
|
|
@ -69,6 +69,8 @@ WavpackContext *WavpackOpenFileInput (read_stream infile, char *error)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
wps->block_bytes_left = wps->wphdr.ckSize - 24;
|
||||
|
||||
if ((wps->wphdr.flags & UNKNOWN_FLAGS) || wps->wphdr.version < MIN_STREAM_VERS ||
|
||||
wps->wphdr.version > MAX_STREAM_VERS) {
|
||||
strcpy_loc (error, "invalid WavPack file!");
|
||||
|
@ -171,6 +173,8 @@ uint32_t WavpackUnpackSamples (WavpackContext *wpc, int32_t *buffer, uint32_t sa
|
|||
if (bcount == (uint32_t) -1)
|
||||
break;
|
||||
|
||||
wps->block_bytes_left = wps->wphdr.ckSize - 24;
|
||||
|
||||
if (wps->wphdr.version < MIN_STREAM_VERS || wps->wphdr.version > MAX_STREAM_VERS) {
|
||||
strcpy_loc (wpc->error_message, "invalid WavPack file!");
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue