]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/vividas.c
avformat/matroskaenc: Write CRC-32 in non-seekable mode
[ffmpeg] / libavformat / vividas.c
index 31f8c47ca478d5aee6b4eab0caffd4889b6953f6..c99cbd1f6ebaa172bf113784d5cde7d32d0a0bcc 100644 (file)
@@ -70,7 +70,7 @@ typedef struct VividasDemuxContext {
     VIV_AudioSubpacket audio_subpackets[MAX_AUDIO_SUBPACKETS];
 } VividasDemuxContext;
 
-static int viv_probe(AVProbeData *p)
+static int viv_probe(const AVProbeData *p)
 {
     if (memcmp(p->buf, "vividas03", 9))
         return 0;
@@ -121,19 +121,20 @@ static unsigned recover_key(unsigned char sample[4], unsigned expected_size)
         ((sample[3]^plaintext[3])<<24);
 }
 
-static void xor_block(void *p1, void *p2, unsigned size, int key, int *key_ptr)
+static void xor_block(void *p1, void *p2, unsigned size, int key, unsigned *key_ptr)
 {
-    int *d1 = p1;
-    int *d2 = p2;
-    int k = *key_ptr;
+    unsigned *d1 = p1;
+    unsigned *d2 = p2;
+    unsigned k = *key_ptr;
 
     size >>= 2;
 
-    while (size--) {
-        *d2 = *d1 ^ k;
+    while (size > 0) {
+        *d2 = *d1 ^ (HAVE_BIGENDIAN ? av_bswap32(k) : k);
         k += key;
         d1++;
         d2++;
+        size--;
     }
 
     *key_ptr = k;
@@ -391,7 +392,8 @@ static void track_header(VividasDemuxContext *viv, AVFormatContext *s,  uint8_t
                 offset += data_len[j];
             }
 
-            st->codecpar->extradata_size = offset;
+            if (offset < st->codecpar->extradata_size)
+                st->codecpar->extradata_size = offset;
         }
     }
 
@@ -581,6 +583,8 @@ static int viv_read_packet(AVFormatContext *s,
     int64_t off;
     int ret;
 
+    if (!viv->sb_pb)
+        return AVERROR(EIO);
     if (avio_feof(viv->sb_pb))
         return AVERROR_EOF;
 
@@ -614,6 +618,8 @@ static int viv_read_packet(AVFormatContext *s,
     }
 
     pb = viv->sb_pb;
+    if (!pb)
+        return AVERROR(EIO);
     off = avio_tell(pb);
     off += viv->sb_entries[viv->current_sb_entry].size;