diff mbox series

[FFmpeg-devel,3/3] avcodec/ccaption_dec: do not modify packet data in case of parity error

Message ID 20200619142650.16870-3-onemda@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,1/3] avcodec/ccaption_dec: rework non-real-time mode with pop-on captions by delaying | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Paul B Mahol June 19, 2020, 2:26 p.m. UTC
To dissallow similar errors in future, make pointers const.

Signed-off-by: Paul B Mahol <onemda@gmail.com>
---
 libavcodec/ccaption_dec.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/ccaption_dec.c b/libavcodec/ccaption_dec.c
index fe6933ab5c..63666db852 100644
--- a/libavcodec/ccaption_dec.c
+++ b/libavcodec/ccaption_dec.c
@@ -341,11 +341,13 @@  static void write_char(CCaptionSubContext *ctx, struct Screen *screen, char ch)
  * If the second byte doesn't pass parity, it returns INVALIDDATA
  * user can ignore the whole pair and pass the other pair.
  */
-static int validate_cc_data_pair(uint8_t *cc_data_pair)
+static int validate_cc_data_pair(const uint8_t *cc_data_pair, uint8_t *hi)
 {
     uint8_t cc_valid = (*cc_data_pair & 4) >>2;
     uint8_t cc_type = *cc_data_pair & 3;
 
+    *hi = cc_data_pair[1];
+
     if (!cc_valid)
         return AVERROR_INVALIDDATA;
 
@@ -355,7 +357,7 @@  static int validate_cc_data_pair(uint8_t *cc_data_pair)
             return AVERROR_INVALIDDATA;
         }
         if (!av_parity(cc_data_pair[1])) {
-            cc_data_pair[1]=0x7F;
+            *hi = 0x7F;
         }
     }
 
@@ -782,17 +784,15 @@  static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avp
     int64_t start_time;
     int64_t end_time;
     int bidx = ctx->buffer_index;
-    uint8_t *bptr = NULL;
+    const uint8_t *bptr = avpkt->data;
     int len = avpkt->size;
     int ret = 0;
     int i;
 
-    bptr = avpkt->data;
-
     for (i = 0; i < len; i += 3) {
-        uint8_t cc_type = bptr[i] & 1;
+        uint8_t hi, cc_type = bptr[i] & 1;
 
-        if (validate_cc_data_pair(bptr + i))
+        if (validate_cc_data_pair(bptr + i, &hi))
             continue;
 
         if (ctx->data_field < 0)
@@ -801,7 +801,7 @@  static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avp
         if (cc_type != ctx->data_field)
             continue;
 
-        ret = process_cc608(ctx, bptr[i + 1] & 0x7f, bptr[i + 2] & 0x7f);
+        ret = process_cc608(ctx, hi & 0x7f, bptr[i + 2] & 0x7f);
         if (ret < 0)
             return ret;