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

Andreas Rheinhardt git at videolan.org
Wed Feb 28 00:05:44 EET 2024


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Tue Feb 27 00:40:32 2024 +0100| [0c204ce9f6b6d1ac3c0ed399bb8b7aa8768d05d9] | committer: Andreas Rheinhardt

avcodec/dxvenc: Use proper alignment, write endian-independent output

Fixes the dxv3enc-dxt1 FATE test with UBSan and on big-endian
hardware.

Reviewed-by: James Almer <jamrial at gmail.com>
Tested-by: Sean McGovern <gseanmcg at gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0c204ce9f6b6d1ac3c0ed399bb8b7aa8768d05d9
---

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

diff --git a/libavcodec/dxvenc.c b/libavcodec/dxvenc.c
index 1ce2b1d014..91f4ba7619 100644
--- a/libavcodec/dxvenc.c
+++ b/libavcodec/dxvenc.c
@@ -134,7 +134,7 @@ typedef struct DXVEncContext {
             if (bytestream2_get_bytes_left_p(pbc) < 4) {                      \
                 return AVERROR_INVALIDDATA;                                   \
             }                                                                 \
-            value = (uint32_t*)pbc->buffer;                                   \
+            value = pbc->buffer;                                              \
             bytestream2_put_le32(pbc, 0);                                     \
             state = 0;                                                        \
         }                                                                     \
@@ -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);



More information about the ffmpeg-cvslog mailing list