From patchwork Thu May 16 22:29:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 13165 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 360D9449AEB for ; Fri, 17 May 2019 01:49:33 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 1CC3A68A15C; Fri, 17 May 2019 01:49:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f68.google.com (mail-wr1-f68.google.com [209.85.221.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4243F689A23 for ; Fri, 17 May 2019 01:49:26 +0300 (EEST) Received: by mail-wr1-f68.google.com with SMTP id r7so5017183wrr.13 for ; Thu, 16 May 2019 15:49:26 -0700 (PDT) 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=OaDVTwpJyl1epLO6WuTHY3FKuDtWALqbNkH7woPwveg=; b=i5jCuTr9UmS3V/7fDP711wTqxJ+ePhxxuapmbHYDDOWuOR0AsKusprxU77FGESNZ/c jj5yuhAGn/equy/KrzYHyXMLJga9DCrpGDWSEwbG3FAu0SlfKWIcyadsYmsDgh2ZKjEK JdOi4OykqMiE+oKeZ/H/l78dOQNzea35X5WInfD6ksXBF/YoEawfvv+BOnxo6SwXFgoh TjW3dkX6zbL0u9uDBiCO98SvDxkle9IhTYVNv+Ws2xpHmBR4mKciLccl2W/HPDM6is9o 2Bf5GZLiamFkRYgbGgUiR3uWNudrJ9+O0CEy97tcfaD1GSFaJz2/x5BDy+1MGaDhC4vx dtKg== 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=OaDVTwpJyl1epLO6WuTHY3FKuDtWALqbNkH7woPwveg=; b=fJXCbViAx6iHrlsL0MjWPNIZS9Qzbyh67COb1Kvt098Mkk6yOUKWny7XbmdRl5i2ej LlCKhG8+70/fxKl6TfKj4MdKnv9efWGyBJQIUfT6c0cOlEQJaxd7i028bKoVhwAq9uL/ N+S3Lx0dldyBYEUGCV73eW3QZQ3wqxK+9ZsfzeB5+i+0sEUCxK0P/8mnam2vn3bbAUUw TeJGhdlvLI3oCmPF6QM4ylN05xrTgHJ3njUSESl9tqVUiyB7SZBGm4jWz70TnT08kJ2Q rxelS+GoszEYHlA/R4Ic0sPQZEGWo7ZIrAYvJwXnaV0tLwwLnM0JkRBtLRoQAESIq2My MxDA== X-Gm-Message-State: APjAAAXa85ygQ5DUrf3Y82zURKRCxsS/k/u9mymghwlj1wrw217RfTs/ MYX0K2q0IuG7dZHxsbPF8auYl7cY X-Google-Smtp-Source: APXvYqwUHiNRtGo/HlAvRCo+upC/cgbgSTWKg2s1/tAmHZ3jNlCi4/4neTzxl1IrtUEWNTUAkAy+YA== X-Received: by 2002:a5d:4849:: with SMTP id n9mr3281298wrs.233.1558046592652; Thu, 16 May 2019 15:43:12 -0700 (PDT) Received: from localhost.localdomain (ipbcc18715.dynamic.kabel-deutschland.de. [188.193.135.21]) by smtp.gmail.com with ESMTPSA id i185sm11168725wmg.32.2019.05.16.15.43.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 16 May 2019 15:43:12 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 17 May 2019 00:29:57 +0200 Message-Id: <20190516223018.30827-14-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190516223018.30827-1-andreas.rheinhardt@gmail.com> References: <20190516223018.30827-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/37] avformat/matroskadec: Improve error/EOF checks III 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" Up until now, when an element was skipped, it was relied upon ffio_limit to make sure that there is enough data available to skip. ffio_limit itself relies upon the availability of the file's size. As this needn't be available, the check has been refined: First one byte less than intended is skipped, then another byte is read, followed by a check of the error flags. Signed-off-by: Andreas Rheinhardt --- libavformat/matroskadec.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 3f11f60878..e01f1703e7 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -1280,13 +1280,23 @@ static int ebml_parse_elem(MatroskaDemuxContext *matroska, case EBML_STOP: return 1; default: - if (ffio_limit(pb, length) != length) { - // ffio_limit emits its own error message, - // so we don't have to. - return AVERROR_EOF; - } - res = avio_skip(pb, length); - res = res < 0 ? res : 0; + if (length) { + if (ffio_limit(pb, length) != length) { + // ffio_limit emits its own error message, + // so we don't have to. + return AVERROR_EOF; + } + if ((res = avio_skip(pb, length - 1)) >= 0) { + // avio_skip might take us past EOF. We check for this + // by skipping only length - 1 bytes, reading a byte and + // checking the error flags. This is done in order to check + // that the element has been properly skipped even when + // no filesize (that ffio_limit relies on) is available. + avio_r8(pb); + res = NEEDS_CHECKING; + } + } else + res = 0; } if (res) { if (res == NEEDS_CHECKING) {