From patchwork Mon Aug 2 10:36:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Niklas Haas X-Patchwork-Id: 29185 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:6c0f:0:0:0:0:0 with SMTP id a15csp1451481ioh; Mon, 2 Aug 2021 03:36:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8yrk00k6QsbW3rgZYo8BX6KVLPUinWWTB2Di4uQvAoaoSj2YOms440NQXhlaQ2l9K5kCF X-Received: by 2002:aa7:d709:: with SMTP id t9mr18039961edq.384.1627900581998; Mon, 02 Aug 2021 03:36:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627900581; cv=none; d=google.com; s=arc-20160816; b=KauNUYyrgfLSU0B4fxZo9gV8UMFz7K5P93xarf4h3esTHv8JqTKBoksMXwTcCC0LaK BMkpDlutmi52E9lI4YeeYqE0ZNmBuhXmO2o2H0YWby5uaEPM1MsEA8lxZAwK4vkohkOu U1D0oyTSRpySF4drV2qO8SlaLICtA6GUtccvA6HT4S85uu1HwGb/ONTEPV2v8aY107CZ 9CSlCHW7i4xcQFKg0jDXF/qsxLEUsmCkPFjPVpqNQ4EGNcp8/Vw8hTD1+Ef2RVPicWgx NFISqJO70cAZnH/k4OIPJfMSG21czMvdDNDT4trQaWviZQmabDQHWoyxrNcltY8L14zc Mj3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=vYX23fyLgXrWbCFxoRzC5AlJkhA8a3tPmFlSMfBj2W8=; b=GPr0lHVOhpkEZCh+MPdAGApqztnq2cPNJy6goyZYNn0hVRjd5z84ZgaqR/AUEoHIxr JfyzLlTxBSTNtfJwyiv1BG5JhQX7CU7QWNZPMrwMg7FrEmoWPGluUMnBUcbgagNgfq96 7PaCDoxPcUZvVNmCQ6ja7axPE6d1irm7LKCWUF7oSjC6skSe9ncJzCQpLL3G1qJVhmQt q8rKOL8+8tLzLHEmVUOy3xVfbj1q6aWPRefQXZG6szahkpGiAp57dDSk+vhhPkyRHE5G 4lf7J9BU3On3VA7Pf1CX+nFzJvLb8f2KFAJGt3QCJcCycmCi9gsEEpFiBNxzN7G5QWUS 5tFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=gYlFxq7H; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id p5si9550600edt.311.2021.08.02.03.36.20; Mon, 02 Aug 2021 03:36:21 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@haasn.xyz header.s=mail header.b=gYlFxq7H; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A38FD6809A7; Mon, 2 Aug 2021 13:36:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 308E86809A7 for ; Mon, 2 Aug 2021 13:36:11 +0300 (EEST) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 893AB4026F; Mon, 2 Aug 2021 12:36:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1627900570; bh=r5hyKPNA3eDIdEKUVurySt7x09XZOGzdXUJlntLu7EY=; h=From:To:Cc:Subject:Date:From; b=gYlFxq7HjfXWcOvLz+okxf3H6rTOErinBzq90nNDcjuv8UfFy3bI1a9mbA2EgRqjK 2oe5fMqav3KO3VmKKWlI+SauRTsi08TduF7Xem2UPSMwVUJ74EMN7025ULuXOdZoSs RAAxGZqvc8rYvfMeOxiJrY0A8CHgk0GUDDUIADJw= From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Mon, 2 Aug 2021 12:36:08 +0200 Message-Id: <20210802103608.125804-1-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/h264_sei: fix H.274 film grain parsing X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Cc: Niklas Haas Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ZUWG2ExvDkZJ From: Niklas Haas The current code has a number of issues: 1. The fg_model_id is specified in H.274 as u(2), not u(8) 2. This SEI has no ue(v) "repetition period", but a u(1) persistence flag Additionally, we can get away with using the non-long version of get_se_golomb() because the SEI spec as written limits these values to 2^(fgBitDepth)-1 where fgBitDepth maxes out at 2^3-1 + 8 = 15 bits. Fixes: corrupt bistream values due to wrong number of bits read Fixes: 4ff73add5dbe6c319d693355be44df2e17a0b8bf Signed-off-by: Niklas Haas --- libavcodec/h264_sei.c | 6 +++--- libavcodec/h264_sei.h | 2 +- libavcodec/h264_slice.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c index 7797f24650..8de1ce4b90 100644 --- a/libavcodec/h264_sei.c +++ b/libavcodec/h264_sei.c @@ -424,7 +424,7 @@ static int decode_film_grain_characteristics(H264SEIFilmGrainCharacteristics *h, if (h->present) { memset(h, 0, sizeof(*h)); - h->model_id = get_bits(gb, 8); + h->model_id = get_bits(gb, 2); h->separate_colour_description_present_flag = get_bits1(gb); if (h->separate_colour_description_present_flag) { h->bit_depth_luma = get_bits(gb, 3) + 8; @@ -448,11 +448,11 @@ static int decode_film_grain_characteristics(H264SEIFilmGrainCharacteristics *h, h->intensity_interval_lower_bound[c][i] = get_bits(gb, 8); h->intensity_interval_upper_bound[c][i] = get_bits(gb, 8); for (int j = 0; j < h->num_model_values[c]; j++) - h->comp_model_value[c][i][j] = get_se_golomb_long(gb); + h->comp_model_value[c][i][j] = get_se_golomb(gb); } } } - h->repetition_period = get_ue_golomb_long(gb); + h->persistent = get_bits1(gb); h->present = 1; } diff --git a/libavcodec/h264_sei.h b/libavcodec/h264_sei.h index f9166b45df..dbceb15627 100644 --- a/libavcodec/h264_sei.h +++ b/libavcodec/h264_sei.h @@ -183,7 +183,7 @@ typedef struct H264SEIFilmGrainCharacteristics { uint8_t intensity_interval_lower_bound[3][256]; uint8_t intensity_interval_upper_bound[3][256]; int16_t comp_model_value[3][256][6]; - int repetition_period; + int persistent; } H264SEIFilmGrainCharacteristics; typedef struct H264SEIContext { diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 41338fbcb6..03606bf504 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -1381,7 +1381,7 @@ static int h264_export_frame_props(H264Context *h) memcpy(&fgp->codec.h274.comp_model_value, &fgc->comp_model_value, sizeof(fgp->codec.h274.comp_model_value)); - fgc->present = !!fgc->repetition_period; + fgc->present = fgc->persistent; } if (h->sei.picture_timing.timecode_cnt > 0) {