]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
mp4: Provide proper error codes for all errors.
authorAndre Noll <maan@tuebingen.mpg.de>
Thu, 26 Aug 2021 17:20:49 +0000 (19:20 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Mon, 6 Jun 2022 14:30:15 +0000 (16:30 +0200)
This changes the few remaining places where we return -1 to indicate
failure by proper error codes which can be turned into a meaningful
error message.

error.h
mp4.c

diff --git a/error.h b/error.h
index 843c4ee8c23c0b8a32e7867981cfaa222b8fac0a..a4fe78a5c2878f8ba9ba8c71abfcf5171f7f2636 100644 (file)
--- a/error.h
+++ b/error.h
        PARA_ERROR(MP3DEC_CORRUPT, "too many corrupt frames"), \
        PARA_ERROR(MP3DEC_EOF, "mp3dec: end of file"), \
        PARA_ERROR(MP3_INFO, "could not read mp3 info"), \
+       PARA_ERROR(MP4_READ, "mp4: read error or unexpected end of file"), \
+       PARA_ERROR(MP4_CORRUPT, "invalid/corrupt mp4 file"), \
        PARA_ERROR(MP4_BAD_CHANNEL_COUNT, "mp4: invalid number of channels"), \
        PARA_ERROR(MP4_BAD_SAMPLE, "mp4: invalid sample number"), \
        PARA_ERROR(MP4_BAD_SAMPLERATE, "mp4: invalid sample rate"), \
        PARA_ERROR(MP4_BAD_SAMPLE_COUNT, "mp4: invalid number of samples"), \
-       PARA_ERROR(MP4_OPEN, "mp4: open failed"), \
        PARA_ERROR(MP4_TRACK, "mp4: no audio track"), \
        PARA_ERROR(MP4_MISSING_ATOM, "mp4: essential atom not found"), \
        PARA_ERROR(MPI_SCAN, "could not scan multi-precision integer"), \
diff --git a/mp4.c b/mp4.c
index dbe2cf1c5f24d2846b4adb31e45c5fed396fc125..757c42958da37c7eeac1c70dc379752da2076fae 100644 (file)
--- a/mp4.c
+++ b/mp4.c
@@ -75,8 +75,8 @@ struct mp4 {
 };
 
 /*
- * Returns -1, 0, or 1 on errors/EOF/success. Partial reads followed by EOF or
- * read errors are treated as errors.
+ * Returns -E_MP4_READ, 0, or 1 on errors/EOF/success. Partial reads followed
+ * by EOF or read errors are treated as errors.
  */
 static int read_data(struct mp4 *f, void *data, size_t size)
 {
@@ -86,7 +86,7 @@ static int read_data(struct mp4 *f, void *data, size_t size)
                        continue;
                /* regard EAGAIN as an error as reads should be blocking. */
                if (ret <= 0)
-                       return ret < 0? -1 : 0;
+                       return ret < 0? -E_MP4_READ : 0;
                size -= ret;
        }
        return 1;
@@ -380,7 +380,7 @@ static int parse_tag(struct mp4 *f, uint8_t parent, int32_t size)
                if (atom_type != ATOM_DATA)
                        continue;
                skip_bytes(f, 8); /* version (1), flags (3), reserved (4) */
-               ret = -ERRNO_TO_PARA_ERROR(EINVAL);
+               ret = -E_MP4_CORRUPT;
                if (subsize < header_size + 8 || subsize > UINT_MAX)
                        goto fail;
                len = subsize - (header_size + 8);
@@ -392,7 +392,7 @@ static int parse_tag(struct mp4 *f, uint8_t parent, int32_t size)
                value[len] = '\0';
        }
        if (!value)
-               return -ERRNO_TO_PARA_ERROR(EINVAL);
+               return -E_MP4_CORRUPT;
        f->meta.tags = para_realloc(f->meta.tags, (f->meta.count + 1)
                * sizeof(struct mp4_tag));
        tag = f->meta.tags + f->meta.count;
@@ -538,7 +538,7 @@ static int parse_sub_atoms(struct mp4 *f, uint64_t total_size, bool meta_only)
                if (ret <= 0)
                        return ret;
                if (size == 0)
-                       return -1;
+                       return -E_MP4_CORRUPT;
                dest = get_position(f) + size - header_size;
                if (atom_type == ATOM_TRAK && f->track.state == ATS_SEEN_MP4A) {
                        f->track.state = ATS_TRACK_CHANGE;
@@ -591,10 +591,8 @@ static int open_file(const struct mp4_callback *cb, bool meta_only, struct mp4 *
                if (ret <= 0)
                        break;
        }
-       if (ret < 0) {
-               ret = -E_MP4_OPEN;
+       if (ret < 0)
                goto fail;
-       }
        ret = -E_MP4_TRACK;
        if (f->track.channel_count == 0)
                goto fail;