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 B92F948120 for ; Tue, 15 Jul 2025 10:51:31 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 19C0C68E195; Tue, 15 Jul 2025 13:51:27 +0300 (EEST) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 1B56368E16F for ; Tue, 15 Jul 2025 13:51:20 +0300 (EEST) Received: from haasn.dev (unknown [10.30.1.1]) by haasn.dev (Postfix) with UTF8SMTP id D0EAB4105D; Tue, 15 Jul 2025 12:51:18 +0200 (CEST) From: Niklas Haas To: ffmpeg-devel@ffmpeg.org Date: Tue, 15 Jul 2025 12:51:17 +0200 Message-ID: <20250715105117.78271-1-ffmpeg@haasn.xyz> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avutil/hwcontext_vulkan: don't over-map buffers with prior padding 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: Niklas Haas 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: From: Niklas Haas If the image data is not at the start of the buffer allocation, such as when the buffer has padding before the image data, this function maps too much memory, since src_data + src_buf->size exceeds the buffer size. Fix this by subtracting the difference between the buffer start and the provided image data pointer from the size of the memory range to map. An easy way to reproduce this issue is using the vf_pad filter, which allocates image data buffers with a nonzero offset whenever padding is requested before the start of the image data. --- libavutil/vulkan.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libavutil/vulkan.c b/libavutil/vulkan.c index f36f2bb7cf..04cc45ee05 100644 --- a/libavutil/vulkan.c +++ b/libavutil/vulkan.c @@ -1408,7 +1408,8 @@ int ff_vk_host_map_buffer(FFVulkanContext *s, AVBufferRef **dst, return AVERROR(ENOMEM); /* Add the offset at the start, which gets ignored */ - buffer_size = offs + src_buf->size; + const ptrdiff_t src_offset = src_data - src_buf->data; + buffer_size = offs + (src_buf->size - src_offset); buffer_size = FFALIGN(buffer_size, s->props.properties.limits.minMemoryMapAlignment); buffer_size = FFALIGN(buffer_size, s->hprops.minImportedHostPointerAlignment); -- 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".