PR #24221 opened by yongdev
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24221
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24221.patch

When performing unscaled planar copies or format conversions on 16-bit
buffers in planarCopyWrapper, srcPtr2 and dstPtr2 are not guaranteed to
be 8-byte aligned (e.g. subsampled chroma planes with non-multiple-of-8
widths/strides or odd slice offsets).

AV_RN64A / AV_WN64A and AV_RN32A / AV_WN32A cast pointers to av_alias64
or av_alias32 which have __attribute__((aligned(8))) or aligned(4).
Dereferencing unaligned pointers with aligned attribute triggers Undefined
Behavior traps (SIGILL / UD1 instruction with Clang -fsanitize=alignment).
Replace them with AV_RN64 / AV_WN64 and AV_RN32 / AV_WN32.

Signed-off-by: yongdev <[email protected]>

# Summary of changes

Briefly describe what this PR does and why.

<!--
If this PR requires new FATE test samples, attach them to the PR and
list their target paths below (relative to the fate-suite root).

Attached filenames must match the sample's filename:

```fate-samples
# e.g. vorbis/new-sample.ogg
```
-->



>From 4fb66efaeed00d559ff0233df398627889bc4ddc Mon Sep 17 00:00:00 2001
From: yongdev <[email protected]>
Date: Tue, 18 Aug 2026 23:04:36 +0000
Subject: [PATCH] libswscale: use unaligned read/write macros in
 planarCopyWrapper

When performing unscaled planar copies or format conversions on 16-bit
buffers in planarCopyWrapper, srcPtr2 and dstPtr2 are not guaranteed to
be 8-byte aligned (e.g. subsampled chroma planes with non-multiple-of-8
widths/strides or odd slice offsets).

AV_RN64A / AV_WN64A and AV_RN32A / AV_WN32A cast pointers to av_alias64
or av_alias32 which have __attribute__((aligned(8))) or aligned(4).
Dereferencing unaligned pointers with aligned attribute triggers Undefined
Behavior traps (SIGILL / UD1 instruction with Clang -fsanitize=alignment).
Replace them with AV_RN64 / AV_WN64 and AV_RN32 / AV_WN32.

Signed-off-by: yongdev <[email protected]>
---
 libswscale/swscale_unscaled.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/libswscale/swscale_unscaled.c b/libswscale/swscale_unscaled.c
index 18fc8fe7d7..7acab95e03 100644
--- a/libswscale/swscale_unscaled.c
+++ b/libswscale/swscale_unscaled.c
@@ -2291,13 +2291,13 @@ static int planarCopyWrapper(SwsInternal *c, const 
uint8_t *const src[],
                            shiftonly) {
 #if HAVE_FAST_64BIT
                             for (; j < length - 3; j += 4) {
-                                uint64_t v = AV_RN64A(srcPtr2 + j) >> 
src_shift;
-                                AV_WN64A(dstPtr2 + j, (v << shift) << 
dst_shift);
+                                uint64_t v = AV_RN64(srcPtr2 + j) >> src_shift;
+                                AV_WN64(dstPtr2 + j, (v << shift) << 
dst_shift);
                             }
 #else
                             for (; j < length - 1; j += 2) {
-                                uint32_t v = AV_RN32A(srcPtr2 + j) >> 
src_shift;
-                                AV_WN32A(dstPtr2 + j, (v << shift) << 
dst_shift);
+                                uint32_t v = AV_RN32(srcPtr2 + j) >> src_shift;
+                                AV_WN32(dstPtr2 + j, (v << shift) << 
dst_shift);
                             }
 #endif
                         }
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to