From patchwork Tue Dec 8 19:43:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 24438 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 2D47A44AC94 for ; Tue, 8 Dec 2020 21:44:30 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id ED1BA689E7D; Tue, 8 Dec 2020 21:44:29 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qt1-f195.google.com (mail-qt1-f195.google.com [209.85.160.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1B40568920B for ; Tue, 8 Dec 2020 21:44:23 +0200 (EET) Received: by mail-qt1-f195.google.com with SMTP id 7so12831655qtp.1 for ; Tue, 08 Dec 2020 11:44:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=dZJcomfIO2iId7icROyewG3snqOxX+Dz13jAKQ6MLwA=; b=ffcVc7tWRATbApwieu1GAiAyUoJ1OPhEZUQ/baZRk6XWLD5pk5dNw7q3PFq1+uaqGK G82pgZKPtE/pFQFPHD19cwE6haI5AhAwE1GFBWTuO7D+eoYlQYVEWBaPiOeqFO1PwqIP EIRbJ7JzSakEVCf677eKRhDyVCYtZuwU1HcgNgIpE5Efl7HXaemAYi/yPlueUV+3EsB3 4qBNL9UMeTtqilEkTG7NDGekhzrW42tkUwoy9uSi9L/EVaKuiGY0u2xyQC4fIZRuX5Z7 Iu7ac8fOX6dI4dIff+G/vRDN9cSpNOq1Zz5r23yy7pPFtfJOLEKBaeWhMbObnPyhRNSV Csew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=dZJcomfIO2iId7icROyewG3snqOxX+Dz13jAKQ6MLwA=; b=TfLXu1kNiYHAQ/P0ydw7iDHdiRWfDjAxENYvi7y/18+Cy2uGcdvlzvPg/vfa6/W2cs e7Hq+9boXFLGgBIG42n9RvPATU4ul+8eoPFAhl3R+wFzhvsdZq3Uo742CuOoJJE5xkaC wwjov5PdILO6UGzr2NMK1ntukRg1sQs9zY7bfUX2IWc2hOKX141CIM0z8xRSMoirfSBC scZ+5HOCaF8F275ecDgnNKGjK4kN0qOMA/9h6HJmWRpFZyS5sB2k/zXdq8sLPMjRpLX7 Jo767VOpsFVhzzFIMrnGlxKHY0nLud+InbKnaJhYYjxwT3MC2X5v6Rqfhroirdfg7Izt 58MA== X-Gm-Message-State: AOAM532//gZeF6lwODMseeqmvp8Acn+KWAPNEq1SaVWURBkBvSMvIyUb I3H3Nbi+ocIWTRKPhXeJGVB8aIwEnWA= X-Google-Smtp-Source: ABdhPJynHagPkdpxzMPnn/AJDADhIbVwHxJy7oRznwvWx/QBUk5o4hqjAI+wDRsNohy2TIc1VU5EYw== X-Received: by 2002:a05:622a:34d:: with SMTP id r13mr32624642qtw.93.1607456661060; Tue, 08 Dec 2020 11:44:21 -0800 (PST) Received: from localhost.localdomain ([181.23.87.99]) by smtp.gmail.com with ESMTPSA id t133sm14956670qke.82.2020.12.08.11.44.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Dec 2020 11:44:19 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Tue, 8 Dec 2020 16:43:27 -0300 Message-Id: <20201208194330.2962-1-jamrial@gmail.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/4] avcodec/h264_sei: refactor parsing User Data Registered ITU-T T35 SEI messages X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: James Almer --- libavcodec/h264_sei.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c index 669560ae5f..42ba94114c 100644 --- a/libavcodec/h264_sei.c +++ b/libavcodec/h264_sei.c @@ -183,12 +183,11 @@ static int decode_registered_user_data_closed_caption(H264SEIA53Caption *h, static int decode_registered_user_data(H264SEIContext *h, GetBitContext *gb, void *logctx, int size) { - uint32_t country_code; - uint32_t user_identifier; + int country_code, provider_code; - if (size < 7) + if (size < 3) return AVERROR_INVALIDDATA; - size -= 7; + size -= 3; country_code = get_bits(gb, 8); // itu_t_t35_country_code if (country_code == 0xFF) { @@ -196,20 +195,34 @@ static int decode_registered_user_data(H264SEIContext *h, GetBitContext *gb, size--; } + if (country_code != 0xB5) // usa_country_code + return 0; + /* itu_t_t35_payload_byte follows */ - skip_bits(gb, 8); // terminal provider code - skip_bits(gb, 8); // terminal provider oriented code - user_identifier = get_bits_long(gb, 32); + provider_code = get_bits(gb, 16); + + switch (provider_code) { + case 0x31: { // atsc_provider_code + uint32_t user_identifier; - switch (user_identifier) { + if (size < 4) + return AVERROR(EINVAL); + size -= 4; + + user_identifier = get_bits_long(gb, 32); + switch (user_identifier) { case MKBETAG('D', 'T', 'G', '1'): // afd_data return decode_registered_user_data_afd(&h->afd, gb, size); case MKBETAG('G', 'A', '9', '4'): // closed captions return decode_registered_user_data_closed_caption(&h->a53_caption, gb, logctx, size); default: - skip_bits(gb, size * 8); break; + } + break; + } + default: + break; } return 0;