From 03900fe178fa1dc6b371424c8a96f91be52877e2 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Thu, 8 Oct 2009 01:09:52 +0200 Subject: [PATCH] More misc wma fixes. --- afh.h | 2 +- wma_common.c | 20 ++++++++++++-------- wmadec_filter.c | 7 +++---- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/afh.h b/afh.h index 72987b31..50c46eee 100644 --- a/afh.h +++ b/afh.h @@ -19,7 +19,7 @@ #define AAC_AUDIO_FORMAT "" #endif -#define SUPPORTED_AUDIO_FORMATS "mp3" OV_AUDIO_FORMAT AAC_AUDIO_FORMAT +#define SUPPORTED_AUDIO_FORMATS "mp3 " OV_AUDIO_FORMAT AAC_AUDIO_FORMAT " wma " /** \endcond */ diff --git a/wma_common.c b/wma_common.c index cab89d3e..5ea92c73 100644 --- a/wma_common.c +++ b/wma_common.c @@ -56,23 +56,27 @@ static int read_header_len(char *buf, int len) { uint16_t header_len; + if (len < 18) + return 0; header_len = read_u16(buf + 16) + 46; - if (header_len > len) - return -E_WMA_BAD_ASF_HEADER; PARA_DEBUG_LOG("header_len: %d\n", header_len); return header_len; } +/** + * \return Negative on errors, zero if more data is needed in order to read the + * full header. Positive header length on success. + */ int read_asf_header(char *buf, int loaded, struct asf_header_info *ahi) { int ret; char *start; - ret = read_header_len(buf, loaded); - if (ret < 0) - return ret; - ahi->header_len = ret; - + ahi->header_len = read_header_len(buf, loaded); + if (ahi->header_len == 0) /* too short to read header len */ + return 0; + if (ahi->header_len > loaded) /* too short to read header */ + return 0; ret = find_audio_stream_info(buf, ahi->header_len); if (ret < 0) return ret; @@ -94,7 +98,7 @@ int read_asf_header(char *buf, int loaded, struct asf_header_info *ahi) ahi->flags2 = read_u16(start + 60); PARA_INFO_LOG("read_asf_header: flags1: %d, flag2: %d\n", ahi->flags1, ahi->flags2); - return 42; + return 1; } const uint8_t log2_tab[256] = { diff --git a/wmadec_filter.c b/wmadec_filter.c index a548d048..4d384e1d 100644 --- a/wmadec_filter.c +++ b/wmadec_filter.c @@ -446,14 +446,13 @@ static int wma_decode_init(char *initial_buf, int len, struct private_wmadec_dat struct private_wmadec_data *s; int ret, i; - if (len < 18) - return 0; - PARA_NOTICE_LOG("initial buf: %d bytes\n", len); s = para_calloc(sizeof(*s)); ret = read_asf_header(initial_buf, len, &s->ahi); - if (ret < 0) + if (ret <= 0) { + free(s); return ret; + } s->use_exp_vlc = s->ahi.flags2 & 0x0001; s->use_bit_reservoir = s->ahi.flags2 & 0x0002; -- 2.39.5