palette_delta_encoding: clamp y and u colors

BUG=aomedia:812

Change-Id: I635d620fc6d350391ecb7885cc119eaef0af39bc
diff --git a/av1/decoder/decodemv.c b/av1/decoder/decodemv.c
index 81e1e06..e896796 100644
--- a/av1/decoder/decodemv.c
+++ b/av1/decoder/decodemv.c
@@ -716,9 +716,11 @@
       int bits = min_bits + aom_read_literal(r, 2, ACCT_STR);
       int range = (1 << bit_depth) - pmi->palette_colors[idx - 1] - 1;
       for (; idx < n; ++idx) {
+        assert(range >= 0);
         const int delta = aom_read_literal(r, bits, ACCT_STR) + 1;
-        pmi->palette_colors[idx] = pmi->palette_colors[idx - 1] + delta;
-        range -= delta;
+        pmi->palette_colors[idx] = clamp(pmi->palette_colors[idx - 1] + delta,
+                                         0, (1 << bit_depth) - 1);
+        range -= (pmi->palette_colors[idx] - pmi->palette_colors[idx - 1]);
         bits = AOMMIN(bits, av1_ceil_log2(range));
       }
     }
@@ -743,9 +745,11 @@
       int bits = min_bits + aom_read_literal(r, 2, ACCT_STR);
       int range = (1 << bit_depth) - pmi->palette_colors[idx - 1];
       for (; idx < PALETTE_MAX_SIZE + n; ++idx) {
+        assert(range >= 0);
         const int delta = aom_read_literal(r, bits, ACCT_STR);
-        pmi->palette_colors[idx] = pmi->palette_colors[idx - 1] + delta;
-        range -= delta;
+        pmi->palette_colors[idx] = clamp(pmi->palette_colors[idx - 1] + delta,
+                                         0, (1 << bit_depth) - 1);
+        range -= (pmi->palette_colors[idx] - pmi->palette_colors[idx - 1]);
         bits = AOMMIN(bits, av1_ceil_log2(range));
       }
     }