[vlc-devel] [PATCH] copy: do not copy more than the destination pitch on split planes

Steve Lhomme robux4 at ycbcr.xyz
Mon Jul 23 14:13:14 CEST 2018


---
 modules/video_chroma/copy.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/modules/video_chroma/copy.c b/modules/video_chroma/copy.c
index 179a792bb2..d4fa0311fe 100644
--- a/modules/video_chroma/copy.c
+++ b/modules/video_chroma/copy.c
@@ -529,7 +529,8 @@ static void SSE_SplitPlanes(uint8_t *dstu, size_t dstu_pitch,
                             uint8_t *cache, size_t cache_size,
                             unsigned height, uint8_t pixel_size, int bitshift)
 {
-    const unsigned w16 = (src_pitch+15) & ~15;
+    size_t cp_pitch = __MIN(__MIN(src_pitch / 2, dstu_pitch), dstv_pitch);
+    const unsigned w16 = (cp_pitch+15) & ~15;
     const unsigned hstep = cache_size / w16;
     assert(hstep > 0);
 
@@ -676,8 +677,9 @@ void Copy420_SP_to_SP(picture_t *dst, const uint8_t *src[static 2],
 }
 
 #define SPLIT_PLANES(type, pitch_den) do { \
+    size_t cp_pitch = __MIN(__MIN(src_pitch / pitch_den, dstu_pitch), dstv_pitch); \
     for (unsigned y = 0; y < height; y++) { \
-        for (unsigned x = 0; x < src_pitch / pitch_den; x++) { \
+        for (unsigned x = 0; x < cp_pitch; x++) { \
             ((type *) dstu)[x] = ((const type *) src)[2*x+0]; \
             ((type *) dstv)[x] = ((const type *) src)[2*x+1]; \
         } \
@@ -688,8 +690,9 @@ void Copy420_SP_to_SP(picture_t *dst, const uint8_t *src[static 2],
 } while(0)
 
 #define SPLIT_PLANES_SHIFTR(type, pitch_den, bitshift) do { \
+    size_t cp_pitch = __MIN(__MIN(src_pitch / pitch_den, dstu_pitch), dstv_pitch); \
     for (unsigned y = 0; y < height; y++) { \
-        for (unsigned x = 0; x < src_pitch / pitch_den; x++) { \
+        for (unsigned x = 0; x < cp_pitch; x++) { \
             ((type *) dstu)[x] = (((const type *) src)[2*x+0]) >> (bitshift); \
             ((type *) dstv)[x] = (((const type *) src)[2*x+1]) >> (bitshift); \
         } \
@@ -700,8 +703,9 @@ void Copy420_SP_to_SP(picture_t *dst, const uint8_t *src[static 2],
 } while(0)
 
 #define SPLIT_PLANES_SHIFTL(type, pitch_den, bitshift) do { \
+    size_t cp_pitch = __MIN(__MIN(src_pitch / pitch_den, dstu_pitch), dstv_pitch); \
     for (unsigned y = 0; y < height; y++) { \
-        for (unsigned x = 0; x < src_pitch / pitch_den; x++) { \
+        for (unsigned x = 0; x < cp_pitch; x++) { \
             ((type *) dstu)[x] = (((const type *) src)[2*x+0]) << (bitshift); \
             ((type *) dstv)[x] = (((const type *) src)[2*x+1]) << (bitshift); \
         } \
-- 
2.17.0



More information about the vlc-devel mailing list