From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id 9E6D54E162 for ; Fri, 6 Jun 2025 23:12:33 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id DC0D168C480; Sat, 7 Jun 2025 02:12:28 +0300 (EEST) Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 6E5FF687DBD for ; Sat, 7 Jun 2025 02:12:22 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id 2C13541B5F; Fri, 6 Jun 2025 23:12:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1749251541; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=PILMNaETxT8sfoy6emPRN4s/f6fNHjQjXZqDFHJhOp0=; b=mgs8wIqgL5Uly6/DUaaV3b0aOWAy3BXmKpY+3c2SG2oAl7bttPJ0DTp4yMK8AiDSPiCxWr 5WhfsX+3kGtxj1KJxFH10Wia61AwLFs0Ajb55loVYg8oeS6VK/FOII2l8r/uhvW6uZjdDK xttVKGB49AOwLJPqv/C68QQLZl0F8qTHk/IOSXnQFR/pKOw7NgBnryDJmITwkudJhIR11F WELWRpUuveBGP0GV11TeZJZg331U83uclmgdr3RlWPWpj5tIl04KInZqB+gWGm2Vu+UBIV P6B+3WupsagotweCrtJ57Ej0/oWAW/io7B+h7MIO7tVvQ4gI3sUFyL8oFNNHdA== From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Sat, 7 Jun 2025 01:12:20 +0200 Message-ID: <20250606231220.88037-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 X-GND-State: clean X-GND-Score: -70 X-GND-Cause: gggruggvucftvghtrhhoucdtuddrgeeffedrtddugdehjeefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuifetpfffkfdpucggtfgfnhhsuhgsshgtrhhisggvnecuuegrihhlohhuthemuceftddunecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenfghrlhcuvffnffculdeftddmnecujfgurhephffvvefufffkofgggfestdekredtredttdenucfhrhhomhepofhitghhrggvlhcupfhivgguvghrmhgrhigvrhcuoehmihgthhgrvghlsehnihgvuggvrhhmrgihvghrrdgttgeqnecuggftrfgrthhtvghrnhepffeulefgueevvdehhedvvdfhudelhfduhfeifffhudevvdffhfejffettdejvdelnecukfhppeeguddrieeirdeijedruddufeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeeguddrieeirdeijedruddufedphhgvlhhopehlohgtrghlhhhoshhtpdhmrghilhhfrhhomhepmhhitghhrggvlhesnhhivgguvghrmhgrhigvrhdrtggtpdhnsggprhgtphhtthhopedvpdhrtghpthhtohepfhhfmhhpvghgqdguvghvvghlsehffhhmphgvghdrohhrghdprhgtphhtthhopehjuhhsthhinhhrsehvihhmvghordgtohhm X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH] avformat/dhav: Do not evaluate avio_size() multiple times 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: Justin Ruggles Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Code like FFMIN(MAX_DURATION_BUFFER_SIZE, avio_size(s->pb)) is not safe as FFMIN() is a macro and avio_size() is thus evaluated multiple times CC: Justin Ruggles Signed-off-by: Michael Niedermayer --- libavformat/dhav.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libavformat/dhav.c b/libavformat/dhav.c index 5a83a8aea9d..c7e5371636a 100644 --- a/libavformat/dhav.c +++ b/libavformat/dhav.c @@ -246,11 +246,12 @@ static int64_t get_duration(AVFormatContext *s) int64_t end_buffer_pos; int64_t offset; unsigned date; + int64_t size = avio_size(s->pb); if (!s->pb->seekable) return 0; - if (start_pos + 16 > avio_size(s->pb)) + if (start_pos + 16 > size) return 0; avio_skip(s->pb, 16); @@ -258,13 +259,13 @@ static int64_t get_duration(AVFormatContext *s) get_timeinfo(date, &timeinfo); start = av_timegm(&timeinfo) * 1000LL; - end_buffer_size = FFMIN(MAX_DURATION_BUFFER_SIZE, avio_size(s->pb)); + end_buffer_size = FFMIN(MAX_DURATION_BUFFER_SIZE, size); end_buffer = av_malloc(end_buffer_size); if (!end_buffer) { avio_seek(s->pb, start_pos, SEEK_SET); return 0; } - end_buffer_pos = avio_size(s->pb) - end_buffer_size; + end_buffer_pos = size - end_buffer_size; avio_seek(s->pb, end_buffer_pos, SEEK_SET); avio_read(s->pb, end_buffer, end_buffer_size); -- 2.49.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".