PR #25599 opened by Marvin Scholz (ePirat)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25599
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/25599.patch

Using `bswap_buf` on unaligned bitstream chunk from packet directly is
undefined behavior. Copy to `bitstream_buffer` first which is fully
aligned.


>From a819c3501e4764336637f8f6e4c306ee34ef402b Mon Sep 17 00:00:00 2001
From: Marvin Scholz <[email protected]>
Date: Thu, 29 Oct 2026 22:33:46 +0000
Subject: [PATCH] avcodec/4xm: fix unaligned access

Using bswap_buf on unaligned bitstream chunk from packet directly is
undefined behavior. Copy to bitstream_buffer first which is fully
aligned.

Signed-off-by: Marvin Scholz <[email protected]>
---
 libavcodec/4xm.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libavcodec/4xm.c b/libavcodec/4xm.c
index c6b2ce12304..78bc3908090 100644
--- a/libavcodec/4xm.c
+++ b/libavcodec/4xm.c
@@ -469,7 +469,8 @@ static int decode_p_frame(FourXContext *f, const uint8_t 
*buf, int length)
                           bitstream_size);
     if (!f->bitstream_buffer)
         return AVERROR(ENOMEM);
-    f->bbdsp.bswap_buf(f->bitstream_buffer, (const uint32_t *) (buf + extra),
+    memcpy(f->bitstream_buffer, buf + extra, bitstream_size);
+    f->bbdsp.bswap_buf(f->bitstream_buffer, f->bitstream_buffer,
                        bitstream_size / 4);
     init_get_bits(&f->gb, f->bitstream_buffer, 8 * bitstream_size);
 
@@ -813,7 +814,8 @@ static int decode_i_frame(FourXContext *f, const uint8_t 
*buf, int length)
                           prestream_size);
     if (!f->bitstream_buffer)
         return AVERROR(ENOMEM);
-    f->bbdsp.bswap_buf(f->bitstream_buffer, (const uint32_t *) prestream,
+    memcpy(f->bitstream_buffer, prestream, prestream_size);
+    f->bbdsp.bswap_buf(f->bitstream_buffer, f->bitstream_buffer,
                        prestream_size / 4);
     init_get_bits(&f->pre_gb, f->bitstream_buffer, 8 * prestream_size);
 
-- 
2.54.0

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

Reply via email to