]> granicus.if.org Git - xz/commitdiff
Remove two redundant validity checks from the LZMA decoder.
authorLasse Collin <lasse.collin@tukaani.org>
Thu, 28 Feb 2008 08:24:31 +0000 (10:24 +0200)
committerLasse Collin <lasse.collin@tukaani.org>
Thu, 28 Feb 2008 08:24:31 +0000 (10:24 +0200)
These are already checked elsewhere, so omitting these
gives (very) tiny speed up.

src/liblzma/lzma/lzma_decoder.c

index 04fae74ea32c77dd5b9d879e7be929ed9ac4d529..9e1226f76e8b148efdd7f6f937cb41dca1b7f1fe 100644 (file)
@@ -541,22 +541,12 @@ decode_real(lzma_coder *restrict coder, const uint8_t *restrict in,
                                if_bit_0(coder->is_rep0_long[state][pos_state]) {
                                        update_bit_0(coder->is_rep0_long[state][pos_state]);
 
-                                       // Repeating exactly one byte. For
-                                       // simplicity, it is done here inline
-                                       // instead of at the end of the main
-                                       // loop.
-
                                        update_short_rep(state);
 
-                                       // Security/sanity checks. See the end
-                                       // of the main loop for explanation
-                                       // of these.
-                                       if ((rep0 >= coder->lz.pos && !coder->lz.is_full)
-                                                       || in_pos_local > in_size)
-                                               return true;
-
-                                       // Repeat one byte and start a new
-                                       // decoding loop.
+                                       // Repeat exactly one byte and start a new decoding loop.
+                                       // Note that rep0 is known to have a safe value, thus we
+                                       // don't need to check if we are wrapping the dictionary
+                                       // when it isn't full yet.
                                        coder->lz.dict[coder->lz.pos]
                                                        = lz_get_byte(coder->lz, rep0);
                                        ++coder->lz.pos;
@@ -622,11 +612,6 @@ decode_real(lzma_coder *restrict coder, const uint8_t *restrict in,
                now_pos += len;
                has_produced_output = true;
 
-               // Validate the buffer position to avoid buffer overflows
-               // on corrupted input data.
-               if (in_pos_local > in_size)
-                       return true;
-
                // Repeat len bytes from distance of rep0.
                if (!lzma_lz_out_repeat(&coder->lz, rep0, len))
                        return true;