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 8DE8F4972D for ; Sun, 21 Dec 2025 19:58:48 +0000 (UTC) Authentication-Results: ffbox; dkim=fail (body hash mismatch (got b'NShMT+rDa3Jz3BhNM6+DZeJRm+JXVzM0UEV262W81/s=', expected b'NeIcfxKK5LH0mIRQImqknLiVdXhIkUBq6NSk7pjcUJE=')) header.d=ffmpeg.org header.i=@ffmpeg.org header.a=rsa-sha256 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1766347110; h=mime-version : to : date : message-id : reply-to : subject : list-id : list-archive : list-archive : list-help : list-owner : list-post : list-subscribe : list-unsubscribe : from : cc : content-type : content-transfer-encoding : from; bh=NShMT+rDa3Jz3BhNM6+DZeJRm+JXVzM0UEV262W81/s=; b=FRHN2vq0TPosxYCBY0TQOvF9AOq+3N2zhqIBYua3mXDmz/apFbqaYmpToZ91+UI6mvZTW Xnlq5iKLwzS+0N2jWO5Hhw9Js5uTNVsoMuhwwGZcZ1RHUomzh0uH5ArWHK3MFu0gapWJaIm yCQ1FuE0Eev3T2NFVjChCgCvHNS9JKPiC5etcS1YHYFspwzg+Q7O4ihdNCrLMyFE5tke3yN 3GeJK/PyeZX6YygEqQ/PV/dAYlepv5YNsnRZZZbWraQSzI1lOGHet1ds0bIF2UBFuPb3/IO eSQsvtGIYK/8QK9Vc8BKhohIcOiE/H36qwFAYuyxBqqE15NugXwdlhZKFNNg== Received: from [172.20.0.2] (unknown [172.19.0.4]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 3C6A6690A57; Sun, 21 Dec 2025 21:58:30 +0200 (EET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=ffmpeg.org; s=arc; t=1766347102; b=L2VLQYGh6eOtSuTSI6EzJGq4iX8j6n+zqgcQXy5WU4LUyn7ng/AEaTIs9VnfjwhyDB70D kEJ5w2L9Bv2DLO57GZmGhslCsUCmM5ZnU1yGQETj7W2skIfAvaepP3h/Hxq8XSaYlGk7G6X t9dGSRRWwXhkgPG8OGgfrNhR+ViR1td43KiF6S7KE5M3e8Y96WeS9OcEDDB5iRa1BCUqe3h JZjepbKh2uL5C81pTy/X7ZYj2aMcDirKai35+34Jl3+gDerl4a3zFjg0UcZZhShlP7wn/Ur k766h4fRQ+aMLHOCMwBMKVvxG+bxWAdMppgczQFYwUQT2KupnauL1PF++fzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=ffmpeg.org; s=arc; t=1766347102; h=from : sender : reply-to : subject : date : message-id : to : cc : mime-version : content-type : content-transfer-encoding : content-id : content-description : resent-date : resent-from : resent-sender : resent-to : resent-cc : resent-message-id : in-reply-to : references : list-id : list-help : list-unsubscribe : list-subscribe : list-post : list-owner : list-archive; bh=ApYe1D9x1k2yjGYGGBRXvRDSS7PSRiv9hP58J+v0oNU=; b=TWDJAe6chIgp8depJImS0GBeUexprob/AW5aVrFZ/PLlD+TYbjoLLuoenN0W7A48iL5kU sp4KO831Q8kBpfqbsKYwG/g6om2u3Ub0m68lTrtq9dSmNVtFzb6DmaiKk3yW3V/nM82G/ba Hn9vrrq0i1CUNi7X6Oev+maCXBxGD7Fie2WVo2IQBKPTXLpYa06H6mSMoIOwlw0ahm77rmc IfaQ4ahhRwuGHOxniKdErGhtEEV0NCSXTa/7kGcrGQizS0iPLo65ZNhmtptJaXPgS2G7dGq uoofM/yVCttpFCqCUs2C/vEyCYOHOBCXj8XHNU0UKoVFRPbx99sA5HUccM0Q== ARC-Authentication-Results: i=1; ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none; dmarc=pass header.from=ffmpeg.org policy.dmarc=quarantine Authentication-Results: ffmpeg.org; dkim=pass header.d=ffmpeg.org header.i=@ffmpeg.org; arc=none (Message is not ARC signed); dmarc=pass (Used From Domain Record) header.from=ffmpeg.org policy.dmarc=quarantine DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ffmpeg.org; i=@ffmpeg.org; q=dns/txt; s=mail; t=1766347094; h=content-type : mime-version : content-transfer-encoding : from : to : reply-to : subject : date : from; bh=NeIcfxKK5LH0mIRQImqknLiVdXhIkUBq6NSk7pjcUJE=; b=Lh8mmxn4N9++ilLejrqTnL5nZuaN/XqeiUOr1rGI3jr9dTZA77P0SV26uSEhQuWWduvHu 9tcSLmIUbSdGKp94kVm5qXD4uAoEVoXP8TjRvr04+GbBLmnuLgBlVEOeaNsOeZ+Drys7hXx WxRv4XuCpFd+WDkqhyqnJb9mErlJxKGLSMPSzivDv3eLsMU461Cu/9oYgXAXTKwCup8rIcp W62lB4GwqjJx+0ZIOmqF/zAKUOWuxLyniP9ujZKQkH7NAFg+iMvPv6vF3PLL3xxsnQFuEFq pbhA/z0Ic5TwnvKM13Vt0v209JhFpaMzZWNpLIBVL5fumXXfjsaqCf0QMJ/A== Received: from 55ca25703178 (code.ffmpeg.org [188.245.149.3]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 2B9D4690A44 for ; Sun, 21 Dec 2025 21:58:14 +0200 (EET) MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Date: Sun, 21 Dec 2025 19:58:13 -0000 Message-ID: <176634709429.60.17911291463588960775@2cb04c0e5124> Message-ID-Hash: PLCZZN7SKZIUHU7Y5TORXEZJZEZQHJRB X-Message-ID-Hash: PLCZZN7SKZIUHU7Y5TORXEZJZEZQHJRB X-MailFrom: code@ffmpeg.org X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-ffmpeg-devel.ffmpeg.org-0; header-match-ffmpeg-devel.ffmpeg.org-1; header-match-ffmpeg-devel.ffmpeg.org-2; header-match-ffmpeg-devel.ffmpeg.org-3; emergency; member-moderation X-Mailman-Version: 3.3.10 Precedence: list Reply-To: FFmpeg development discussions and patches Subject: [FFmpeg-devel] [PATCH] avcodec/exif: keep IFD base size in buffer sizing (PR #21255) List-Id: FFmpeg development discussions and patches Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: ruikai via ffmpeg-devel Cc: ruikai Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Archived-At: List-Archive: List-Post: PR #21255 opened by ruikai URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21255 Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21255.patch Extra IFDs are stored as pseudo-tags 0xFFFC..0xFFED in the top-level IFD. The size calculation skips the 12-byte directory entry for those tags, but the extraction loop breaks on the first missing tag. If 0xFFFC is absent and 0xFFFB remains, av_exif_write allocates too small a buffer and exif_write_ifd will still emit the entry, causing an OOB write when it pads inline payloads (AV_WN32 on the last 4 bytes). Always account for the base tag size so the allocation stays conservative even when extra tags remain. Repro (ASan): ./configure --toolchain=clang-asan --enable-debug \ --disable-optimizations make -j"$(nproc)" # PNG with EXIF IFD0 entries {0xFFFB, 0x0100, 0x0112} ASAN_OPTIONS=halt_on_error=1:detect_leaks=0 ./ffmpeg_g \ -loglevel error -nostdin -i poc-exif-orient2.png -f null - this triggers heap-buffer-overflow write in exif.c:731 (exif_write_ifd). reference: https://gist.github.com/retr0reg/bc5f5dd9e2afedb09853913f1d1ee246 Regression: 784aa09fa8 Found-by: Ruikai Peng, Pwno >>From 7ea0d12bc09cbda9d978cd3cc298182fb9c54962 Mon Sep 17 00:00:00 2001 From: Ruikai Peng Date: Sun, 21 Dec 2025 14:49:56 -0500 Subject: [PATCH] avcodec/exif: keep IFD base size in buffer sizing Extra IFDs are stored as pseudo-tags 0xFFFC..0xFFED in the top-level IFD. The size calculation skips the 12-byte directory entry for those tags, but the extraction loop breaks on the first missing tag. If 0xFFFC is absent and 0xFFFB remains, av_exif_write allocates too small a buffer and exif_write_ifd will still emit the entry, causing an OOB write when it pads inline payloads (AV_WN32 on the last 4 bytes). Always account for the base tag size so the allocation stays conservative even when extra tags remain. Repro (ASan): ./configure --toolchain=clang-asan --enable-debug \ --disable-optimizations make -j"$(nproc)" # PNG with EXIF IFD0 entries {0xFFFB, 0x0100, 0x0112} ASAN_OPTIONS=halt_on_error=1:detect_leaks=0 ./ffmpeg_g \ -loglevel error -nostdin -i poc-exif-orient2.png -f null - this triggers heap-buffer-overflow write in exif.c:731 (exif_write_ifd). reference: https://gist.github.com/retr0reg/bc5f5dd9e2afedb09853913f1d1ee246 Regression: 784aa09fa8 Found-by: Ruikai Peng, Pwno --- libavcodec/exif.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libavcodec/exif.c b/libavcodec/exif.c index 0de543e35a..c7399e94b2 100644 --- a/libavcodec/exif.c +++ b/libavcodec/exif.c @@ -673,9 +673,7 @@ static size_t exif_get_ifd_size(const AVExifMetadata *ifd) for (size_t i = 0; i < ifd->count; i++) { const AVExifEntry *entry = &ifd->entries[i]; if (entry->type == AV_TIFF_IFD) { - /* this is an extra IFD, not an entry, so we don't need to add base tag size */ - size_t base_size = entry->id > 0xFFECu && entry->id <= 0xFFFCu ? 0 : BASE_TAG_SIZE; - total_size += base_size + exif_get_ifd_size(&entry->value.ifd) + entry->ifd_offset; + total_size += BASE_TAG_SIZE + exif_get_ifd_size(&entry->value.ifd) + entry->ifd_offset; } else { size_t payload_size = entry->count * exif_sizes[entry->type]; total_size += BASE_TAG_SIZE + (payload_size > 4 ? payload_size : 0); -- 2.49.1 _______________________________________________ ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org