From patchwork Thu Oct 17 08:29:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 15795 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 C6535449FA2 for ; Thu, 17 Oct 2019 11:30:39 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B2E8868A65A; Thu, 17 Oct 2019 11:30:39 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D0F8668A3BB for ; Thu, 17 Oct 2019 11:30:38 +0300 (EEST) Received: by mail-wr1-f67.google.com with SMTP id n14so1271568wrw.9 for ; Thu, 17 Oct 2019 01:30:38 -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=I015+Pjxd5GJ2nx+DtMzvSz00yD0joCFYJQHrK3Kac0=; b=kwlgA58PTT/ulrvAtBFWVau3YFibAMaJVFcikDFitqtVN//y4tNrzNJKEiyt7ey6B3 Eua2S/TFRSaZfTSjmuPJxGAP7td2idOQzwnvjkRv6iiT/7XnpzF/XuhsDp/t9ZOWVGWw IXFwfIs2WcfKKFWZLRRXlA5RYvGpc+MXtG+pWCAib8k1Iylkc9Uryf/8u2QCF1jjSmGG L2ivr5l/JmwSNlCJAe8d2AJwtW/3WBZD0iGeDh0aKigwZ090ahVwF50G0hyAt2Un8qWQ jM5s2cVSWMIr2+1Wfjivjk+mwBbzorU1bzrJ/FOGA9GfQKIYPX1Q5296ZXOqVvaDfvs4 M9CQ== 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=I015+Pjxd5GJ2nx+DtMzvSz00yD0joCFYJQHrK3Kac0=; b=qRLHTp+HqWoIs3//PPF7Nih1Vg4aVmSNDxpf4KAXQBSA3tKt7iJwFLp89wy1wUaeBy nExY7Cgf10MaHGag5VUx6T6RXY6DXWeOEvvm0kTv4tDSv3gg5Ff9BF0TBZjUtmQLTzBA l/W+JWILzHvOZx6iaL/baIwl/ySjIGBPEsXL+B/ksfPrMoKZ3ODeA9n+xyGjWY3QTkHp skOtME5VACE5ezsYUUTTLETdVfAJHZR2wNf+/TJXDTUyBzlhmm2RRFvAVIQGZtV0zTlw ztdDskFJCwU4ZEsyxXP91IkEDUS81h+9f/2vw5F36rCSr3PGKBybYNmjwxuyI/Utc/ak egHw== X-Gm-Message-State: APjAAAVmEN9+wHaBZpwE6oejv/mvN48ptQF2lIvx713kInz/hPt9lyye u7NcjgfE4yoIlpZNxfw0qiEydJVx X-Google-Smtp-Source: APXvYqx6uPEMNSXyqRpKibz2IAERaYNCcTjvJIGpowGxZpmJUSKK6r0PWHsknMYvy3lOEIdGJkDbwg== X-Received: by 2002:adf:f101:: with SMTP id r1mr2022226wro.320.1571301038106; Thu, 17 Oct 2019 01:30:38 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc08937.dynamic.kabel-deutschland.de. [188.192.137.55]) by smtp.gmail.com with ESMTPSA id l7sm1369273wrv.77.2019.10.17.01.30.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Oct 2019 01:30:37 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 17 Oct 2019 10:29:32 +0200 Message-Id: <20191017082945.13534-2-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191017082945.13534-1-andreas.rheinhardt@gmail.com> References: <20191017082945.13534-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 02/15] bytestream: Make get_bytes_left compatible with overread 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" bytestream2_get_bytes_left returns an unsigned int; as a result, it returns big positive numbers if an overread already happened, making it unsuitable for scenarios where one wants to allow this (because the buffer is actually padded so that no segfaults can happen). So add a function returning ptrdiff_t for this purpose; given that it is intended to be used with the unsafe functions, it has an "u" suffix, although it is not unsafe by itself. Signed-off-by: Andreas Rheinhardt --- libavcodec/bytestream.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavcodec/bytestream.h b/libavcodec/bytestream.h index 7be7fc22fc..18774524cf 100644 --- a/libavcodec/bytestream.h +++ b/libavcodec/bytestream.h @@ -156,6 +156,11 @@ static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext * return g->buffer_end - g->buffer; } +static av_always_inline ptrdiff_t bytestream2_get_bytes_leftu(GetByteContext *g) +{ + return g->buffer_end - g->buffer; +} + static av_always_inline unsigned int bytestream2_get_bytes_left_p(PutByteContext *p) { return p->buffer_end - p->buffer;