[FFmpeg-devel] [PATCH] avcodec/dxvenc: Use proper alignment, write endian-independent output

Andreas Rheinhardt andreas.rheinhardt at outlook.com
Tue Feb 27 01:50:17 EET 2024


Fixes the dxv3enc-dxt1 FATE test with UBSan.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
---
I have not actually tested whether the output is actually wrong
on BE systems. Would be nice if someone could.

 libavcodec/dxvenc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
index 1ce2b1d014..3f28fb696a 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -149,7 +149,7 @@ typedef struct DXVEncContext {
         } else {                                                              \
             op = 0;                                                           \
         }                                                                     \
-        *value |= (op << (state * 2));                                        \
+        AV_WL32(value, AV_RL32(value) | (op << (state * 2)));                 \
         state++;                                                              \
     } while (0)
 
@@ -157,7 +157,7 @@ static int dxv_compress_dxt1(AVCodecContext *avctx)
 {
     DXVEncContext *ctx = avctx->priv_data;
     PutByteContext *pbc = &ctx->pbc;
-    uint32_t *value;
+    void *value;
     uint32_t color, lut, idx, color_idx, lut_idx, prev_pos, state = 16, pos = 2, op = 0;
 
     ht_init(ctx->color_lookback_ht);
-- 
2.40.1



More information about the ffmpeg-devel mailing list