From patchwork Fri Jan 24 22:48:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 17522 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 632F2449962 for ; Sat, 25 Jan 2020 00:48:55 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5053468AF61; Sat, 25 Jan 2020 00:48:55 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3AB9368AD7F for ; Sat, 25 Jan 2020 00:48:49 +0200 (EET) Received: by mail-wr1-f66.google.com with SMTP id z7so3897308wrl.13 for ; Fri, 24 Jan 2020 14:48:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1KmDrd6R3nZALx/RJ/gkkrNVe4/xKmWj6XMc4khPWRo=; b=RvnUrJpagGbeT6Lu2BVTEdvUyI4E0gqSdJwnOwluEW+mBP281L/vGwY/rJyt6RnlmM GUmNQl6sT8AFHfjGRmTUlYO3osU7d3y84JjCm5qv7Xu4ZfAvrHKLZ/D5XsUyBzpjjMVJ kC959t83onQ8zYuO7jo/af4dWTtVRIJYNfrqCtm99O0svo9ZDMeNrij8RrQs247VuL7Z wpdrkGw4wCjc+rXA9aNKdvO9KKcCmiWs2AzYfx1E9WHe+URsw3BQBEdfbVyBNtTEe8E7 /E0+28oW2wc89mSwt49VYU3gREWxWY8A+HXit8ugxH/AKOP95Wk71u2bMXxSZX2zW5bL z1Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1KmDrd6R3nZALx/RJ/gkkrNVe4/xKmWj6XMc4khPWRo=; b=Y2dRSj4LO/GPRQ1PEy8PchaZWHEF4ym5wtd8cPhbe6Pxmc+OAzO1NG1m6/w4pfPi9+ R4KmucPOCuDK2wvSe9J/tKVBh25UCDJLr/L6BdLRi284CPZi3YrkOp60UNMO39uDelg2 WpOTaU1tw1E84S1FtzmqbpoQpxNJlEPt1aUSkvwkPKFOREgA3g0D07zgJ8xU6V61D5eM eTjJxHhGere8k0LkfUU7UMe1qF7nCCWeUZ/ztxGbPFNpU33K49ZJo1bM95b7/JmJ6n3u avViJdr6urajFjGj8cuWqabhTMZXqIuQmx9kmAL3ZcanDDc/dAu5edcQzQG7+hZIH1ps u0ZA== X-Gm-Message-State: APjAAAXpKUYubPkzhTapFOfjsS4WnGfzfUrlc/gLDQSFoHYZtS9O8ogv T03slch65Z2RSZ25IYtHNSmNfrCo X-Google-Smtp-Source: APXvYqxDh+2C5T2xHnpBSSn69OZ431m4EeL0TbJzFffk+i/23QbmrWwj4sjdLj7QXL3qio6mFo1uGw== X-Received: by 2002:adf:e683:: with SMTP id r3mr7176350wrm.38.1579906128469; Fri, 24 Jan 2020 14:48:48 -0800 (PST) Received: from sblaptop.fritz.box (ipbcc08bbf.dynamic.kabel-deutschland.de. [188.192.139.191]) by smtp.gmail.com with ESMTPSA id z25sm8977594wmf.14.2020.01.24.14.48.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 14:48:48 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 24 Jan 2020 23:48:29 +0100 Message-Id: <20200124224833.17579-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200123160832.2020-1-andreas.rheinhardt@gmail.com> References: <20200123160832.2020-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 08/12] avformat/avc, hevc: Check the allocations implicit in dynamic buffers 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Dynamic buffers involve implicit allocations that are currently usually unchecked; ff_avc_parse_nal_units_buf() and ff_hevc_annexb2mp4buf() are no exceptions to this. So add checks for them. Signed-off-by: Andreas Rheinhardt --- One might argue that this should also check for whether the size returned by ff_hevc_annexb2mp4() resp. ff_avc_parse_nal_units() equals the size of the buffer (dynamic buffers have an implicit INT_MAX/2 allocation limit and if it is hit, no further writes are performed, but the already written data is not discarded); given that I prefer to drop this limit (and replace it by INT_MAX) later I have not added such a check here. (In case of an unchecked allocation failure in which the returned buffer is NULL, the returned size is -AV_INPUT_BUFFER_PADDING_SIZE. This is something that put_ebml_num() (the int is converted to uint64_t for it) doesn't like at all (it should assert, yet it actually runs into an infinite loop in ebml_num_size()).) libavformat/avc.c | 3 +++ libavformat/hevc.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/libavformat/avc.c b/libavformat/avc.c index cd15ac3cdb..aef5d3c35d 100644 --- a/libavformat/avc.c +++ b/libavformat/avc.c @@ -102,6 +102,9 @@ int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size) ff_avc_parse_nal_units(pb, buf_in, *size); *size = avio_close_dyn_buf(pb, buf); + if (!*buf) + return AVERROR(ENOMEM); + return 0; } diff --git a/libavformat/hevc.c b/libavformat/hevc.c index f621cb2f19..a4e53bc4ab 100644 --- a/libavformat/hevc.c +++ b/libavformat/hevc.c @@ -1061,6 +1061,8 @@ int ff_hevc_annexb2mp4_buf(const uint8_t *buf_in, uint8_t **buf_out, } *size = avio_close_dyn_buf(pb, buf_out); + if (!*buf_out) + return AVERROR(ENOMEM); return 0; }