From patchwork Thu Feb 11 15:42:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 25573 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 2BB3744BCDF for ; Thu, 11 Feb 2021 17:49:18 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0639768AAE9; Thu, 11 Feb 2021 17:49:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f182.google.com (mail-qk1-f182.google.com [209.85.222.182]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EE33E68AAD3 for ; Thu, 11 Feb 2021 17:49:10 +0200 (EET) Received: by mail-qk1-f182.google.com with SMTP id q85so5553829qke.8 for ; Thu, 11 Feb 2021 07:49:10 -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=TdVU4CeJ85lDfmVN4CiTkjPy75sapPiWEJad6OI2CDM=; b=HOSVvHwV1BfVLFJAvs7MqYYyoPkjyMfQ8C/5cW3HU70RcJv+LP9Cgi1Agr4SulTSv9 OG9GUQ55lesWlo3dsDzqTHe+0XPzIW3N6wt01hGeT1eRkN0uqkUogkyR6HmJ1mDGKtor Kb8zA4KsnGJ6i2BqJh6eQF30wCf/KwHrt70B76Cn9wJaQYUf77PiIqii6jpGDSq4KF0M K4/kdLI6IrEsKaLfS3uakN701YWNkqtHPXRnFA+79eGHwRz6QqgbjoLb0rthLsoa4Zrs 5s5f+G1Y0Se9utaBfLOm008ry0R4hzcw8CWlERnNqQFaIFP1L0Dn5Dlcxz7Zi28ois1+ GtHA== 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=TdVU4CeJ85lDfmVN4CiTkjPy75sapPiWEJad6OI2CDM=; b=T1DS4vivm+Rdt5margSq5TyH5z1BoD6rBWPAe05pMDGkCXeWj10IiHQ7SHfm7d73Jc 6nK740mfyaTVKkPhME6NJVX6HBVcUEhhcRPyOmDvysxAHFiUWSbpe4L9/0wJe0OhtTNf KRinefXjrcLLiQufomgQnB+OS3jpFf62poR9RMPr9hQuju2XYP3af8Hx4O5lIDibdV2u KLPIa6aBctiU2Nk2pfE5pcWpNzvQmtQB6jXyRAg5Ye6Lm3YPQpV/wKVgJUePNe68d/gf eHAIM19g7tzc4a/nkjsOAMrqtY9ryBgGlmYh2pLlEwBfm4e3wTvRryGd0addwnHmV6z+ TVgA== X-Gm-Message-State: AOAM531NdRpOwUIDl2mjFf0zPevScyMWWTWyJ+7Y7OSSnWQUlhrSqw+7 3nM7dlLnNU++LCSRAua0uSfrlMgUcRQ= X-Google-Smtp-Source: ABdhPJwww0JBJh9oHzEOBLtMyPgu9SfiTAhjngQ3FDkuL97nRtS2NJO2NPtJap6AkkWNzXvZnROqVA== X-Received: by 2002:a37:6244:: with SMTP id w65mr8919245qkb.230.1613058187003; Thu, 11 Feb 2021 07:43:07 -0800 (PST) Received: from localhost.localdomain ([181.23.76.251]) by smtp.gmail.com with ESMTPSA id d1sm3651264qtq.94.2021.02.11.07.43.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Feb 2021 07:43:06 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 11 Feb 2021 12:42:27 -0300 Message-Id: <20210211154227.114-1-jamrial@gmail.com> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/hevcdec: add some missing allocation checks 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/hevcdec.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 898dac8cbb..325c7850e6 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -515,6 +515,9 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps, s->sao_pixel_buffer_v[c_idx] = av_malloc((h * 2 * sps->ctb_width) << sps->pixel_shift); + if (!s->sao_pixel_buffer_h[c_idx] || + !s->sao_pixel_buffer_v[c_idx]) + goto fail; } } @@ -525,6 +528,10 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps, fail: pic_arrays_free(s); + for (i = 0; i < 3; i++) { + av_freep(&s->sao_pixel_buffer_h[i]); + av_freep(&s->sao_pixel_buffer_v[i]); + } s->ps.sps = NULL; return ret; } @@ -2624,13 +2631,19 @@ static int hls_slice_data_wpp(HEVCContext *s, const H2645NAL *nal) ff_alloc_entries(s->avctx, s->sh.num_entry_point_offsets + 1); - if (!s->sList[1]) { - for (i = 1; i < s->threads_number; i++) { - s->sList[i] = av_malloc(sizeof(HEVCContext)); - memcpy(s->sList[i], s, sizeof(HEVCContext)); - s->HEVClcList[i] = av_mallocz(sizeof(HEVCLocalContext)); - s->sList[i]->HEVClc = s->HEVClcList[i]; + for (i = 1; i < s->threads_number; i++) { + if (s->sList[i] && s->HEVClcList[i]) + continue; + av_freep(&s->sList[i]); + av_freep(&s->HEVClcList[i]); + s->sList[i] = av_malloc(sizeof(HEVCContext)); + s->HEVClcList[i] = av_mallocz(sizeof(HEVCLocalContext)); + if (!s->sList[i] || !s->HEVClcList[i]) { + res = AVERROR_INVALIDDATA; + goto error; } + memcpy(s->sList[i], s, sizeof(HEVCContext)); + s->sList[i]->HEVClc = s->HEVClcList[i]; } offset = (lc->gb.index >> 3);