Gentoo Logo
Gentoo Spaceship




Note: Due to technical difficulties, the Archives are currently not up to date. GMANE provides an alternative service for most mailing lists.
c.f. bug 424647
List Archive: gentoo-commits
Navigation:
Lists: gentoo-commits: < Prev By Thread Next > < Prev By Date Next >
Headers:
To: gentoo-commits@g.o
From: "Caleb Tennis (caleb)" <caleb@g.o>
Subject: gentoo-x86 commit in media-video/qt-faststart/files: qt-faststart-0.2.diff
Date: Sun, 28 Dec 2008 23:05:59 +0000
caleb       08/12/28 23:05:59

  Added:                qt-faststart-0.2.diff
  Log:
  Version bump, with patch from 249953
  (Portage version: 2.2_rc18/cvs/Linux 2.6.18-xenU-ec2-v1.0 i686)

Revision  Changes    Path
1.1                  media-video/qt-faststart/files/qt-faststart-0.2.diff

file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/media-video/qt-faststart/files/qt-faststart-0.2.diff?rev=1.1&view=markup
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/media-video/qt-faststart/files/qt-faststart-0.2.diff?rev=1.1&content-type=text/plain

Index: qt-faststart-0.2.diff
===================================================================
--- qt-faststart.c	2008-12-05 11:33:16 -0500
+++ qt-faststart.c	2008-12-05 11:45:19 -0500
@@ -1,9 +1,16 @@
 /*
- * qt-faststart.c, v0.1
+ * qt-faststart.c, v0.2
+ *
  * by Mike Melanson (melanson@...)
  * This file is placed in the public domain. Use the program however you
  * see fit.
  *
+ * ChangLog
+ * 20081205 - Andrew Andkjar <andkjar@...>
+ *   qt-faststart.c v0.2 - fixes for infinite loops caused by various malformed input files
+ * Pre 20081205 - Mike Melanson <melanson@...>
+ *   qt-faststart.c v0.1 - original version
+ *
  * This utility rearranges a Quicktime file such that the moov atom
  * is in front of the data, thus facilitating network streaming.
  *
@@ -70,32 +77,32 @@
 
 int main(int argc, char *argv[])
 {
-    FILE *infile;
-    FILE *outfile;
+    FILE *infile = NULL;
+    FILE *outfile = NULL;
     unsigned char atom_bytes[ATOM_PREAMBLE_SIZE];
     uint32_t atom_type = 0;
     uint64_t atom_size = 0;
-    uint64_t last_offset;
-    unsigned char *moov_atom;
-    unsigned char *ftyp_atom = 0;
-    uint64_t moov_atom_size;
+    uint64_t last_offset = 0;
+    unsigned char *moov_atom = NULL;
+    unsigned char *ftyp_atom = NULL;
+    uint64_t moov_atom_size = 0;
     uint64_t ftyp_atom_size = 0;
-    uint64_t i, j;
-    uint32_t offset_count;
-    uint64_t current_offset;
+    uint64_t i = 0, j = 0;
+    uint32_t offset_count = 0;
+    uint64_t current_offset = 0;
     uint64_t start_offset = 0;
     unsigned char copy_buffer[COPY_BUFFER_SIZE];
-    int bytes_to_copy;
+    int bytes_to_copy = 0;
 
     if (argc != 3) {
-        printf ("Usage: qt-faststart <infile.mov> <outfile.mov>\n");
+        fprintf(stderr, "Usage: qt-faststart <infile.mov> <outfile.mov>\n");
         return 0;
     }
 
     infile = fopen(argv[1], "rb");
     if (!infile) {
         perror(argv[1]);
-        return 1;
+        goto error_out;
     }
 
     /* traverse through the atoms in the file to make sure that 'moov' is
@@ -107,6 +114,11 @@
         atom_size = (uint32_t)BE_32(&atom_bytes[0]);
         atom_type = BE_32(&atom_bytes[4]);
 
+        if(atom_size < ATOM_PREAMBLE_SIZE) {
+            fprintf(stderr, "fatal error:  bad atom size\n");
+            goto error_out;
+        }
+
         if ((atom_type != FREE_ATOM) &&
             (atom_type != JUNK_ATOM) &&
             (atom_type != MDAT_ATOM) &&
@@ -116,7 +128,7 @@
             (atom_type != WIDE_ATOM) &&
             (atom_type != PICT_ATOM) &&
             (atom_type != FTYP_ATOM)) {
-            printf ("encountered non-QT top-level atom (is this a Quicktime file?)\n");
+            fprintf(stderr, "encountered non-QT top-level atom (is this a Quicktime file?)\n");
             break;
         }
 
@@ -125,70 +137,82 @@
             ftyp_atom_size = atom_size;
             ftyp_atom = malloc(ftyp_atom_size);
             if (!ftyp_atom) {
-                printf ("could not allocate 0x%llX byte for ftyp atom\n",
-                        atom_size);
-                fclose(infile);
-                return 1;
+                fprintf(stderr, "could not allocate 0x%llX byte for ftyp atom\n", atom_size);
+                goto error_out;
             }
-            fseeko(infile, -ATOM_PREAMBLE_SIZE, SEEK_CUR);
+
+            if(0 != fseeko(infile, -ATOM_PREAMBLE_SIZE, SEEK_CUR)) {
+                perror(argv[1]);
+                goto error_out;
+            }
+
             if (fread(ftyp_atom, atom_size, 1, infile) != 1) {
                 perror(argv[1]);
-                free(ftyp_atom);
-                fclose(infile);
-                return 1;
+                goto error_out;
             }
             start_offset = ftello(infile);
+            if(start_offset < 0) {
+                perror(argv[1]);
+                goto error_out;
+            }
             continue;
         }
 
         /* 64-bit special case */
         if (atom_size == 1) {
             if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) {
-                break;
+              break;
             }
             atom_size = BE_64(&atom_bytes[0]);
-            fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE * 2, SEEK_CUR);
+            if(0 != fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE * 2, SEEK_CUR)) {
+                perror(argv[1]);
+                goto error_out;
+            }
         } else {
-            fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE, SEEK_CUR);
+            if(0 != fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE, SEEK_CUR)) {              
+                perror(argv[1]);
+                goto error_out;
+            }
         }
     }
 
     if (atom_type != MOOV_ATOM) {
-        printf ("last atom in file was not a moov atom\n");
-        fclose(infile);
-        return 0;
+        fprintf(stderr, "last atom in file was not a moov atom\n");
+        goto error_out;
     }
 
     /* moov atom was, in fact, the last atom in the chunk; load the whole
      * moov atom */
-    fseeko(infile, -atom_size, SEEK_END);
+    if(0 != fseeko(infile, -atom_size, SEEK_END)) {
+        perror(argv[1]);
+        goto error_out;
+    }
     last_offset = ftello(infile);
+    if(last_offset < 0) {
+        perror(argv[1]);
+        goto error_out;
+    }
     moov_atom_size = atom_size;
     moov_atom = malloc(moov_atom_size);
     if (!moov_atom) {
-        printf ("could not allocate 0x%llX byte for moov atom\n",
-            atom_size);
-        fclose(infile);
-        return 1;
+        fprintf(stderr, "could not allocate 0x%llX byte for moov atom\n", atom_size);
+        goto error_out;
     }
     if (fread(moov_atom, atom_size, 1, infile) != 1) {
         perror(argv[1]);
-        free(moov_atom);
-        fclose(infile);
-        return 1;
+        goto error_out;
     }
 
     /* this utility does not support compressed atoms yet, so disqualify
      * files with compressed QT atoms */
     if (BE_32(&moov_atom[12]) == CMOV_ATOM) {
-        printf ("this utility does not support compressed moov atoms yet\n");
-        free(moov_atom);
-        fclose(infile);
-        return 1;
+        fprintf(stderr, "this utility does not support compressed moov atoms yet\n");
+        goto error_out;
     }
 
     /* close; will be re-opened later */
     fclose(infile);
+    infile = NULL;
 
     /* crawl through the moov chunk in search of stco or co64 atoms */
     for (i = 4; i < moov_atom_size - 4; i++) {
@@ -198,8 +222,7 @@
             atom_size = BE_32(&moov_atom[i - 4]);
             if (i + atom_size - 4 > moov_atom_size) {
                 printf (" bad atom size\n");
-                free(moov_atom);
-                return 1;
+                goto error_out;
             }
             offset_count = BE_32(&moov_atom[i + 8]);
             for (j = 0; j < offset_count; j++) {
@@ -216,8 +239,7 @@
             atom_size = BE_32(&moov_atom[i - 4]);
             if (i + atom_size - 4 > moov_atom_size) {
                 printf (" bad atom size\n");
-                free(moov_atom);
-                return 1;
+                goto error_out;
             }
             offset_count = BE_32(&moov_atom[i + 8]);
             for (j = 0; j < offset_count; j++) {
@@ -240,21 +262,21 @@
     infile = fopen(argv[1], "rb");
     if (!infile) {
         perror(argv[1]);
-        free(moov_atom);
-        return 1;
+        goto error_out;
     }
 
     if (start_offset > 0) { /* seek after ftyp atom */
-        fseeko(infile, start_offset, SEEK_SET);
+        if(0 != fseeko(infile, start_offset, SEEK_SET)) {
+            perror(argv[1]);
+            goto error_out;
+        }
         last_offset -= start_offset;
     }
 
     outfile = fopen(argv[2], "wb");
     if (!outfile) {
         perror(argv[2]);
-        fclose(outfile);
-        free(moov_atom);
-        return 1;
+        goto error_out;
     }
 
     /* dump the same ftyp atom */
@@ -295,17 +317,16 @@
 
     fclose(infile);
     fclose(outfile);
-    free(moov_atom);
-    if (ftyp_atom_size > 0)
-        free(ftyp_atom);
-
+    free(moov_atom);    
+    free(ftyp_atom);
     return 0;
 
 error_out:
-    fclose(infile);
-    fclose(outfile);
+    if(infile)
+        fclose(infile);
+    if(outfile)
+        fclose(outfile);
     free(moov_atom);
-    if (ftyp_atom_size > 0)
-        free(ftyp_atom);
+    free(ftyp_atom);
     return 1;
 }





Navigation:
Lists: gentoo-commits: < Prev By Thread Next > < Prev By Date Next >
Previous by thread:
gentoo-x86 commit in media-video/qt-faststart: qt-faststart-0.2.ebuild ChangeLog
Next by thread:
gentoo-x86 commit in media-video/qt-faststart/files: qt-faststart-0.2.diff
Previous by date:
gentoo-x86 commit in media-video/qt-faststart: qt-faststart-0.2.ebuild ChangeLog
Next by date:
gentoo commit in xml/htdocs/main/en: lists.xml


Updated Jan 25, 2012

Summary: Archive of the gentoo-commits mailing list.

Donate to support our development efforts.

Copyright 2001-2013 Gentoo Foundation, Inc. Questions, Comments? Contact us.