Browse code

prores: Add a codepath for decoding errors

Luca Barbato authored on 2013/10/10 15:40:39
Showing 1 changed files
... ...
@@ -369,10 +369,10 @@ static inline void decode_dc_coeffs(GetBitContext *gb, int16_t *out,
369 369
 /**
370 370
  * Decode AC coefficients for all blocks in a slice.
371 371
  */
372
-static inline void decode_ac_coeffs(GetBitContext *gb, int16_t *out,
373
-                                    int blocks_per_slice,
374
-                                    int plane_size_factor,
375
-                                    const uint8_t *scan)
372
+static inline int decode_ac_coeffs(GetBitContext *gb, int16_t *out,
373
+                                   int blocks_per_slice,
374
+                                   int plane_size_factor,
375
+                                   const uint8_t *scan)
376 376
 {
377 377
     int pos, block_mask, run, level, sign, run_cb_index, lev_cb_index;
378 378
     int max_coeffs, bits_left;
... ...
@@ -390,13 +390,13 @@ static inline void decode_ac_coeffs(GetBitContext *gb, int16_t *out,
390 390
 
391 391
         bits_left = get_bits_left(gb);
392 392
         if (bits_left <= 0 || (bits_left <= 8 && !show_bits(gb, bits_left)))
393
-            return;
393
+            return AVERROR_INVALIDDATA;
394 394
 
395 395
         run = decode_vlc_codeword(gb, ff_prores_ac_codebook[run_cb_index]);
396 396
 
397 397
         bits_left = get_bits_left(gb);
398 398
         if (bits_left <= 0 || (bits_left <= 8 && !show_bits(gb, bits_left)))
399
-            return;
399
+            return AVERROR_INVALIDDATA;
400 400
 
401 401
         level = decode_vlc_codeword(gb, ff_prores_ac_codebook[lev_cb_index]) + 1;
402 402
 
... ...
@@ -408,22 +408,24 @@ static inline void decode_ac_coeffs(GetBitContext *gb, int16_t *out,
408 408
         out[((pos & block_mask) << 6) + scan[pos >> plane_size_factor]] =
409 409
             (level ^ sign) - sign;
410 410
     }
411
+
412
+    return 0;
411 413
 }
412 414
 
413 415
 
414 416
 /**
415 417
  * Decode a slice plane (luma or chroma).
416 418
  */
417
-static void decode_slice_plane(ProresContext *ctx, ProresThreadData *td,
418
-                               const uint8_t *buf,
419
-                               int data_size, uint16_t *out_ptr,
420
-                               int linesize, int mbs_per_slice,
421
-                               int blocks_per_mb, int plane_size_factor,
422
-                               const int16_t *qmat, int is_chroma)
419
+static int decode_slice_plane(ProresContext *ctx, ProresThreadData *td,
420
+                              const uint8_t *buf,
421
+                              int data_size, uint16_t *out_ptr,
422
+                              int linesize, int mbs_per_slice,
423
+                              int blocks_per_mb, int plane_size_factor,
424
+                              const int16_t *qmat, int is_chroma)
423 425
 {
424 426
     GetBitContext gb;
425 427
     int16_t *block_ptr;
426
-    int mb_num, blocks_per_slice;
428
+    int mb_num, blocks_per_slice, ret;
427 429
 
428 430
     blocks_per_slice = mbs_per_slice * blocks_per_mb;
429 431
 
... ...
@@ -433,8 +435,10 @@ static void decode_slice_plane(ProresContext *ctx, ProresThreadData *td,
433 433
 
434 434
     decode_dc_coeffs(&gb, td->blocks, blocks_per_slice);
435 435
 
436
-    decode_ac_coeffs(&gb, td->blocks, blocks_per_slice,
437
-                     plane_size_factor, ctx->scantable.permutated);
436
+    ret = decode_ac_coeffs(&gb, td->blocks, blocks_per_slice,
437
+                           plane_size_factor, ctx->scantable.permutated);
438
+    if (ret < 0)
439
+        return ret;
438 440
 
439 441
     /* inverse quantization, inverse transform and output */
440 442
     block_ptr = td->blocks;
... ...
@@ -468,6 +472,7 @@ static void decode_slice_plane(ProresContext *ctx, ProresThreadData *td,
468 468
             }
469 469
         }
470 470
     }
471
+    return 0;
471 472
 }
472 473
 
473 474
 
... ...
@@ -560,6 +565,7 @@ static int decode_slice(AVCodecContext *avctx, void *tdata)
560 560
     int y_data_size, u_data_size, v_data_size, a_data_size;
561 561
     int y_linesize, u_linesize, v_linesize, a_linesize;
562 562
     int coff[4];
563
+    int ret;
563 564
 
564 565
     buf             = ctx->slice_data[slice_num].index;
565 566
     slice_data_size = ctx->slice_data[slice_num + 1].index - buf;
... ...
@@ -631,24 +637,31 @@ static int decode_slice(AVCodecContext *avctx, void *tdata)
631 631
     }
632 632
 
633 633
     /* decode luma plane */
634
-    decode_slice_plane(ctx, td, buf + coff[0], y_data_size,
635
-                       (uint16_t*) y_data, y_linesize,
636
-                       mbs_per_slice, 4, slice_width_factor + 2,
637
-                       td->qmat_luma_scaled, 0);
634
+    ret = decode_slice_plane(ctx, td, buf + coff[0], y_data_size,
635
+                             (uint16_t*) y_data, y_linesize,
636
+                             mbs_per_slice, 4, slice_width_factor + 2,
637
+                             td->qmat_luma_scaled, 0);
638
+
639
+    if (ret < 0)
640
+        return ret;
638 641
 
639 642
     /* decode U chroma plane */
640
-    decode_slice_plane(ctx, td, buf + coff[1], u_data_size,
641
-                       (uint16_t*) u_data, u_linesize,
642
-                       mbs_per_slice, ctx->num_chroma_blocks,
643
-                       slice_width_factor + ctx->chroma_factor - 1,
644
-                       td->qmat_chroma_scaled, 1);
643
+    ret = decode_slice_plane(ctx, td, buf + coff[1], u_data_size,
644
+                             (uint16_t*) u_data, u_linesize,
645
+                             mbs_per_slice, ctx->num_chroma_blocks,
646
+                             slice_width_factor + ctx->chroma_factor - 1,
647
+                             td->qmat_chroma_scaled, 1);
648
+    if (ret < 0)
649
+        return ret;
645 650
 
646 651
     /* decode V chroma plane */
647
-    decode_slice_plane(ctx, td, buf + coff[2], v_data_size,
648
-                       (uint16_t*) v_data, v_linesize,
649
-                       mbs_per_slice, ctx->num_chroma_blocks,
650
-                       slice_width_factor + ctx->chroma_factor - 1,
651
-                       td->qmat_chroma_scaled, 1);
652
+    ret = decode_slice_plane(ctx, td, buf + coff[2], v_data_size,
653
+                             (uint16_t*) v_data, v_linesize,
654
+                             mbs_per_slice, ctx->num_chroma_blocks,
655
+                             slice_width_factor + ctx->chroma_factor - 1,
656
+                             td->qmat_chroma_scaled, 1);
657
+    if (ret < 0)
658
+        return ret;
652 659
 
653 660
     /* decode alpha plane if available */
654 661
     if (a_data && a_data_size)