]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
mp4: Add error checking to parse_atoms() and friends.
authorAndre Noll <maan@tuebingen.mpg.de>
Wed, 18 Aug 2021 15:08:08 +0000 (17:08 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 30 May 2022 19:37:35 +0000 (21:37 +0200)
After this patch read errors are propagated all the way down from the
read_data() primitive to the public entry functions mp4_open_read()
and mp4_open_meta().

mp4.c

diff --git a/mp4.c b/mp4.c
index 7b5f4694d5afe93d2b5fb96efa46646d6f967420..c40fbe0b6cce2e1e7a87436b941555d7d780176b 100644 (file)
--- a/mp4.c
+++ b/mp4.c
@@ -913,7 +913,9 @@ static int parse_sub_atoms(struct mp4 *f, uint64_t total_size, int meta_only)
                if (meta_only && !need_parse_when_meta_only(atom_type)) {
                        set_position(f, get_position(f) + size - header_size);
                } else if (atom_type < SUBATOMIC) {
-                       parse_sub_atoms(f, size - header_size, meta_only);
+                       ret = parse_sub_atoms(f, size - header_size, meta_only);
+                       if (ret <= 0)
+                               return ret;
                } else {
                        ret = atom_read(f, size, atom_type);
                        if (ret <= 0)
@@ -924,7 +926,7 @@ static int parse_sub_atoms(struct mp4 *f, uint64_t total_size, int meta_only)
 }
 
 /* parse root atoms */
-static int32_t parse_atoms(struct mp4 *f, int meta_only)
+static int parse_atoms(struct mp4 *f, int meta_only)
 {
        int ret;
        uint64_t size;
@@ -946,7 +948,9 @@ static int32_t parse_atoms(struct mp4 *f, int meta_only)
                if (meta_only && !need_parse_when_meta_only(atom_type)) {
                        set_position(f, get_position(f) + size - header_size);
                } else if (atom_type < SUBATOMIC) {
-                       parse_sub_atoms(f, size - header_size, meta_only);
+                       ret = parse_sub_atoms(f, size - header_size, meta_only);
+                       if (ret <= 0)
+                               return ret;
                } else {
                        /* skip this atom */
                        set_position(f, get_position(f) + size - header_size);
@@ -957,13 +961,14 @@ static int32_t parse_atoms(struct mp4 *f, int meta_only)
 
 struct mp4 *mp4_open_read(const struct mp4_callback *cb)
 {
+       int ret;
        struct mp4 *f = para_calloc(sizeof(struct mp4));
 
        f->cb = cb;
-       parse_atoms(f, 0);
-       if (f->error) {
+       ret = parse_atoms(f, 0);
+       if (ret < 0 || f->error) {
                free(f);
-               f = NULL;
+               return NULL;
        }
        return f;
 }
@@ -1158,13 +1163,14 @@ int32_t mp4_num_samples(const struct mp4 *f, int32_t track)
 
 struct mp4 *mp4_open_meta(const struct mp4_callback *cb)
 {
+       int ret;
        struct mp4 *f = para_calloc(sizeof(struct mp4));
 
        f->cb = cb;
-       parse_atoms(f, 1);
-       if (f->error) {
+       ret = parse_atoms(f, 1);
+       if (ret < 0 || f->error) {
                free(f);
-               f = NULL;
+               return NULL;
        }
        return f;
 }