Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] Avoid possible integer overflow in yuv420 to rgba64 templates by saturating.
@ 2022-10-26 16:17 Drew Dunne
  2022-11-01 19:05 ` [FFmpeg-devel] [PATCH] sws_scale: Use av_sat_add32 in yuv2rgba64 template Drew Dunne
  0 siblings, 1 reply; 4+ messages in thread
From: Drew Dunne @ 2022-10-26 16:17 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Drew Dunne

---
 libswscale/output.c | 96 ++++++++++++++++++++++-----------------------
 1 file changed, 48 insertions(+), 48 deletions(-)

diff --git a/libswscale/output.c b/libswscale/output.c
index 0e1c1225a0..8c8f62682a 100644
--- a/libswscale/output.c
+++ b/libswscale/output.c
@@ -1109,20 +1109,20 @@ yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter,
         B =                            U * c->yuv2rgb_u2b_coeff;
 
         // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits
-        output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
-        output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
-        output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
+        output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y1), 30) >> 14);
+        output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y1), 30) >> 14);
+        output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y1), 30) >> 14);
         if (eightbytes) {
             output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
-            output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
-            output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
-            output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
+            output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14);
+            output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(  G, Y2), 30) >> 14);
+            output_pixel(&dest[6], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14);
             output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
             dest += 8;
         } else {
-            output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
-            output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
-            output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
+            output_pixel(&dest[3], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14);
+            output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(  G, Y2), 30) >> 14);
+            output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14);
             dest += 6;
         }
     }
@@ -1175,20 +1175,20 @@ yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2],
             A2 += 1 << 13;
         }
 
-        output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
-        output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
-        output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
+        output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y1), 30) >> 14);
+        output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y1), 30) >> 14);
+        output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y1), 30) >> 14);
         if (eightbytes) {
             output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
-            output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
-            output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
-            output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
+            output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14);
+            output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(  G, Y2), 30) >> 14);
+            output_pixel(&dest[6], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14);
             output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
             dest += 8;
         } else {
-            output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
-            output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
-            output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
+            output_pixel(&dest[3], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14);
+            output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(  G, Y2), 30) >> 14);
+            output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14);
             dest += 6;
         }
     }
@@ -1232,20 +1232,20 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0,
             G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
             B =                            U * c->yuv2rgb_u2b_coeff;
 
-            output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
-            output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
-            output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
+            output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y1), 30) >> 14);
+            output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y1), 30) >> 14);
+            output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y1), 30) >> 14);
             if (eightbytes) {
                 output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
-                output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
-                output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
-                output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
+                output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14);
+                output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(  G, Y2), 30) >> 14);
+                output_pixel(&dest[6], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14);
                 output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
                 dest += 8;
             } else {
-                output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
-                output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
-                output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
+                output_pixel(&dest[3], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14);
+                output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(  G, Y2), 30) >> 14);
+                output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14);
                 dest += 6;
             }
         }
@@ -1278,20 +1278,20 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0,
             G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
             B =                            U * c->yuv2rgb_u2b_coeff;
 
-            output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
-            output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
-            output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
+            output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y1), 30) >> 14);
+            output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y1), 30) >> 14);
+            output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y1), 30) >> 14);
             if (eightbytes) {
                 output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
-                output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
-                output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
-                output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
+                output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14);
+                output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(  G, Y2), 30) >> 14);
+                output_pixel(&dest[6], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14);
                 output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
                 dest += 8;
             } else {
-                output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
-                output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
-                output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
+                output_pixel(&dest[3], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14);
+                output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(  G, Y2), 30) >> 14);
+                output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14);
                 dest += 6;
             }
         }
@@ -1351,9 +1351,9 @@ yuv2rgba64_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
         B =                            U * c->yuv2rgb_u2b_coeff;
 
         // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
-        output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
-        output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
-        output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
+        output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y), 30) >> 14);
+        output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y), 30) >> 14);
+        output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y), 30) >> 14);
         if (eightbytes) {
             output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
             dest += 4;
@@ -1404,9 +1404,9 @@ yuv2rgba64_full_2_c_template(SwsContext *c, const int32_t *buf[2],
             A += 1 << 13;
         }
 
-        output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
-        output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
-        output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
+        output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y), 30) >> 14);
+        output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y), 30) >> 14);
+        output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y), 30) >> 14);
         if (eightbytes) {
             output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
             dest += 4;
@@ -1448,9 +1448,9 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0,
             G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
             B =                            U * c->yuv2rgb_u2b_coeff;
 
-            output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
-            output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
-            output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
+            output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y), 30) >> 14);
+            output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y), 30) >> 14);
+            output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y), 30) >> 14);
             if (eightbytes) {
                 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
                 dest += 4;
@@ -1481,9 +1481,9 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0,
             G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
             B =                            U * c->yuv2rgb_u2b_coeff;
 
-            output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
-            output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
-            output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
+            output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y), 30) >> 14);
+            output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y), 30) >> 14);
+            output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y), 30) >> 14);
             if (eightbytes) {
                 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
                 dest += 4;
-- 
2.38.0.135.g90850a2211-goog

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

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [FFmpeg-devel] [PATCH] sws_scale: Use av_sat_add32 in yuv2rgba64 template
  2022-10-26 16:17 [FFmpeg-devel] [PATCH] Avoid possible integer overflow in yuv420 to rgba64 templates by saturating Drew Dunne
@ 2022-11-01 19:05 ` Drew Dunne
  2022-11-01 19:12   ` Drew Dunne
  0 siblings, 1 reply; 4+ messages in thread
From: Drew Dunne @ 2022-11-01 19:05 UTC (permalink / raw)
  To: ffmpeg-devel; +Cc: Drew Dunne

Avoid a possible integer overflow in the yuv2rgba64 templates by using
av_sat_add32 when combing the R, G, B components with Y. On certain
inputs, this addition can overflow to a negative, is then clipped to a
power of two and shifted down 14. This results in a much different value
in the output than had it been saturated instead. I will attach an
example input YUV in a follow up and some images that show the artifacts
resulting from this overflow.

---
 libswscale/output.c | 96 ++++++++++++++++++++++-----------------------
 1 file changed, 48 insertions(+), 48 deletions(-)

diff --git a/libswscale/output.c b/libswscale/output.c
index 0e1c1225a0..8c8f62682a 100644
--- a/libswscale/output.c
+++ b/libswscale/output.c
@@ -1109,20 +1109,20 @@ yuv2rgba64_X_c_template(SwsContext *c, const int16_t *lumFilter,
         B =                            U * c->yuv2rgb_u2b_coeff;
 
         // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits
-        output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
-        output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
-        output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
+        output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y1), 30) >> 14);
+        output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y1), 30) >> 14);
+        output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y1), 30) >> 14);
         if (eightbytes) {
             output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
-            output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
-            output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
-            output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
+            output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14);
+            output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(  G, Y2), 30) >> 14);
+            output_pixel(&dest[6], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14);
             output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
             dest += 8;
         } else {
-            output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
-            output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
-            output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
+            output_pixel(&dest[3], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14);
+            output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(  G, Y2), 30) >> 14);
+            output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14);
             dest += 6;
         }
     }
@@ -1175,20 +1175,20 @@ yuv2rgba64_2_c_template(SwsContext *c, const int32_t *buf[2],
             A2 += 1 << 13;
         }
 
-        output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
-        output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
-        output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
+        output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y1), 30) >> 14);
+        output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y1), 30) >> 14);
+        output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y1), 30) >> 14);
         if (eightbytes) {
             output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
-            output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
-            output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
-            output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
+            output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14);
+            output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(  G, Y2), 30) >> 14);
+            output_pixel(&dest[6], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14);
             output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
             dest += 8;
         } else {
-            output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
-            output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
-            output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
+            output_pixel(&dest[3], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14);
+            output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(  G, Y2), 30) >> 14);
+            output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14);
             dest += 6;
         }
     }
@@ -1232,20 +1232,20 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0,
             G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
             B =                            U * c->yuv2rgb_u2b_coeff;
 
-            output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
-            output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
-            output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
+            output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y1), 30) >> 14);
+            output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y1), 30) >> 14);
+            output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y1), 30) >> 14);
             if (eightbytes) {
                 output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
-                output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
-                output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
-                output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
+                output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14);
+                output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(  G, Y2), 30) >> 14);
+                output_pixel(&dest[6], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14);
                 output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
                 dest += 8;
             } else {
-                output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
-                output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
-                output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
+                output_pixel(&dest[3], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14);
+                output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(  G, Y2), 30) >> 14);
+                output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14);
                 dest += 6;
             }
         }
@@ -1278,20 +1278,20 @@ yuv2rgba64_1_c_template(SwsContext *c, const int32_t *buf0,
             G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
             B =                            U * c->yuv2rgb_u2b_coeff;
 
-            output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
-            output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
-            output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
+            output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y1), 30) >> 14);
+            output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y1), 30) >> 14);
+            output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y1), 30) >> 14);
             if (eightbytes) {
                 output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
-                output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
-                output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
-                output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
+                output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14);
+                output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(  G, Y2), 30) >> 14);
+                output_pixel(&dest[6], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14);
                 output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
                 dest += 8;
             } else {
-                output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
-                output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
-                output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
+                output_pixel(&dest[3], av_clip_uintp2(av_sat_add32(R_B, Y2), 30) >> 14);
+                output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(  G, Y2), 30) >> 14);
+                output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(B_R, Y2), 30) >> 14);
                 dest += 6;
             }
         }
@@ -1351,9 +1351,9 @@ yuv2rgba64_full_X_c_template(SwsContext *c, const int16_t *lumFilter,
         B =                            U * c->yuv2rgb_u2b_coeff;
 
         // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
-        output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
-        output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
-        output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
+        output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y), 30) >> 14);
+        output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y), 30) >> 14);
+        output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y), 30) >> 14);
         if (eightbytes) {
             output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
             dest += 4;
@@ -1404,9 +1404,9 @@ yuv2rgba64_full_2_c_template(SwsContext *c, const int32_t *buf[2],
             A += 1 << 13;
         }
 
-        output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
-        output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
-        output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
+        output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y), 30) >> 14);
+        output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y), 30) >> 14);
+        output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y), 30) >> 14);
         if (eightbytes) {
             output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
             dest += 4;
@@ -1448,9 +1448,9 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0,
             G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
             B =                            U * c->yuv2rgb_u2b_coeff;
 
-            output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
-            output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
-            output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
+            output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y), 30) >> 14);
+            output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y), 30) >> 14);
+            output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y), 30) >> 14);
             if (eightbytes) {
                 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
                 dest += 4;
@@ -1481,9 +1481,9 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const int32_t *buf0,
             G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
             B =                            U * c->yuv2rgb_u2b_coeff;
 
-            output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
-            output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
-            output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
+            output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y), 30) >> 14);
+            output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y), 30) >> 14);
+            output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y), 30) >> 14);
             if (eightbytes) {
                 output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
                 dest += 4;
-- 
2.38.1.273.g43a17bfeac-goog

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

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [FFmpeg-devel] [PATCH] sws_scale: Use av_sat_add32 in yuv2rgba64 template
  2022-11-01 19:05 ` [FFmpeg-devel] [PATCH] sws_scale: Use av_sat_add32 in yuv2rgba64 template Drew Dunne
@ 2022-11-01 19:12   ` Drew Dunne
  2022-11-02 19:05     ` Michael Niedermayer
  0 siblings, 1 reply; 4+ messages in thread
From: Drew Dunne @ 2022-11-01 19:12 UTC (permalink / raw)
  To: ffmpeg-devel

[-- Attachment #1: Type: text/plain, Size: 13050 bytes --]

This was supposed to be in reply to a previous patch I sent, but I changed
the git message so maybe it didn't like that. Sorry about that.

Attached is the example YUVA file that can reproduce the overflow bug.

The command to reproduce is:

./ffmpeg \
  -f rawvideo -video_size 66x64 -pixel_format yuva420p10le \
  -i overflow_input_w66h64.yuva420p10le \
  -filter_complex
"scale=flags=bicubic+full_chroma_int+full_chroma_inp+bitexact+accurate_rnd:in_color_matrix=bt2020:out_color_matrix=bt2020:in_range=full:out_range=full,format=rgba64[out]"
\
  -f rawvideo -codec:v:0 rawvideo -pixel_format rgba64 -map '[out]' \
  -y overflow_w66h64.rgba64

I've attached a PNG of the resulting overflowed image, there is a clear
discoloration in the bottom left corner that's orange instead of pink.

I've also attached a PNG of the image using the patch to correct this
overflow.



On Tue, Nov 1, 2022 at 3:05 PM Drew Dunne <asdunne@google.com> wrote:

> Avoid a possible integer overflow in the yuv2rgba64 templates by using
> av_sat_add32 when combing the R, G, B components with Y. On certain
> inputs, this addition can overflow to a negative, is then clipped to a
> power of two and shifted down 14. This results in a much different value
> in the output than had it been saturated instead. I will attach an
> example input YUV in a follow up and some images that show the artifacts
> resulting from this overflow.
>
> ---
>  libswscale/output.c | 96 ++++++++++++++++++++++-----------------------
>  1 file changed, 48 insertions(+), 48 deletions(-)
>
> diff --git a/libswscale/output.c b/libswscale/output.c
> index 0e1c1225a0..8c8f62682a 100644
> --- a/libswscale/output.c
> +++ b/libswscale/output.c
> @@ -1109,20 +1109,20 @@ yuv2rgba64_X_c_template(SwsContext *c, const
> int16_t *lumFilter,
>          B =                            U * c->yuv2rgb_u2b_coeff;
>
>          // 8 bits: 30 - 22 = 8 bits, 16 bits: 30 bits - 14 = 16 bits
> -        output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
> -        output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
> -        output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
> +        output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y1), 30)
> >> 14);
> +        output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y1), 30)
> >> 14);
> +        output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y1), 30)
> >> 14);
>          if (eightbytes) {
>              output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
> -            output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
> -            output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
> -            output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
> +            output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(R_B, Y2),
> 30) >> 14);
> +            output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(  G, Y2),
> 30) >> 14);
> +            output_pixel(&dest[6], av_clip_uintp2(av_sat_add32(B_R, Y2),
> 30) >> 14);
>              output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
>              dest += 8;
>          } else {
> -            output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
> -            output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
> -            output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
> +            output_pixel(&dest[3], av_clip_uintp2(av_sat_add32(R_B, Y2),
> 30) >> 14);
> +            output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(  G, Y2),
> 30) >> 14);
> +            output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(B_R, Y2),
> 30) >> 14);
>              dest += 6;
>          }
>      }
> @@ -1175,20 +1175,20 @@ yuv2rgba64_2_c_template(SwsContext *c, const
> int32_t *buf[2],
>              A2 += 1 << 13;
>          }
>
> -        output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
> -        output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
> -        output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
> +        output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y1), 30)
> >> 14);
> +        output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y1), 30)
> >> 14);
> +        output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y1), 30)
> >> 14);
>          if (eightbytes) {
>              output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >> 14);
> -            output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >> 14);
> -            output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >> 14);
> -            output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >> 14);
> +            output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(R_B, Y2),
> 30) >> 14);
> +            output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(  G, Y2),
> 30) >> 14);
> +            output_pixel(&dest[6], av_clip_uintp2(av_sat_add32(B_R, Y2),
> 30) >> 14);
>              output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >> 14);
>              dest += 8;
>          } else {
> -            output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14);
> -            output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >> 14);
> -            output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14);
> +            output_pixel(&dest[3], av_clip_uintp2(av_sat_add32(R_B, Y2),
> 30) >> 14);
> +            output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(  G, Y2),
> 30) >> 14);
> +            output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(B_R, Y2),
> 30) >> 14);
>              dest += 6;
>          }
>      }
> @@ -1232,20 +1232,20 @@ yuv2rgba64_1_c_template(SwsContext *c, const
> int32_t *buf0,
>              G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
>              B =                            U * c->yuv2rgb_u2b_coeff;
>
> -            output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
> -            output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
> -            output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
> +            output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y1),
> 30) >> 14);
> +            output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y1),
> 30) >> 14);
> +            output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y1),
> 30) >> 14);
>              if (eightbytes) {
>                  output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >>
> 14);
> -                output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >>
> 14);
> -                output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >>
> 14);
> -                output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >>
> 14);
> +                output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(R_B,
> Y2), 30) >> 14);
> +                output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(  G,
> Y2), 30) >> 14);
> +                output_pixel(&dest[6], av_clip_uintp2(av_sat_add32(B_R,
> Y2), 30) >> 14);
>                  output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >>
> 14);
>                  dest += 8;
>              } else {
> -                output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >>
> 14);
> -                output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >>
> 14);
> -                output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >>
> 14);
> +                output_pixel(&dest[3], av_clip_uintp2(av_sat_add32(R_B,
> Y2), 30) >> 14);
> +                output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(  G,
> Y2), 30) >> 14);
> +                output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(B_R,
> Y2), 30) >> 14);
>                  dest += 6;
>              }
>          }
> @@ -1278,20 +1278,20 @@ yuv2rgba64_1_c_template(SwsContext *c, const
> int32_t *buf0,
>              G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
>              B =                            U * c->yuv2rgb_u2b_coeff;
>
> -            output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14);
> -            output_pixel(&dest[1], av_clip_uintp2(  G + Y1, 30) >> 14);
> -            output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14);
> +            output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y1),
> 30) >> 14);
> +            output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y1),
> 30) >> 14);
> +            output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y1),
> 30) >> 14);
>              if (eightbytes) {
>                  output_pixel(&dest[3], av_clip_uintp2(A1      , 30) >>
> 14);
> -                output_pixel(&dest[4], av_clip_uintp2(R_B + Y2, 30) >>
> 14);
> -                output_pixel(&dest[5], av_clip_uintp2(  G + Y2, 30) >>
> 14);
> -                output_pixel(&dest[6], av_clip_uintp2(B_R + Y2, 30) >>
> 14);
> +                output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(R_B,
> Y2), 30) >> 14);
> +                output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(  G,
> Y2), 30) >> 14);
> +                output_pixel(&dest[6], av_clip_uintp2(av_sat_add32(B_R,
> Y2), 30) >> 14);
>                  output_pixel(&dest[7], av_clip_uintp2(A2      , 30) >>
> 14);
>                  dest += 8;
>              } else {
> -                output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >>
> 14);
> -                output_pixel(&dest[4], av_clip_uintp2(  G + Y2, 30) >>
> 14);
> -                output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >>
> 14);
> +                output_pixel(&dest[3], av_clip_uintp2(av_sat_add32(R_B,
> Y2), 30) >> 14);
> +                output_pixel(&dest[4], av_clip_uintp2(av_sat_add32(  G,
> Y2), 30) >> 14);
> +                output_pixel(&dest[5], av_clip_uintp2(av_sat_add32(B_R,
> Y2), 30) >> 14);
>                  dest += 6;
>              }
>          }
> @@ -1351,9 +1351,9 @@ yuv2rgba64_full_X_c_template(SwsContext *c, const
> int16_t *lumFilter,
>          B =                            U * c->yuv2rgb_u2b_coeff;
>
>          // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit
> -        output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
> -        output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
> -        output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
> +        output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y), 30)
> >> 14);
> +        output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y), 30)
> >> 14);
> +        output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y), 30)
> >> 14);
>          if (eightbytes) {
>              output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
>              dest += 4;
> @@ -1404,9 +1404,9 @@ yuv2rgba64_full_2_c_template(SwsContext *c, const
> int32_t *buf[2],
>              A += 1 << 13;
>          }
>
> -        output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
> -        output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
> -        output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
> +        output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y), 30)
> >> 14);
> +        output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y), 30)
> >> 14);
> +        output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y), 30)
> >> 14);
>          if (eightbytes) {
>              output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
>              dest += 4;
> @@ -1448,9 +1448,9 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const
> int32_t *buf0,
>              G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
>              B =                            U * c->yuv2rgb_u2b_coeff;
>
> -            output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
> -            output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
> -            output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
> +            output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y),
> 30) >> 14);
> +            output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y),
> 30) >> 14);
> +            output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y),
> 30) >> 14);
>              if (eightbytes) {
>                  output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
>                  dest += 4;
> @@ -1481,9 +1481,9 @@ yuv2rgba64_full_1_c_template(SwsContext *c, const
> int32_t *buf0,
>              G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff;
>              B =                            U * c->yuv2rgb_u2b_coeff;
>
> -            output_pixel(&dest[0], av_clip_uintp2(R_B + Y, 30) >> 14);
> -            output_pixel(&dest[1], av_clip_uintp2(  G + Y, 30) >> 14);
> -            output_pixel(&dest[2], av_clip_uintp2(B_R + Y, 30) >> 14);
> +            output_pixel(&dest[0], av_clip_uintp2(av_sat_add32(R_B, Y),
> 30) >> 14);
> +            output_pixel(&dest[1], av_clip_uintp2(av_sat_add32(  G, Y),
> 30) >> 14);
> +            output_pixel(&dest[2], av_clip_uintp2(av_sat_add32(B_R, Y),
> 30) >> 14);
>              if (eightbytes) {
>                  output_pixel(&dest[3], av_clip_uintp2(A, 30) >> 14);
>                  dest += 4;
> --
> 2.38.1.273.g43a17bfeac-goog
>
>

-- 
Drew Dunne
asdunne@google.com

[-- Attachment #2: overflow_input_w66h64.yuva420p10le --]
[-- Type: application/octet-stream, Size: 21120 bytes --]

[-- Attachment #3: overflow.png --]
[-- Type: image/png, Size: 43399 bytes --]

[-- Attachment #4: patched.png --]
[-- Type: image/png, Size: 37535 bytes --]

[-- Attachment #5: Type: text/plain, Size: 251 bytes --]

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

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [FFmpeg-devel] [PATCH] sws_scale: Use av_sat_add32 in yuv2rgba64 template
  2022-11-01 19:12   ` Drew Dunne
@ 2022-11-02 19:05     ` Michael Niedermayer
  0 siblings, 0 replies; 4+ messages in thread
From: Michael Niedermayer @ 2022-11-02 19:05 UTC (permalink / raw)
  To: FFmpeg development discussions and patches


[-- Attachment #1.1: Type: text/plain, Size: 1294 bytes --]

dooa    2On Tue, Nov 01, 2022 at 03:12:08PM -0400, Drew Dunne wrote:
> This was supposed to be in reply to a previous patch I sent, but I changed
> the git message so maybe it didn't like that. Sorry about that.
> 
> Attached is the example YUVA file that can reproduce the overflow bug.
> 
> The command to reproduce is:
> 
> ./ffmpeg \
>   -f rawvideo -video_size 66x64 -pixel_format yuva420p10le \
>   -i overflow_input_w66h64.yuva420p10le \
>   -filter_complex
> "scale=flags=bicubic+full_chroma_int+full_chroma_inp+bitexact+accurate_rnd:in_color_matrix=bt2020:out_color_matrix=bt2020:in_range=full:out_range=full,format=rgba64[out]"
> \
>   -f rawvideo -codec:v:0 rawvideo -pixel_format rgba64 -map '[out]' \
>   -y overflow_w66h64.rgba64
> 
> I've attached a PNG of the resulting overflowed image, there is a clear
> discoloration in the bottom left corner that's orange instead of pink.
> 
> I've also attached a PNG of the image using the patch to correct this
> overflow.

I dont like the multi cliping per sample, ill post a different solution

thx

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Elect your leaders based on what they did after the last election, not
based on what they say before an election.


[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

[-- Attachment #2: Type: text/plain, Size: 251 bytes --]

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

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-11-02 19:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-26 16:17 [FFmpeg-devel] [PATCH] Avoid possible integer overflow in yuv420 to rgba64 templates by saturating Drew Dunne
2022-11-01 19:05 ` [FFmpeg-devel] [PATCH] sws_scale: Use av_sat_add32 in yuv2rgba64 template Drew Dunne
2022-11-01 19:12   ` Drew Dunne
2022-11-02 19:05     ` Michael Niedermayer

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git