From 662fbe85190d071f2d4b839d0ab8440920e8d47d Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Wed, 18 Aug 2021 17:08:08 +0200 Subject: [PATCH] mp4: Add error checking to parse_atoms() and friends. 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 | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/mp4.c b/mp4.c index 7b5f4694..c40fbe0b 100644 --- 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; } -- 2.39.2