From 01d8aad1e847732808f2b70085b664088ab1c517 Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 6 Jul 2017 16:25:18 +0200 Subject: [PATCH] demux_lavf: potentially fix --demuxer-lavf-cryptokey The first time I saw a user try to use this option, and apparently it didn't work. I'm not exactly sure why, but the code seems to be broken anyway. Apart from not doing any error checking (neither mallocs nor warning the user against invalid input), it forgets to add a 0 terminator. Use the corresponding AVOption instead, which probably works. See #4579. --- demux/demux_lavf.c | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c index da0dbd46aa..f5f6a1af63 100644 --- a/demux/demux_lavf.c +++ b/demux/demux_lavf.c @@ -490,25 +490,6 @@ static int lavf_check_file(demuxer_t *demuxer, enum demux_check check) return 0; } -static uint8_t char2int(char c) -{ - 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 0; -} - -static void parse_cryptokey(AVFormatContext *avfc, const char *str) -{ - int len = strlen(str) / 2; - uint8_t *key = av_mallocz(len); - int i; - avfc->keylen = len; - avfc->key = key; - for (i = 0; i < len; i++, str += 2) - *key++ = (char2int(str[0]) << 4) | char2int(str[1]); -} - static char *replace_idx_ext(void *ta_ctx, bstr f) { if (f.len < 4 || f.start[f.len - 4] != '.') @@ -811,8 +792,6 @@ static int demux_open_lavf(demuxer_t *demuxer, enum demux_check check) if (!avfc) return -1; - if (lavfdopts->cryptokey) - parse_cryptokey(avfc, lavfdopts->cryptokey); if (lavfdopts->genptsmode) avfc->flags |= AVFMT_FLAG_GENPTS; if (index_mode != 1) @@ -882,6 +861,9 @@ static int demux_open_lavf(demuxer_t *demuxer, enum demux_check check) if (priv->format_hack.fix_editlists) av_dict_set(&dopts, "advanced_editlist", "0", 0); + if (lavfdopts->cryptokey && lavfdopts->cryptokey[0]) + av_dict_set(&dopts, "decryption_key", lavfdopts->cryptokey, 0); + avfc->interrupt_callback = (AVIOInterruptCB){ .callback = interrupt_cb, .opaque = demuxer,