diff --git a/libavcodec/xan.c b/libavcodec/xan.c
index 27583522f9d9c1164757df484f9501ec47372b9a..41925aa346f1adc0d4cb7834c1ed6b94bf2f78c8 100644
--- a/libavcodec/xan.c
+++ b/libavcodec/xan.c
@@ -249,6 +249,12 @@ static inline void xan_wc3_copy_pixel_run(XanContext *s, AVFrame *frame,
     curframe_x = x;
     prevframe_index = (y + motion_y) * stride + x + motion_x;
     prevframe_x = x + motion_x;
+
+    if (prev_palette_plane == palette_plane && FFABS(curframe_index - prevframe_index) < pixel_count) {
+         avpriv_request_sample(s->avctx, "Overlapping copy\n");
+         return ;
+    }
+
     while (pixel_count &&
            curframe_index  < s->frame_size &&
            prevframe_index < s->frame_size) {