]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/crypto.c
nut: fix int32 overflow
[ffmpeg] / libavformat / crypto.c
index 789a4d1e7638b0ad1c7ba4a7d3def146893e549a..5d518beb01191508ed91e2841d7bde652a0f3541 100644 (file)
@@ -45,9 +45,10 @@ typedef struct {
 } CryptoContext;
 
 #define OFFSET(x) offsetof(CryptoContext, x)
+#define D AV_OPT_FLAG_DECODING_PARAM
 static const AVOption options[] = {
-    {"key", "AES decryption key", OFFSET(key), FF_OPT_TYPE_BINARY },
-    {"iv",  "AES decryption initialization vector", OFFSET(iv),  FF_OPT_TYPE_BINARY },
+    {"key", "AES decryption key", OFFSET(key), AV_OPT_TYPE_BINARY, .flags = D },
+    {"iv",  "AES decryption initialization vector", OFFSET(iv), AV_OPT_TYPE_BINARY, .flags = D },
     { NULL }
 };
 
@@ -58,10 +59,10 @@ static const AVClass crypto_class = {
     .version        = LIBAVUTIL_VERSION_INT,
 };
 
-static int crypto_open(URLContext *h, const char *uri, int flags)
+static int crypto_open2(URLContext *h, const char *uri, int flags, AVDictionary **options)
 {
     const char *nested_url;
-    int ret;
+    int ret = 0;
     CryptoContext *c = h->priv_data;
 
     if (!av_strstart(uri, "crypto+", &nested_url) &&
@@ -81,11 +82,12 @@ static int crypto_open(URLContext *h, const char *uri, int flags)
         ret = AVERROR(ENOSYS);
         goto err;
     }
-    if ((ret = ffurl_open(&c->hd, nested_url, AVIO_FLAG_READ)) < 0) {
+    if ((ret = ffurl_open(&c->hd, nested_url, AVIO_FLAG_READ,
+                          &h->interrupt_callback, options)) < 0) {
         av_log(h, AV_LOG_ERROR, "Unable to open input\n");
         goto err;
     }
-    c->aes = av_mallocz(av_aes_size);
+    c->aes = av_aes_alloc();
     if (!c->aes) {
         ret = AVERROR(ENOMEM);
         goto err;
@@ -95,10 +97,7 @@ static int crypto_open(URLContext *h, const char *uri, int flags)
 
     h->is_streamed = 1;
 
-    return 0;
 err:
-    av_free(c->key);
-    av_free(c->iv);
     return ret;
 }
 
@@ -157,14 +156,12 @@ static int crypto_close(URLContext *h)
     if (c->hd)
         ffurl_close(c->hd);
     av_freep(&c->aes);
-    av_freep(&c->key);
-    av_freep(&c->iv);
     return 0;
 }
 
 URLProtocol ff_crypto_protocol = {
     .name            = "crypto",
-    .url_open        = crypto_open,
+    .url_open2       = crypto_open2,
     .url_read        = crypto_read,
     .url_close       = crypto_close,
     .priv_data_size  = sizeof(CryptoContext),