]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/cdtoons.c
avcodec: Constify AVCodecs
[ffmpeg] / libavcodec / cdtoons.c
index 24a328352c6e5123869912d114201d6818d084a3..14c15c4579cb156d148d28518c39a072675c91af 100644 (file)
@@ -61,7 +61,7 @@ static int cdtoons_render_sprite(AVCodecContext *avctx, const uint8_t *data,
 {
     CDToonsContext *c = avctx->priv_data;
     const uint8_t *next_line = data;
-    const uint8_t *end = data + data_size;;
+    const uint8_t *end = data + data_size;
     uint16_t line_size;
     uint8_t *dest;
     int skip = 0, to_skip, x;
@@ -82,9 +82,11 @@ static int cdtoons_render_sprite(AVCodecContext *avctx, const uint8_t *data,
     for (int y = 0; y < height; y++) {
         /* one scanline at a time, size is provided */
         data      = next_line;
-        if (data > end - 2)
+        if (end - data < 2)
             return 1;
         line_size = bytestream_get_be16(&data);
+        if (end - data < line_size)
+            return 1;
         next_line = data + line_size;
         if (dst_y + y < 0)
             continue;
@@ -94,7 +96,7 @@ static int cdtoons_render_sprite(AVCodecContext *avctx, const uint8_t *data,
         to_skip = skip;
         x       = 0;
         while (x < width - skip) {
-            int raw, size;
+            int raw, size, step;
             uint8_t val;
 
             if (data >= end)
@@ -108,20 +110,22 @@ static int cdtoons_render_sprite(AVCodecContext *avctx, const uint8_t *data,
             if (to_skip >= size) {
                 to_skip -= size;
                 if (raw) {
-                    data += size;
+                    step = size;
                 } else {
-                    data += 1;
+                    step = 1;
                 }
-                if (data > next_line)
+                if (next_line - data < step)
                     return 1;
+                data += step;
                 continue;
             } else if (to_skip) {
                 size -= to_skip;
-                if (raw)
+                if (raw) {
+                    if (next_line - data < to_skip)
+                        return 1;
                     data += to_skip;
+                }
                 to_skip = 0;
-                if (data > next_line)
-                    return 1;
             }
 
             if (x + size >= width - skip)
@@ -129,10 +133,10 @@ static int cdtoons_render_sprite(AVCodecContext *avctx, const uint8_t *data,
 
             /* either raw data, or a run of a single color */
             if (raw) {
+                if (next_line - data < size)
+                    return 1;
                 memcpy(dest + x, data, size);
                 data += size;
-                if (data > next_line)
-                    return 1;
             } else {
                 uint8_t color = bytestream_get_byte(&data);
                 /* ignore transparent runs */
@@ -186,6 +190,9 @@ static int cdtoons_decode_frame(AVCodecContext *avctx, void *data,
     palette_set        = bytestream_get_byte(&buf);
     buf               += 5;
 
+    if (sprite_offset > buf_size)
+        return AVERROR_INVALIDDATA;
+
     /* read new sprites introduced in this frame */
     buf = avpkt->data + sprite_offset;
     while (sprite_count--) {
@@ -265,7 +272,7 @@ static int cdtoons_decode_frame(AVCodecContext *avctx, void *data,
                 diff_size  = bytestream_get_be32(&buf);
                 width      = bytestream_get_be16(&buf);
                 height     = bytestream_get_be16(&buf);
-                if (diff_size < 4 || diff_size - 4 > eod - buf) {
+                if (diff_size < 8 || diff_size - 4 > eod - buf) {
                     av_log(avctx, AV_LOG_WARNING, "Ran (seriously) out of data for Diff frame data.\n");
                     return AVERROR_INVALIDDATA;
                 }
@@ -435,7 +442,7 @@ static av_cold int cdtoons_decode_end(AVCodecContext *avctx)
     return 0;
 }
 
-AVCodec ff_cdtoons_decoder = {
+const AVCodec ff_cdtoons_decoder = {
     .name           = "cdtoons",
     .long_name      = NULL_IF_CONFIG_SMALL("CDToons video"),
     .type           = AVMEDIA_TYPE_VIDEO,
@@ -446,4 +453,5 @@ AVCodec ff_cdtoons_decoder = {
     .decode         = cdtoons_decode_frame,
     .capabilities   = AV_CODEC_CAP_DR1,
     .flush          = cdtoons_flush,
+    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };