ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinha...@outlook.com> | 
Wed Mar  5 14:19:13 2025 +0100| [72cff47be73f6e9c154066131d13515101574b29] | 
committer: Andreas Rheinhardt

avcodec/exr: Fix potential effective-type violation

Storing the values via a union of an uint32_t and a float makes
said union the effective type of the destination. This means that
it may only be read via such a union which is of course not what
our users do/expect. So store the values via AV_WN32A instead
which disables effective type analysis (for compilers that perform it).

This also fixes a -Wdeclaration-after-statement warning
introduced in 0e917389fe73c932049635d947bba076f1709589.

Reviewed-by: Michael Niedermayer <mich...@niedermayer.cc>
Signed-off-by: Andreas Rheinhardt <andreas.rheinha...@outlook.com>

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

 libavcodec/exr.c | 29 ++++++++++++-----------------
 1 file changed, 12 insertions(+), 17 deletions(-)

diff --git a/libavcodec/exr.c b/libavcodec/exr.c
index d2871e34b2..b25e9ef397 100644
--- a/libavcodec/exr.c
+++ b/libavcodec/exr.c
@@ -1383,34 +1383,29 @@ static int decode_block(AVCodecContext *avctx, void 
*tdata,
                     s->compression == EXR_DWAA ||
                     s->compression == EXR_DWAB) {
                     // 32-bit
-                    union av_intfloat32 *ptr_x;
+                    uint8_t *ptr_x = ptr;
 
                     src = channel_buffer[c];
-                    ptr_x = (union av_intfloat32 *)ptr;
 
                     // Zero out the start if xmin is not 0
                     memset(ptr_x, 0, bxmin);
-                    ptr_x += window_xoffset;
+                    ptr_x += 4 * window_xoffset;
 
-                    union av_intfloat32 t;
                     if (trc_func && c < 3) {
-                        for (x = 0; x < xsize; x++) {
-                            t.i = bytestream_get_le32(&src);
-                            t.f = trc_func(t.f);
-                            *ptr_x++ = t;
+                        for (int x = 0; x < xsize; x++, ptr_x += 4) {
+                            float f = av_int2float(bytestream_get_le32(&src));
+                            AV_WN32A(ptr_x, av_float2int(trc_func(f)));
                         }
                     } else if (one_gamma != 1.f) {
-                        for (x = 0; x < xsize; x++) {
-                            t.i = bytestream_get_le32(&src);
-                            if (t.f > 0.0f && c < 3)  /* avoid negative values 
*/
-                                t.f = powf(t.f, one_gamma);
-                            *ptr_x++ = t;
+                        for (int x = 0; x < xsize; x++, ptr_x += 4) {
+                            float f = av_int2float(bytestream_get_le32(&src));
+                            if (f > 0.0f && c < 3)  /* avoid negative values */
+                                f = powf(f, one_gamma);
+                            AV_WN32A(ptr_x, av_float2int(f));
                         }
                     } else {
-                        for (x = 0; x < xsize; x++) {
-                            t.i = bytestream_get_le32(&src);
-                            *ptr_x++ = t;
-                        }
+                        for (int x = 0; x < xsize; x++, ptr_x += 4)
+                            AV_WN32A(ptr_x, bytestream_get_le32(&src));
                     }
                     memset(ptr_x, 0, axmax);
                 } else if (s->pixel_type == EXR_HALF) {

_______________________________________________
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to