diff options
-rw-r--r-- | apps/codecs/libwavpack/metadata.c | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/apps/codecs/libwavpack/metadata.c b/apps/codecs/libwavpack/metadata.c index b7d1e950bf..c7f2d61841 100644 --- a/apps/codecs/libwavpack/metadata.c +++ b/apps/codecs/libwavpack/metadata.c | |||
@@ -16,6 +16,7 @@ | |||
16 | 16 | ||
17 | int read_metadata_buff (WavpackContext *wpc, WavpackMetadata *wpmd) | 17 | int read_metadata_buff (WavpackContext *wpc, WavpackMetadata *wpmd) |
18 | { | 18 | { |
19 | uint32_t bytes_to_read; | ||
19 | uchar tchar; | 20 | uchar tchar; |
20 | 21 | ||
21 | if (!wpc->infile (&wpmd->id, 1) || !wpc->infile (&tchar, 1)) | 22 | if (!wpc->infile (&wpmd->id, 1) || !wpc->infile (&tchar, 1)) |
@@ -42,18 +43,29 @@ int read_metadata_buff (WavpackContext *wpc, WavpackMetadata *wpmd) | |||
42 | wpmd->byte_length--; | 43 | wpmd->byte_length--; |
43 | } | 44 | } |
44 | 45 | ||
45 | if (wpmd->byte_length && wpmd->byte_length <= (int32_t)sizeof (wpc->read_buffer)) { | 46 | if (!wpmd->byte_length || wpmd->id == ID_WV_BITSTREAM) { |
46 | uint32_t bytes_to_read = wpmd->byte_length + (wpmd->byte_length & 1); | 47 | wpmd->data = NULL; |
48 | return TRUE; | ||
49 | } | ||
47 | 50 | ||
48 | if (wpc->infile (wpc->read_buffer, bytes_to_read) != (int32_t) bytes_to_read) { | 51 | bytes_to_read = wpmd->byte_length + (wpmd->byte_length & 1); |
49 | wpmd->data = NULL; | ||
50 | return FALSE; | ||
51 | } | ||
52 | 52 | ||
53 | wpmd->data = wpc->read_buffer; | 53 | if (bytes_to_read > sizeof (wpc->read_buffer)) { |
54 | wpmd->data = NULL; | ||
55 | |||
56 | while (bytes_to_read > sizeof (wpc->read_buffer)) | ||
57 | if (wpc->infile (wpc->read_buffer, sizeof (wpc->read_buffer)) == sizeof (wpc->read_buffer)) | ||
58 | bytes_to_read -= sizeof (wpc->read_buffer); | ||
59 | else | ||
60 | return FALSE; | ||
54 | } | 61 | } |
55 | else | 62 | else |
63 | wpmd->data = wpc->read_buffer; | ||
64 | |||
65 | if (bytes_to_read && wpc->infile (wpc->read_buffer, bytes_to_read) != (int32_t) bytes_to_read) { | ||
56 | wpmd->data = NULL; | 66 | wpmd->data = NULL; |
67 | return FALSE; | ||
68 | } | ||
57 | 69 | ||
58 | return TRUE; | 70 | return TRUE; |
59 | } | 71 | } |