From patchwork Thu May 18 20:12:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Meyers X-Patchwork-Id: 3699 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.10.2 with SMTP id 2csp823919vsk; Thu, 18 May 2017 13:13:06 -0700 (PDT) X-Received: by 10.223.175.46 with SMTP id z43mr510974wrc.84.1495138386279; Thu, 18 May 2017 13:13:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1495138386; cv=none; d=google.com; s=arc-20160816; b=E/ecWhLjpCWVx9G4fS0r8R9nIeB+2/56SiDA6n7yFAWvfcNgG5HG1jhM+iQAb5pM/N 27fTkvWmsHANWs1K4Og4X12xDCMfOX6SsifHU9S6Juw5J1Q+PQX10w9SLCjf0OsqvxV6 nnfdrvZMAB0nAyiQ7bPd1aRbl3nei2kPWzvTlcr0dftgL8O3MkBts3klIgphKh8ojiYO yaX74fMWlb3YmnFtLkO/kJBtS1tbSJlgBDC3WU0PsUNKbfnI4d8ADPbL0rauEI3ngaOv mbHwA62JiLaAJQy6dQA0WMOh/NsGhcVfX6MN/Ta2DqKXFZkQWPg65obTFTUyFiQdI3TI w7Xw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=vp7yARBNkqb1dUIR+eCwbwxYIXcE2eDooP0K98JSgag=; b=HNQQh/qa8uEi2DzC2WVPYe9Y2xBq/LLGChIFAFU+aLfgrjdBqdHjnx8HKgOyzG8kg7 5lLu4GImg5BRbjY5OWEqO5agtCqXY8kMC/I6pYVub/bt4bqhRTLCucLOqkytHQC4fEvN sbWNZE8ECbmG7l7OxMnQ8xZZPqqiY0LeOYy3b+JUgH1qF5e61VJAcdHvxrnLR4R6185V e693SksFx6OnR5xySzL199LC4GcnNYyCl9Be/vim2NDFjny9XFMhZgZNgwCuGjuuNulC wOe0VOVsoGSpNpPT1solBagOg4haMkIIL9q+12kgOzDw6731mQNVjsxJ9r0abAHzbkEa pc6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id q30si355748wra.220.2017.05.18.13.13.05; Thu, 18 May 2017 13:13:06 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 39555689882; Thu, 18 May 2017 23:13:02 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pg0-f42.google.com (mail-pg0-f42.google.com [74.125.83.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6DC30689207 for ; Thu, 18 May 2017 23:12:55 +0300 (EEST) Received: by mail-pg0-f42.google.com with SMTP id q125so27667454pgq.2 for ; Thu, 18 May 2017 13:12:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=A/7d9GvxS93ZbSwG9G/w9XJBiPDSBHR7t+ry7uH/UR4=; b=D34D7xtxmxwQbQg713vWfWnuPLdEyOYqniquvrVkSNzvXjJONpwXpqdZfU4D+DxEsA jpWeC8esQdIeM/8BMbMCuZPgN0wE6uxXncNVYV1S0vs5pzM+meJF3+vO7BAAY+wfEkRN 56EyOnPM/0/omCr4qfgKregZyx6YIpGTdkkTNNOgokLlMkBeq2tTwjEDIKvdOfMqNJVq ZRaIFJpmR2nuomPDWwZGwKM8RTu2Lbf0udvELTDeMsaUJd6mDUht/1JG/L/UccaatErY IIk6r+AEEKKyBPuNyJKyr19vTsYvM4h82e+vcSIwGGxP/gAse5JaAgPLbCHNZO+u3Vmc ytdw== 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; bh=A/7d9GvxS93ZbSwG9G/w9XJBiPDSBHR7t+ry7uH/UR4=; b=Wpv6LBS2yM5+GRPnsnfOQp4q1pPKtnmDgYcPmpdK/wqWx8a1VVEABj4KlPR0mliHEI LmuDSxqrUL8G7p/iE2yBPQVjsz19mwiV+Ntg9TOkLZuQ85W7kH2/2ErVv35a7L8LKWy7 U1MuMzgbOaWn2Brb5spD9idLU3rmzHWWQ1z2BbZ+6awlz4GZG/7xl+R6DgibGNczy1i2 w0Ot/xj4ZaFRgMr7WW59qrQHCsbtG5zHH0ALOk27ARBkTaSYWDXXJvklodR/sWeWulnN L4XohFAAlhF0OhXFjxQkpyQsa7/DyV29fob1VdllaRJRseZdhyHNXhtPz9R1OyJap5+D 6NzA== X-Gm-Message-State: AODbwcBBJROCop05JM/cY5cCabbVht2+UK6KDEgNpA27xsqr+CCO1YdU 7HZvUlfxQXTFFYBA X-Received: by 10.98.212.18 with SMTP id a18mr6585316pfh.28.1495138373661; Thu, 18 May 2017 13:12:53 -0700 (PDT) Received: from robertmeyers0.mtv.corp.google.com ([100.98.24.67]) by smtp.gmail.com with ESMTPSA id u74sm10345261pfk.58.2017.05.18.13.12.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 May 2017 13:12:53 -0700 (PDT) From: Rob Meyers To: ffmpeg-devel@ffmpeg.org Date: Thu, 18 May 2017 13:12:49 -0700 Message-Id: <20170518201249.87904-1-robertmeyers@google.com> X-Mailer: git-send-email 2.13.0.303.g4ebf302169-goog Subject: [FFmpeg-devel] [PATCH] avio_read data loss with multiple calls to fill_buffer 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: Rob Meyers MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" avio_read may make multiple calls to fill_buffer to accumulate bytes to fulfill a request. fill_buffer will overwrite previously read data if it is not prepped. Added a call to 'ffio_ensure_seekback' to adjust the s->buffer to fill_buffer's liking. This isn't necessary for the very first call to fill_buffer, thus the "size1 != size" check. --- libavformat/aviobuf.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 0a7c39eacd..8e9594cab8 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -648,6 +648,11 @@ int avio_read(AVIOContext *s, unsigned char *buf, int size) s->buf_end = s->buffer/* + len*/; } } else { + if (size1 != size) + /* this call will ensure fill_buffer will not overwrite previously + read data. */ + ffio_ensure_seekback(s, size1); + fill_buffer(s); len = s->buf_end - s->buf_ptr; if (len == 0)