+ case MKBETAG('G', 'A', '9', '4'): // closed captions
+ if (size < 3)
+ return AVERROR(EINVAL);
+
+ user_data_type_code = get_bits(&h->gb, 8);
+ if (user_data_type_code == 0x3) {
+ skip_bits(&h->gb, 1); // reserved
+
+ flag = get_bits(&h->gb, 1); // process_cc_data_flag
+ if (flag) {
+ skip_bits(&h->gb, 1); // zero bit
+ cc_count = get_bits(&h->gb, 5);
+ skip_bits(&h->gb, 8); // reserved
+ size -= 2;
+
+ if (cc_count && size >= cc_count * 3) {
+ int i, ret;
+ int new_size = (int64_t) h->a53_caption_size +
+ (int64_t) cc_count * 3;
+
+ if (new_size > INT_MAX)
+ return AVERROR(EINVAL);
+
+ /* Allow merging of the cc data from two fields. */
+ ret = av_reallocp(&h->a53_caption,
+ h->a53_caption_size + cc_count * 3);
+ if (ret < 0)
+ return ret;
+
+ for (i = 0; i < cc_count; i++) {
+ h->a53_caption[h->a53_caption_size++] = get_bits(&h->gb, 8);
+ h->a53_caption[h->a53_caption_size++] = get_bits(&h->gb, 8);
+ h->a53_caption[h->a53_caption_size++] = get_bits(&h->gb, 8);
+ }
+
+ skip_bits(&h->gb, 8); // marker_bits
+ }
+ }
+ }
+ break;