vlc/vlc-2.0 | branch: master | Rafaël Carré <[email protected]> | Tue Mar 6 17:52:59 2012 -0500| [a7b544a41e5daa04dd8844de55eb24842fe95964] | committer: Jean-Baptiste Kempf
HLS: fix IV parsing Don't assume IV has 32 digits (leading zeroes are not mentioned in the spec) (cherry picked from commit a75552b81ca070dced73f42873c3c52c4d75f4a7) Signed-off-by: Jean-Baptiste Kempf <[email protected]> > http://git.videolan.org/gitweb.cgi/vlc/vlc-2.0.git/?a=commit;h=a7b544a41e5daa04dd8844de55eb24842fe95964 --- modules/stream_filter/httplive.c | 54 +++++++++++++++++++++---------------- 1 files changed, 31 insertions(+), 23 deletions(-) diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c index 6e0926c..ffebc0f 100644 --- a/modules/stream_filter/httplive.c +++ b/modules/stream_filter/httplive.c @@ -502,33 +502,38 @@ static char *parse_Attributes(const char *line, const char *attr) return NULL; } -static int hex2int(char c) +static int string_to_IV(char *string_hexa, uint8_t iv[AES_BLOCK_SIZE]) { - if (c >= '0' && c <= '9') - return c - '0'; - if (c >= 'A' && c <= 'F') - return c - 'A' + 10; - if (c >= 'a' && c <= 'f') - return c - 'a' + 10; - return -1; -} - -static int string_to_IV(const char *string_hexa, uint8_t iv[AES_BLOCK_SIZE]) -{ - const char *p = string_hexa; - uint8_t *d = iv; - unsigned int c; - - if (*p++ != '0') + unsigned long long iv_hi, iv_lo; + char *end = NULL; + if (*string_hexa++ != '0') return VLC_EGENERIC; - if (*p++ != 'x') + if (*string_hexa != 'x' && *string_hexa != 'X') return VLC_EGENERIC; - while (*p && *(p+1)) - { - c = hex2int(*p++) << 4; - c |= hex2int(*p++); - *d++ = c; + string_hexa++; + + size_t len = strlen(string_hexa); + if (len <= 16) { + iv_hi = 0; + iv_lo = strtoull(string_hexa, &end, 16); + if (end) + return VLC_EGENERIC; + } else { + iv_lo = strtoull(&string_hexa[len-16], NULL, 16); + if (end) + return VLC_EGENERIC; + string_hexa[len-16] = '\0'; + iv_hi = strtoull(string_hexa, NULL, 16); + if (end) + return VLC_EGENERIC; + } + + for (int i = 8; i ; --i) { + iv[ i] = iv_hi & 0xff; + iv[8+i] = iv_lo & 0xff; + iv_hi >>= 8; + iv_lo >>= 8; } return VLC_SUCCESS; @@ -790,7 +795,10 @@ static int parse_Key(stream_t *s, hls_stream_t *hls, char *p_read) */ if (string_to_IV(iv, hls->psz_AES_IV) == VLC_EGENERIC) + { + msg_Err(s, "IV invalid"); err = VLC_EGENERIC; + } else hls->b_iv_loaded = true; free(value); _______________________________________________ vlc-commits mailing list [email protected] http://mailman.videolan.org/listinfo/vlc-commits
