]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/flvdec.c
avformat/rtsp: Use avio_closep() to avoid leaving stale pointers in memory
[ffmpeg] / libavformat / flvdec.c
index 54f2f56dba2bf644617ef986f776a6d4450f0453..572268f2ad1b877796c6547d037b903f8e72395d 100644 (file)
@@ -390,7 +390,7 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream,
     FLVContext *flv = s->priv_data;
     AVIOContext *ioc;
     AMFDataType amf_type;
-    char str_val[256];
+    char str_val[1024];
     double num_val;
 
     num_val  = 0;
@@ -405,8 +405,10 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream,
         num_val = avio_r8(ioc);
         break;
     case AMF_DATA_TYPE_STRING:
-        if (amf_get_string(ioc, str_val, sizeof(str_val)) < 0)
+        if (amf_get_string(ioc, str_val, sizeof(str_val)) < 0) {
+            av_log(s, AV_LOG_ERROR, "AMF_DATA_TYPE_STRING parsing failed\n");
             return -1;
+        }
         break;
     case AMF_DATA_TYPE_OBJECT:
         if ((vstream || astream) && key &&
@@ -421,8 +423,10 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream,
             if (amf_parse_object(s, astream, vstream, str_val, max_pos,
                                  depth + 1) < 0)
                 return -1;     // if we couldn't skip, bomb out.
-        if (avio_r8(ioc) != AMF_END_OF_OBJECT)
+        if (avio_r8(ioc) != AMF_END_OF_OBJECT) {
+            av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_OBJECT\n");
             return -1;
+        }
         break;
     case AMF_DATA_TYPE_NULL:
     case AMF_DATA_TYPE_UNDEFINED:
@@ -437,8 +441,10 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream,
             if (amf_parse_object(s, astream, vstream, str_val, max_pos,
                                  depth + 1) < 0)
                 return -1;
-        if (avio_r8(ioc) != AMF_END_OF_OBJECT)
+        if (avio_r8(ioc) != AMF_END_OF_OBJECT) {
+            av_log(s, AV_LOG_ERROR, "Missing AMF_END_OF_OBJECT in AMF_DATA_TYPE_MIXEDARRAY\n");
             return -1;
+        }
         break;
     case AMF_DATA_TYPE_ARRAY:
     {
@@ -455,6 +461,7 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream,
         avio_skip(ioc, 8 + 2);  // timestamp (double) and UTC offset (int16)
         break;
     default:                    // unsupported type, we couldn't skip
+        av_log(s, AV_LOG_ERROR, "unsupported amf type %d\n", amf_type);
         return -1;
     }
 
@@ -538,6 +545,9 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream,
     return 0;
 }
 
+#define TYPE_ONTEXTDATA 1
+#define TYPE_UNKNOWN 2
+
 static int flv_read_metabody(AVFormatContext *s, int64_t next_pos)
 {
     AMFDataType type;
@@ -558,13 +568,13 @@ static int flv_read_metabody(AVFormatContext *s, int64_t next_pos)
     type = avio_r8(ioc);
     if (type != AMF_DATA_TYPE_STRING ||
         amf_get_string(ioc, buffer, sizeof(buffer)) < 0)
-        return -1;
+        return TYPE_UNKNOWN;
 
     if (!strcmp(buffer, "onTextData"))
-        return 1;
+        return TYPE_ONTEXTDATA;
 
     if (strcmp(buffer, "onMetaData") && strcmp(buffer, "onCuePoint"))
-        return -1;
+        return TYPE_UNKNOWN;
 
     // find the streams now so that amf_parse_object doesn't need to do
     // the lookup every time it is called.
@@ -822,7 +832,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
             stream_type=FLV_STREAM_TYPE_DATA;
             if (size > 13 + 1 + 4 && dts == 0) { // Header-type metadata stuff
                 meta_pos = avio_tell(s->pb);
-                if (flv_read_metabody(s, next) == 0) {
+                if (flv_read_metabody(s, next) <= 0) {
                     goto skip;
                 }
                 avio_seek(s->pb, meta_pos, SEEK_SET);