Bug 1242904 - Adjust calculation of ringbuffer_end_minus_copy_length in BrotliDecompressStreaming. r=mcmanus, a=sylvestre
authorFrédéric Wang <fred.wang@free.fr>
Thu, 25 Feb 2016 12:35:18 +0100
changeset 313189 4a5d8ade4e3ebfa28287430ec8bb139efa570695
parent 313188 7190c35c9e14fc0e7f642e26ef1e8aa4becd8983
child 313190 80ce3f1ffe03de3e0cd64d14531d4c4aa531d03f
push id1040
push userraliiev@mozilla.com
push dateMon, 29 Feb 2016 17:11:22 +0000
treeherdermozilla-release@8c3167321162 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmcmanus, sylvestre
bugs1242904
milestone45.0
Bug 1242904 - Adjust calculation of ringbuffer_end_minus_copy_length in BrotliDecompressStreaming. r=mcmanus, a=sylvestre
modules/brotli/dec/decode.c
--- a/modules/brotli/dec/decode.c
+++ b/modules/brotli/dec/decode.c
@@ -1534,16 +1534,19 @@ postReadDistance:
             break;
           }
         } else {
           const uint8_t *ringbuffer_end_minus_copy_length =
               s->ringbuffer_end - i;
           copy_src = &s->ringbuffer[(pos - s->distance_code) &
                                     s->ringbuffer_mask];
           copy_dst = &s->ringbuffer[pos];
+          if (PREDICT_FALSE(s->ringbuffer_end < (const uint8_t*)0 + i)) {
+            ringbuffer_end_minus_copy_length = 0;
+          }
           /* update the recent distances cache */
           s->dist_rb[s->dist_rb_idx & 3] = s->distance_code;
           ++s->dist_rb_idx;
           s->meta_block_remaining_len -= i;
           if (PREDICT_FALSE(s->meta_block_remaining_len < 0)) {
             BROTLI_LOG(("Invalid backward reference. pos: %d distance: %d "
                    "len: %d bytes left: %d\n", pos, s->distance_code, i,
                    s->meta_block_remaining_len));