Re: [FFmpeg-devel] [PATCH 3/3] libavformat/dashdec: Fix for ticket 6856 (filename limited to 1024)

2018-01-20 Thread Steven Liu
2018-01-17 11:02 GMT+08:00 Colin NG :
> ---
>  libavformat/dashdec.c | 88 
> +--
>  1 file changed, 58 insertions(+), 30 deletions(-)
>
> diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
> index 1d520d4..9d5986d 100644
> --- a/libavformat/dashdec.c
> +++ b/libavformat/dashdec.c
> @@ -147,6 +147,7 @@ typedef struct DASHContext {
>  char *headers;   ///< holds HTTP headers set as an 
> AVOption to the HTTP protocol context
>  char *allowed_extensions;
>  AVDictionary *avio_opts;
> +int max_url_size;
>  } DASHContext;
>
>  static int ishttp(char *url) {
> @@ -154,6 +155,10 @@ static int ishttp(char *url) {
>  return av_strstart(proto_name, "http", NULL);
>  }
>
> +static int aligned(int val) {
> +return ((val + 0x3F) >> 6) << 6;
> +}
> +
>  static uint64_t get_current_time_in_sec(void)
>  {
>  return  av_gettime() / 100;
> @@ -452,6 +457,7 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, 
> const char *url,
>
>  static char *get_content_url(xmlNodePtr *baseurl_nodes,
>   int n_baseurl_nodes,
> + int max_url_size,
>   char *rep_id_val,
>   char *rep_bandwidth_val,
>   char *val)
> @@ -459,43 +465,47 @@ static char *get_content_url(xmlNodePtr *baseurl_nodes,
>  int i;
>  char *text;
>  char *url = NULL;
> -char tmp_str[MAX_URL_SIZE];
> -char tmp_str_2[MAX_URL_SIZE];
> -
> -memset(tmp_str, 0, sizeof(tmp_str));
> +char *tmp_str = av_mallocz(max_url_size);
> +char *tmp_str_2 = av_mallocz(max_url_size);
>
> +if (!tmp_str || !tmp_str_2) {
> +return NULL;
> +}
>  for (i = 0; i < n_baseurl_nodes; ++i) {
>  if (baseurl_nodes[i] &&
>  baseurl_nodes[i]->children &&
>  baseurl_nodes[i]->children->type == XML_TEXT_NODE) {
>  text = xmlNodeGetContent(baseurl_nodes[i]->children);
>  if (text) {
> -memset(tmp_str, 0, sizeof(tmp_str));
> -memset(tmp_str_2, 0, sizeof(tmp_str_2));
> -ff_make_absolute_url(tmp_str_2, MAX_URL_SIZE, tmp_str, text);
> -av_strlcpy(tmp_str, tmp_str_2, sizeof(tmp_str));
> +memset(tmp_str, 0, max_url_size);
> +memset(tmp_str_2, 0, max_url_size);
> +ff_make_absolute_url(tmp_str_2, max_url_size, tmp_str, text);
> +av_strlcpy(tmp_str, tmp_str_2, max_url_size);
>  xmlFree(text);
>  }
>  }
>  }
>
>  if (val)
> -av_strlcat(tmp_str, (const char*)val, sizeof(tmp_str));
> +av_strlcat(tmp_str, (const char*)val, max_url_size);
>
>  if (rep_id_val) {
>  url = av_strireplace(tmp_str, "$RepresentationID$", (const 
> char*)rep_id_val);
>  if (!url) {
> -return NULL;
> +goto end;
>  }
> -av_strlcpy(tmp_str, url, sizeof(tmp_str));
> +av_strlcpy(tmp_str, url, max_url_size);
>  av_free(url);
>  }
>  if (rep_bandwidth_val && tmp_str[0] != '\0') {
>  url = av_strireplace(tmp_str, "$Bandwidth$", (const 
> char*)rep_bandwidth_val);
>  if (!url) {
> -return NULL;
> +goto end;
>  }
>  }
> +end:
> +av_free(tmp_str);
> +av_free(tmp_str_2);
>  return url;
>  }
>
> @@ -580,9 +590,11 @@ static int parse_manifest_segmenturlnode(AVFormatContext 
> *s, struct representati
>   char *rep_id_val,
>   char *rep_bandwidth_val)
>  {
> +DASHContext *c = s->priv_data;
>  char *initialization_val = NULL;
>  char *media_val = NULL;
>  char *range_val = NULL;
> +int max_url_size = c ? c->max_url_size: MAX_URL_SIZE;
>
>  if (!av_strcasecmp(fragmenturl_node->name, (const char 
> *)"Initialization")) {
>  initialization_val = xmlGetProp(fragmenturl_node, "sourceURL");
> @@ -595,6 +607,7 @@ static int parse_manifest_segmenturlnode(AVFormatContext 
> *s, struct representati
>  return AVERROR(ENOMEM);
>  }
>  rep->init_section->url = get_content_url(baseurl_nodes, 4,
> + max_url_size,
>   rep_id_val,
>   rep_bandwidth_val,
>   initialization_val);
> @@ -619,6 +632,7 @@ static int parse_manifest_segmenturlnode(AVFormatContext 
> *s, struct representati
>  return AVERROR(ENOMEM);
>  }
>  seg->url = get_content_url(baseurl_nodes, 4,
> +   max_url_size,
> rep_id_val,
>

[FFmpeg-devel] [PATCH 3/3] libavformat/dashdec: Fix for ticket 6856 (filename limited to 1024)

2018-01-16 Thread Colin NG
---
 libavformat/dashdec.c | 88 +--
 1 file changed, 58 insertions(+), 30 deletions(-)

diff --git a/libavformat/dashdec.c b/libavformat/dashdec.c
index 1d520d4..9d5986d 100644
--- a/libavformat/dashdec.c
+++ b/libavformat/dashdec.c
@@ -147,6 +147,7 @@ typedef struct DASHContext {
 char *headers;   ///< holds HTTP headers set as an 
AVOption to the HTTP protocol context
 char *allowed_extensions;
 AVDictionary *avio_opts;
+int max_url_size;
 } DASHContext;
 
 static int ishttp(char *url) {
@@ -154,6 +155,10 @@ static int ishttp(char *url) {
 return av_strstart(proto_name, "http", NULL);
 }
 
+static int aligned(int val) {
+return ((val + 0x3F) >> 6) << 6;
+}
+
 static uint64_t get_current_time_in_sec(void)
 {
 return  av_gettime() / 100;
@@ -452,6 +457,7 @@ static int open_url(AVFormatContext *s, AVIOContext **pb, 
const char *url,
 
 static char *get_content_url(xmlNodePtr *baseurl_nodes,
  int n_baseurl_nodes,
+ int max_url_size,
  char *rep_id_val,
  char *rep_bandwidth_val,
  char *val)
@@ -459,43 +465,47 @@ static char *get_content_url(xmlNodePtr *baseurl_nodes,
 int i;
 char *text;
 char *url = NULL;
-char tmp_str[MAX_URL_SIZE];
-char tmp_str_2[MAX_URL_SIZE];
-
-memset(tmp_str, 0, sizeof(tmp_str));
+char *tmp_str = av_mallocz(max_url_size);
+char *tmp_str_2 = av_mallocz(max_url_size);
 
+if (!tmp_str || !tmp_str_2) {
+return NULL;
+}
 for (i = 0; i < n_baseurl_nodes; ++i) {
 if (baseurl_nodes[i] &&
 baseurl_nodes[i]->children &&
 baseurl_nodes[i]->children->type == XML_TEXT_NODE) {
 text = xmlNodeGetContent(baseurl_nodes[i]->children);
 if (text) {
-memset(tmp_str, 0, sizeof(tmp_str));
-memset(tmp_str_2, 0, sizeof(tmp_str_2));
-ff_make_absolute_url(tmp_str_2, MAX_URL_SIZE, tmp_str, text);
-av_strlcpy(tmp_str, tmp_str_2, sizeof(tmp_str));
+memset(tmp_str, 0, max_url_size);
+memset(tmp_str_2, 0, max_url_size);
+ff_make_absolute_url(tmp_str_2, max_url_size, tmp_str, text);
+av_strlcpy(tmp_str, tmp_str_2, max_url_size);
 xmlFree(text);
 }
 }
 }
 
 if (val)
-av_strlcat(tmp_str, (const char*)val, sizeof(tmp_str));
+av_strlcat(tmp_str, (const char*)val, max_url_size);
 
 if (rep_id_val) {
 url = av_strireplace(tmp_str, "$RepresentationID$", (const 
char*)rep_id_val);
 if (!url) {
-return NULL;
+goto end;
 }
-av_strlcpy(tmp_str, url, sizeof(tmp_str));
+av_strlcpy(tmp_str, url, max_url_size);
 av_free(url);
 }
 if (rep_bandwidth_val && tmp_str[0] != '\0') {
 url = av_strireplace(tmp_str, "$Bandwidth$", (const 
char*)rep_bandwidth_val);
 if (!url) {
-return NULL;
+goto end;
 }
 }
+end:
+av_free(tmp_str);
+av_free(tmp_str_2);
 return url;
 }
 
@@ -580,9 +590,11 @@ static int parse_manifest_segmenturlnode(AVFormatContext 
*s, struct representati
  char *rep_id_val,
  char *rep_bandwidth_val)
 {
+DASHContext *c = s->priv_data;
 char *initialization_val = NULL;
 char *media_val = NULL;
 char *range_val = NULL;
+int max_url_size = c ? c->max_url_size: MAX_URL_SIZE;
 
 if (!av_strcasecmp(fragmenturl_node->name, (const char 
*)"Initialization")) {
 initialization_val = xmlGetProp(fragmenturl_node, "sourceURL");
@@ -595,6 +607,7 @@ static int parse_manifest_segmenturlnode(AVFormatContext 
*s, struct representati
 return AVERROR(ENOMEM);
 }
 rep->init_section->url = get_content_url(baseurl_nodes, 4,
+ max_url_size,
  rep_id_val,
  rep_bandwidth_val,
  initialization_val);
@@ -619,6 +632,7 @@ static int parse_manifest_segmenturlnode(AVFormatContext 
*s, struct representati
 return AVERROR(ENOMEM);
 }
 seg->url = get_content_url(baseurl_nodes, 4,
+   max_url_size,
rep_id_val,
rep_bandwidth_val,
media_val);
@@ -673,7 +687,7 @@ static int parse_manifest_segmenttimeline(AVFormatContext 
*s, struct representat
 return 0;
 }
 
-static int resolve_content_path(AVFormatContext *s, const char *url,