Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 1 | /* |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 2 | * LZ4 - Fast LZ compression algorithm |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 3 | * Copyright (C) 2011 - 2016, Yann Collet. |
| 4 | * BSD 2 - Clause License (http://www.opensource.org/licenses/bsd - license.php) |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are |
| 7 | * met: |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 8 | * * Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * * Redistributions in binary form must reproduce the above |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 11 | * copyright notice, this list of conditions and the following disclaimer |
| 12 | * in the documentation and/or other materials provided with the |
| 13 | * distribution. |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 15 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 16 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 17 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 18 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 19 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 20 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 25 | * You can contact the author at : |
| 26 | * - LZ4 homepage : http://www.lz4.org |
| 27 | * - LZ4 source repository : https://github.com/lz4/lz4 |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 28 | * |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 29 | * Changed for kernel usage by: |
| 30 | * Sven Schmidt <4sschmid@informatik.uni-hamburg.de> |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 31 | */ |
| 32 | |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 33 | /*-************************************ |
| 34 | * Dependencies |
| 35 | **************************************/ |
| 36 | #include <linux/lz4.h> |
| 37 | #include "lz4defs.h" |
| 38 | #include <linux/init.h> |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 39 | #include <linux/module.h> |
| 40 | #include <linux/kernel.h> |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 41 | #include <asm/unaligned.h> |
| 42 | |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 43 | /*-***************************** |
| 44 | * Decompression functions |
| 45 | *******************************/ |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 46 | |
| 47 | #define DEBUGLOG(l, ...) {} /* disabled */ |
| 48 | |
| 49 | #ifndef assert |
| 50 | #define assert(condition) ((void)0) |
| 51 | #endif |
| 52 | |
| 53 | /* |
| 54 | * LZ4_decompress_generic() : |
| 55 | * This generic decompression function covers all use cases. |
| 56 | * It shall be instantiated several times, using different sets of directives. |
| 57 | * Note that it is important for performance that this function really get inlined, |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 58 | * in order to remove useless branches during compilation optimization. |
| 59 | */ |
| 60 | static FORCE_INLINE int LZ4_decompress_generic( |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 61 | const char * const src, |
| 62 | char * const dst, |
| 63 | int srcSize, |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 64 | /* |
| 65 | * If endOnInput == endOnInputSize, |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 66 | * this value is `dstCapacity` |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 67 | */ |
| 68 | int outputSize, |
| 69 | /* endOnOutputSize, endOnInputSize */ |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 70 | endCondition_directive endOnInput, |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 71 | /* full, partial */ |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 72 | earlyEnd_directive partialDecoding, |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 73 | /* noDict, withPrefix64k, usingExtDict */ |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 74 | dict_directive dict, |
| 75 | /* always <= dst, == dst when no prefix */ |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 76 | const BYTE * const lowPrefix, |
| 77 | /* only if dict == usingExtDict */ |
| 78 | const BYTE * const dictStart, |
| 79 | /* note : = 0 if noDict */ |
| 80 | const size_t dictSize |
| 81 | ) |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 82 | { |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 83 | const BYTE *ip = (const BYTE *) src; |
| 84 | const BYTE * const iend = ip + srcSize; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 85 | |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 86 | BYTE *op = (BYTE *) dst; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 87 | BYTE * const oend = op + outputSize; |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 88 | BYTE *cpy; |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 89 | |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 90 | const BYTE * const dictEnd = (const BYTE *)dictStart + dictSize; |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 91 | static const unsigned int inc32table[8] = {0, 1, 2, 1, 0, 4, 4, 4}; |
| 92 | static const int dec64table[8] = {0, 0, 0, -1, -4, 1, 2, 3}; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 93 | |
| 94 | const int safeDecode = (endOnInput == endOnInputSize); |
| 95 | const int checkOffset = ((safeDecode) && (dictSize < (int)(64 * KB))); |
| 96 | |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 97 | /* Set up the "end" pointers for the shortcut. */ |
| 98 | const BYTE *const shortiend = iend - |
| 99 | (endOnInput ? 14 : 8) /*maxLL*/ - 2 /*offset*/; |
| 100 | const BYTE *const shortoend = oend - |
| 101 | (endOnInput ? 14 : 8) /*maxLL*/ - 18 /*maxML*/; |
| 102 | |
| 103 | DEBUGLOG(5, "%s (srcSize:%i, dstSize:%i)", __func__, |
| 104 | srcSize, outputSize); |
| 105 | |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 106 | /* Special cases */ |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 107 | assert(lowPrefix <= op); |
| 108 | assert(src != NULL); |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 109 | |
| 110 | /* Empty output buffer */ |
| 111 | if ((endOnInput) && (unlikely(outputSize == 0))) |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 112 | return ((srcSize == 1) && (*ip == 0)) ? 0 : -1; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 113 | |
| 114 | if ((!endOnInput) && (unlikely(outputSize == 0))) |
| 115 | return (*ip == 0 ? 1 : -1); |
| 116 | |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 117 | if ((endOnInput) && unlikely(srcSize == 0)) |
| 118 | return -1; |
| 119 | |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 120 | /* Main Loop : decode sequences */ |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 121 | while (1) { |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 122 | size_t length; |
| 123 | const BYTE *match; |
| 124 | size_t offset; |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 125 | |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 126 | /* get literal length */ |
| 127 | unsigned int const token = *ip++; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 128 | length = token>>ML_BITS; |
| 129 | |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 130 | /* ip < iend before the increment */ |
| 131 | assert(!endOnInput || ip <= iend); |
| 132 | |
| 133 | /* |
| 134 | * A two-stage shortcut for the most common case: |
| 135 | * 1) If the literal length is 0..14, and there is enough |
| 136 | * space, enter the shortcut and copy 16 bytes on behalf |
| 137 | * of the literals (in the fast mode, only 8 bytes can be |
| 138 | * safely copied this way). |
| 139 | * 2) Further if the match length is 4..18, copy 18 bytes |
| 140 | * in a similar manner; but we ensure that there's enough |
| 141 | * space in the output for those 18 bytes earlier, upon |
| 142 | * entering the shortcut (in other words, there is a |
| 143 | * combined check for both stages). |
| 144 | */ |
| 145 | if ((endOnInput ? length != RUN_MASK : length <= 8) |
| 146 | /* |
| 147 | * strictly "less than" on input, to re-enter |
| 148 | * the loop with at least one byte |
| 149 | */ |
| 150 | && likely((endOnInput ? ip < shortiend : 1) & |
| 151 | (op <= shortoend))) { |
| 152 | /* Copy the literals */ |
| 153 | memcpy(op, ip, endOnInput ? 16 : 8); |
| 154 | op += length; ip += length; |
| 155 | |
| 156 | /* |
| 157 | * The second stage: |
| 158 | * prepare for match copying, decode full info. |
| 159 | * If it doesn't work out, the info won't be wasted. |
| 160 | */ |
| 161 | length = token & ML_MASK; /* match length */ |
| 162 | offset = LZ4_readLE16(ip); |
| 163 | ip += 2; |
| 164 | match = op - offset; |
| 165 | assert(match <= op); /* check overflow */ |
| 166 | |
| 167 | /* Do not deal with overlapping matches. */ |
| 168 | if ((length != ML_MASK) && |
| 169 | (offset >= 8) && |
| 170 | (dict == withPrefix64k || match >= lowPrefix)) { |
| 171 | /* Copy the match. */ |
| 172 | memcpy(op + 0, match + 0, 8); |
| 173 | memcpy(op + 8, match + 8, 8); |
| 174 | memcpy(op + 16, match + 16, 2); |
| 175 | op += length + MINMATCH; |
| 176 | /* Both stages worked, load the next token. */ |
| 177 | continue; |
| 178 | } |
| 179 | |
| 180 | /* |
| 181 | * The second stage didn't work out, but the info |
| 182 | * is ready. Propel it right to the point of match |
| 183 | * copying. |
| 184 | */ |
| 185 | goto _copy_match; |
| 186 | } |
| 187 | |
| 188 | /* decode literal length */ |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 189 | if (length == RUN_MASK) { |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 190 | unsigned int s; |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 191 | |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 192 | if (unlikely(endOnInput ? ip >= iend - RUN_MASK : 0)) { |
| 193 | /* overflow detection */ |
| 194 | goto _output_error; |
| 195 | } |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 196 | do { |
| 197 | s = *ip++; |
| 198 | length += s; |
| 199 | } while (likely(endOnInput |
| 200 | ? ip < iend - RUN_MASK |
| 201 | : 1) & (s == 255)); |
| 202 | |
| 203 | if ((safeDecode) |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 204 | && unlikely((uptrval)(op) + |
| 205 | length < (uptrval)(op))) { |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 206 | /* overflow detection */ |
Greg Kroah-Hartman | 206204a | 2014-06-20 22:01:41 -0700 | [diff] [blame] | 207 | goto _output_error; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 208 | } |
| 209 | if ((safeDecode) |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 210 | && unlikely((uptrval)(ip) + |
| 211 | length < (uptrval)(ip))) { |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 212 | /* overflow detection */ |
| 213 | goto _output_error; |
| 214 | } |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | /* copy literals */ |
| 218 | cpy = op + length; |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 219 | LZ4_STATIC_ASSERT(MFLIMIT >= WILDCOPYLENGTH); |
| 220 | |
| 221 | if (((endOnInput) && ((cpy > oend - MFLIMIT) |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 222 | || (ip + length > iend - (2 + 1 + LASTLITERALS)))) |
| 223 | || ((!endOnInput) && (cpy > oend - WILDCOPYLENGTH))) { |
| 224 | if (partialDecoding) { |
| 225 | if (cpy > oend) { |
| 226 | /* |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 227 | * Partial decoding : |
| 228 | * stop in the middle of literal segment |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 229 | */ |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 230 | cpy = oend; |
| 231 | length = oend - op; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 232 | } |
| 233 | if ((endOnInput) |
| 234 | && (ip + length > iend)) { |
| 235 | /* |
| 236 | * Error : |
| 237 | * read attempt beyond |
| 238 | * end of input buffer |
| 239 | */ |
| 240 | goto _output_error; |
| 241 | } |
| 242 | } else { |
| 243 | if ((!endOnInput) |
| 244 | && (cpy != oend)) { |
| 245 | /* |
| 246 | * Error : |
| 247 | * block decoding must |
| 248 | * stop exactly there |
| 249 | */ |
| 250 | goto _output_error; |
| 251 | } |
| 252 | if ((endOnInput) |
| 253 | && ((ip + length != iend) |
| 254 | || (cpy > oend))) { |
| 255 | /* |
| 256 | * Error : |
| 257 | * input must be consumed |
| 258 | */ |
| 259 | goto _output_error; |
| 260 | } |
| 261 | } |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 262 | |
| 263 | memcpy(op, ip, length); |
| 264 | ip += length; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 265 | op += length; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 266 | |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 267 | /* Necessarily EOF, due to parsing restrictions */ |
| 268 | if (!partialDecoding || (cpy == oend)) |
| 269 | break; |
| 270 | } else { |
| 271 | /* may overwrite up to WILDCOPYLENGTH beyond cpy */ |
| 272 | LZ4_wildCopy(op, ip, cpy); |
| 273 | ip += length; |
| 274 | op = cpy; |
| 275 | } |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 276 | |
| 277 | /* get offset */ |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 278 | offset = LZ4_readLE16(ip); |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 279 | ip += 2; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 280 | match = op - offset; |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 281 | |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 282 | /* get matchlength */ |
| 283 | length = token & ML_MASK; |
| 284 | |
| 285 | _copy_match: |
| 286 | if ((checkOffset) && (unlikely(match + dictSize < lowPrefix))) { |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 287 | /* Error : offset outside buffers */ |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 288 | goto _output_error; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | /* costs ~1%; silence an msan warning when offset == 0 */ |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 292 | /* |
| 293 | * note : when partialDecoding, there is no guarantee that |
| 294 | * at least 4 bytes remain available in output buffer |
| 295 | */ |
| 296 | if (!partialDecoding) { |
| 297 | assert(oend > op); |
| 298 | assert(oend - op >= 4); |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 299 | |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 300 | LZ4_write32(op, (U32)offset); |
| 301 | } |
| 302 | |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 303 | if (length == ML_MASK) { |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 304 | unsigned int s; |
| 305 | |
| 306 | do { |
| 307 | s = *ip++; |
| 308 | |
| 309 | if ((endOnInput) && (ip > iend - LASTLITERALS)) |
| 310 | goto _output_error; |
| 311 | |
| 312 | length += s; |
| 313 | } while (s == 255); |
| 314 | |
| 315 | if ((safeDecode) |
| 316 | && unlikely( |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 317 | (uptrval)(op) + length < (uptrval)op)) { |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 318 | /* overflow detection */ |
Greg Kroah-Hartman | 4148c1f | 2014-06-24 16:59:01 -0400 | [diff] [blame] | 319 | goto _output_error; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 320 | } |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 321 | } |
| 322 | |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 323 | length += MINMATCH; |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 324 | |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 325 | /* match starting within external dictionary */ |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 326 | if ((dict == usingExtDict) && (match < lowPrefix)) { |
| 327 | if (unlikely(op + length > oend - LASTLITERALS)) { |
| 328 | /* doesn't respect parsing restriction */ |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 329 | if (!partialDecoding) |
| 330 | goto _output_error; |
| 331 | length = min(length, (size_t)(oend - op)); |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | if (length <= (size_t)(lowPrefix - match)) { |
| 335 | /* |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 336 | * match fits entirely within external |
| 337 | * dictionary : just copy |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 338 | */ |
| 339 | memmove(op, dictEnd - (lowPrefix - match), |
| 340 | length); |
| 341 | op += length; |
| 342 | } else { |
| 343 | /* |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 344 | * match stretches into both external |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 345 | * dictionary and current block |
| 346 | */ |
| 347 | size_t const copySize = (size_t)(lowPrefix - match); |
| 348 | size_t const restSize = length - copySize; |
| 349 | |
| 350 | memcpy(op, dictEnd - copySize, copySize); |
| 351 | op += copySize; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 352 | if (restSize > (size_t)(op - lowPrefix)) { |
| 353 | /* overlap copy */ |
| 354 | BYTE * const endOfMatch = op + restSize; |
| 355 | const BYTE *copyFrom = lowPrefix; |
| 356 | |
| 357 | while (op < endOfMatch) |
| 358 | *op++ = *copyFrom++; |
| 359 | } else { |
| 360 | memcpy(op, lowPrefix, restSize); |
| 361 | op += restSize; |
| 362 | } |
| 363 | } |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 364 | continue; |
| 365 | } |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 366 | |
| 367 | /* copy match within block */ |
| 368 | cpy = op + length; |
| 369 | |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 370 | /* |
| 371 | * partialDecoding : |
| 372 | * may not respect endBlock parsing restrictions |
| 373 | */ |
| 374 | assert(op <= oend); |
| 375 | if (partialDecoding && |
| 376 | (cpy > oend - MATCH_SAFEGUARD_DISTANCE)) { |
| 377 | size_t const mlen = min(length, (size_t)(oend - op)); |
| 378 | const BYTE * const matchEnd = match + mlen; |
| 379 | BYTE * const copyEnd = op + mlen; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 380 | |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 381 | if (matchEnd > op) { |
| 382 | /* overlap copy */ |
| 383 | while (op < copyEnd) |
| 384 | *op++ = *match++; |
| 385 | } else { |
| 386 | memcpy(op, match, mlen); |
| 387 | } |
| 388 | op = copyEnd; |
| 389 | if (op == oend) |
| 390 | break; |
| 391 | continue; |
| 392 | } |
| 393 | |
| 394 | if (unlikely(offset < 8)) { |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 395 | op[0] = match[0]; |
| 396 | op[1] = match[1]; |
| 397 | op[2] = match[2]; |
| 398 | op[3] = match[3]; |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 399 | match += inc32table[offset]; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 400 | memcpy(op + 4, match, 4); |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 401 | match -= dec64table[offset]; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 402 | } else { |
| 403 | LZ4_copy8(op, match); |
| 404 | match += 8; |
| 405 | } |
| 406 | |
| 407 | op += 8; |
| 408 | |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 409 | if (unlikely(cpy > oend - MATCH_SAFEGUARD_DISTANCE)) { |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 410 | BYTE * const oCopyLimit = oend - (WILDCOPYLENGTH - 1); |
| 411 | |
| 412 | if (cpy > oend - LASTLITERALS) { |
| 413 | /* |
| 414 | * Error : last LASTLITERALS bytes |
| 415 | * must be literals (uncompressed) |
| 416 | */ |
| 417 | goto _output_error; |
| 418 | } |
| 419 | |
| 420 | if (op < oCopyLimit) { |
| 421 | LZ4_wildCopy(op, match, oCopyLimit); |
| 422 | match += oCopyLimit - op; |
| 423 | op = oCopyLimit; |
| 424 | } |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 425 | while (op < cpy) |
| 426 | *op++ = *match++; |
| 427 | } else { |
| 428 | LZ4_copy8(op, match); |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 429 | if (length > 16) |
| 430 | LZ4_wildCopy(op + 8, match + 8, cpy); |
| 431 | } |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 432 | op = cpy; /* wildcopy correction */ |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 433 | } |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 434 | |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 435 | /* end of decoding */ |
| 436 | if (endOnInput) { |
| 437 | /* Nb of output bytes decoded */ |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 438 | return (int) (((char *)op) - dst); |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 439 | } else { |
| 440 | /* Nb of input bytes read */ |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 441 | return (int) (((const char *)ip) - src); |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | /* Overflow error detected */ |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 445 | _output_error: |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 446 | return (int) (-(((const char *)ip) - src)) - 1; |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 449 | int LZ4_decompress_safe(const char *source, char *dest, |
| 450 | int compressedSize, int maxDecompressedSize) |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 451 | { |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 452 | return LZ4_decompress_generic(source, dest, |
| 453 | compressedSize, maxDecompressedSize, |
| 454 | endOnInputSize, decode_full_block, |
| 455 | noDict, (BYTE *)dest, NULL, 0); |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 456 | } |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 457 | |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 458 | int LZ4_decompress_safe_partial(const char *src, char *dst, |
| 459 | int compressedSize, int targetOutputSize, int dstCapacity) |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 460 | { |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 461 | dstCapacity = min(targetOutputSize, dstCapacity); |
| 462 | return LZ4_decompress_generic(src, dst, compressedSize, dstCapacity, |
| 463 | endOnInputSize, partial_decode, |
| 464 | noDict, (BYTE *)dst, NULL, 0); |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 465 | } |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 466 | |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 467 | int LZ4_decompress_fast(const char *source, char *dest, int originalSize) |
| 468 | { |
| 469 | return LZ4_decompress_generic(source, dest, 0, originalSize, |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 470 | endOnOutputSize, decode_full_block, |
| 471 | withPrefix64k, |
| 472 | (BYTE *)dest - 64 * KB, NULL, 0); |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 473 | } |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 474 | |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 475 | /* ===== Instantiate a few more decoding cases, used more than once. ===== */ |
| 476 | |
| 477 | int LZ4_decompress_safe_withPrefix64k(const char *source, char *dest, |
| 478 | int compressedSize, int maxOutputSize) |
| 479 | { |
| 480 | return LZ4_decompress_generic(source, dest, |
| 481 | compressedSize, maxOutputSize, |
| 482 | endOnInputSize, decode_full_block, |
| 483 | withPrefix64k, |
| 484 | (BYTE *)dest - 64 * KB, NULL, 0); |
| 485 | } |
| 486 | |
| 487 | static int LZ4_decompress_safe_withSmallPrefix(const char *source, char *dest, |
| 488 | int compressedSize, |
| 489 | int maxOutputSize, |
| 490 | size_t prefixSize) |
| 491 | { |
| 492 | return LZ4_decompress_generic(source, dest, |
| 493 | compressedSize, maxOutputSize, |
| 494 | endOnInputSize, decode_full_block, |
| 495 | noDict, |
| 496 | (BYTE *)dest - prefixSize, NULL, 0); |
| 497 | } |
| 498 | |
| 499 | int LZ4_decompress_safe_forceExtDict(const char *source, char *dest, |
| 500 | int compressedSize, int maxOutputSize, |
| 501 | const void *dictStart, size_t dictSize) |
| 502 | { |
| 503 | return LZ4_decompress_generic(source, dest, |
| 504 | compressedSize, maxOutputSize, |
| 505 | endOnInputSize, decode_full_block, |
| 506 | usingExtDict, (BYTE *)dest, |
| 507 | (const BYTE *)dictStart, dictSize); |
| 508 | } |
| 509 | |
| 510 | static int LZ4_decompress_fast_extDict(const char *source, char *dest, |
| 511 | int originalSize, |
| 512 | const void *dictStart, size_t dictSize) |
| 513 | { |
| 514 | return LZ4_decompress_generic(source, dest, |
| 515 | 0, originalSize, |
| 516 | endOnOutputSize, decode_full_block, |
| 517 | usingExtDict, (BYTE *)dest, |
| 518 | (const BYTE *)dictStart, dictSize); |
| 519 | } |
| 520 | |
| 521 | /* |
| 522 | * The "double dictionary" mode, for use with e.g. ring buffers: the first part |
| 523 | * of the dictionary is passed as prefix, and the second via dictStart + dictSize. |
| 524 | * These routines are used only once, in LZ4_decompress_*_continue(). |
| 525 | */ |
| 526 | static FORCE_INLINE |
| 527 | int LZ4_decompress_safe_doubleDict(const char *source, char *dest, |
| 528 | int compressedSize, int maxOutputSize, |
| 529 | size_t prefixSize, |
| 530 | const void *dictStart, size_t dictSize) |
| 531 | { |
| 532 | return LZ4_decompress_generic(source, dest, |
| 533 | compressedSize, maxOutputSize, |
| 534 | endOnInputSize, decode_full_block, |
| 535 | usingExtDict, (BYTE *)dest - prefixSize, |
| 536 | (const BYTE *)dictStart, dictSize); |
| 537 | } |
| 538 | |
| 539 | static FORCE_INLINE |
| 540 | int LZ4_decompress_fast_doubleDict(const char *source, char *dest, |
| 541 | int originalSize, size_t prefixSize, |
| 542 | const void *dictStart, size_t dictSize) |
| 543 | { |
| 544 | return LZ4_decompress_generic(source, dest, |
| 545 | 0, originalSize, |
| 546 | endOnOutputSize, decode_full_block, |
| 547 | usingExtDict, (BYTE *)dest - prefixSize, |
| 548 | (const BYTE *)dictStart, dictSize); |
| 549 | } |
| 550 | |
| 551 | /* ===== streaming decompression functions ===== */ |
| 552 | |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 553 | int LZ4_setStreamDecode(LZ4_streamDecode_t *LZ4_streamDecode, |
| 554 | const char *dictionary, int dictSize) |
| 555 | { |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 556 | LZ4_streamDecode_t_internal *lz4sd = |
| 557 | &LZ4_streamDecode->internal_donotuse; |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 558 | |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 559 | lz4sd->prefixSize = (size_t) dictSize; |
| 560 | lz4sd->prefixEnd = (const BYTE *) dictionary + dictSize; |
| 561 | lz4sd->externalDict = NULL; |
| 562 | lz4sd->extDictSize = 0; |
| 563 | return 1; |
| 564 | } |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 565 | |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 566 | /* |
| 567 | * *_continue() : |
| 568 | * These decoding functions allow decompression of multiple blocks |
| 569 | * in "streaming" mode. |
| 570 | * Previously decoded blocks must still be available at the memory |
| 571 | * position where they were decoded. |
| 572 | * If it's not possible, save the relevant part of |
| 573 | * decoded data into a safe buffer, |
| 574 | * and indicate where it stands using LZ4_setStreamDecode() |
| 575 | */ |
| 576 | int LZ4_decompress_safe_continue(LZ4_streamDecode_t *LZ4_streamDecode, |
| 577 | const char *source, char *dest, int compressedSize, int maxOutputSize) |
| 578 | { |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 579 | LZ4_streamDecode_t_internal *lz4sd = |
| 580 | &LZ4_streamDecode->internal_donotuse; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 581 | int result; |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 582 | |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 583 | if (lz4sd->prefixSize == 0) { |
| 584 | /* The first call, no dictionary yet. */ |
| 585 | assert(lz4sd->extDictSize == 0); |
| 586 | result = LZ4_decompress_safe(source, dest, |
| 587 | compressedSize, maxOutputSize); |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 588 | if (result <= 0) |
| 589 | return result; |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 590 | lz4sd->prefixSize = result; |
| 591 | lz4sd->prefixEnd = (BYTE *)dest + result; |
| 592 | } else if (lz4sd->prefixEnd == (BYTE *)dest) { |
| 593 | /* They're rolling the current segment. */ |
| 594 | if (lz4sd->prefixSize >= 64 * KB - 1) |
| 595 | result = LZ4_decompress_safe_withPrefix64k(source, dest, |
| 596 | compressedSize, maxOutputSize); |
| 597 | else if (lz4sd->extDictSize == 0) |
| 598 | result = LZ4_decompress_safe_withSmallPrefix(source, |
| 599 | dest, compressedSize, maxOutputSize, |
| 600 | lz4sd->prefixSize); |
| 601 | else |
| 602 | result = LZ4_decompress_safe_doubleDict(source, dest, |
| 603 | compressedSize, maxOutputSize, |
| 604 | lz4sd->prefixSize, |
| 605 | lz4sd->externalDict, lz4sd->extDictSize); |
| 606 | if (result <= 0) |
| 607 | return result; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 608 | lz4sd->prefixSize += result; |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 609 | lz4sd->prefixEnd += result; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 610 | } else { |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 611 | /* |
| 612 | * The buffer wraps around, or they're |
| 613 | * switching to another buffer. |
| 614 | */ |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 615 | lz4sd->extDictSize = lz4sd->prefixSize; |
| 616 | lz4sd->externalDict = lz4sd->prefixEnd - lz4sd->extDictSize; |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 617 | result = LZ4_decompress_safe_forceExtDict(source, dest, |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 618 | compressedSize, maxOutputSize, |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 619 | lz4sd->externalDict, lz4sd->extDictSize); |
| 620 | if (result <= 0) |
| 621 | return result; |
| 622 | lz4sd->prefixSize = result; |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 623 | lz4sd->prefixEnd = (BYTE *)dest + result; |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 624 | } |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 625 | |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 626 | return result; |
| 627 | } |
| 628 | |
| 629 | int LZ4_decompress_fast_continue(LZ4_streamDecode_t *LZ4_streamDecode, |
| 630 | const char *source, char *dest, int originalSize) |
| 631 | { |
| 632 | LZ4_streamDecode_t_internal *lz4sd = &LZ4_streamDecode->internal_donotuse; |
| 633 | int result; |
| 634 | |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 635 | if (lz4sd->prefixSize == 0) { |
| 636 | assert(lz4sd->extDictSize == 0); |
| 637 | result = LZ4_decompress_fast(source, dest, originalSize); |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 638 | if (result <= 0) |
| 639 | return result; |
| 640 | lz4sd->prefixSize = originalSize; |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 641 | lz4sd->prefixEnd = (BYTE *)dest + originalSize; |
| 642 | } else if (lz4sd->prefixEnd == (BYTE *)dest) { |
| 643 | if (lz4sd->prefixSize >= 64 * KB - 1 || |
| 644 | lz4sd->extDictSize == 0) |
| 645 | result = LZ4_decompress_fast(source, dest, |
| 646 | originalSize); |
| 647 | else |
| 648 | result = LZ4_decompress_fast_doubleDict(source, dest, |
| 649 | originalSize, lz4sd->prefixSize, |
| 650 | lz4sd->externalDict, lz4sd->extDictSize); |
| 651 | if (result <= 0) |
| 652 | return result; |
| 653 | lz4sd->prefixSize += originalSize; |
| 654 | lz4sd->prefixEnd += originalSize; |
| 655 | } else { |
| 656 | lz4sd->extDictSize = lz4sd->prefixSize; |
| 657 | lz4sd->externalDict = lz4sd->prefixEnd - lz4sd->extDictSize; |
| 658 | result = LZ4_decompress_fast_extDict(source, dest, |
| 659 | originalSize, lz4sd->externalDict, lz4sd->extDictSize); |
| 660 | if (result <= 0) |
| 661 | return result; |
| 662 | lz4sd->prefixSize = originalSize; |
| 663 | lz4sd->prefixEnd = (BYTE *)dest + originalSize; |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 664 | } |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 665 | return result; |
| 666 | } |
| 667 | |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 668 | int LZ4_decompress_safe_usingDict(const char *source, char *dest, |
| 669 | int compressedSize, int maxOutputSize, |
| 670 | const char *dictStart, int dictSize) |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 671 | { |
| 672 | if (dictSize == 0) |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 673 | return LZ4_decompress_safe(source, dest, |
| 674 | compressedSize, maxOutputSize); |
| 675 | if (dictStart+dictSize == dest) { |
| 676 | if (dictSize >= 64 * KB - 1) |
| 677 | return LZ4_decompress_safe_withPrefix64k(source, dest, |
| 678 | compressedSize, maxOutputSize); |
| 679 | return LZ4_decompress_safe_withSmallPrefix(source, dest, |
| 680 | compressedSize, maxOutputSize, dictSize); |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 681 | } |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 682 | return LZ4_decompress_safe_forceExtDict(source, dest, |
| 683 | compressedSize, maxOutputSize, dictStart, dictSize); |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | int LZ4_decompress_fast_usingDict(const char *source, char *dest, |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 687 | int originalSize, |
| 688 | const char *dictStart, int dictSize) |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 689 | { |
Gao Xiang | 2209fda | 2018-10-30 15:07:28 -0700 | [diff] [blame] | 690 | if (dictSize == 0 || dictStart + dictSize == dest) |
| 691 | return LZ4_decompress_fast(source, dest, originalSize); |
| 692 | |
| 693 | return LZ4_decompress_fast_extDict(source, dest, originalSize, |
| 694 | dictStart, dictSize); |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 695 | } |
| 696 | |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 697 | #ifndef STATIC |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 698 | EXPORT_SYMBOL(LZ4_decompress_safe); |
| 699 | EXPORT_SYMBOL(LZ4_decompress_safe_partial); |
| 700 | EXPORT_SYMBOL(LZ4_decompress_fast); |
| 701 | EXPORT_SYMBOL(LZ4_setStreamDecode); |
| 702 | EXPORT_SYMBOL(LZ4_decompress_safe_continue); |
| 703 | EXPORT_SYMBOL(LZ4_decompress_fast_continue); |
| 704 | EXPORT_SYMBOL(LZ4_decompress_safe_usingDict); |
| 705 | EXPORT_SYMBOL(LZ4_decompress_fast_usingDict); |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 706 | |
Richard Laager | ee8a99b | 2013-08-22 16:35:47 -0700 | [diff] [blame] | 707 | MODULE_LICENSE("Dual BSD/GPL"); |
Sven Schmidt | 4e1a33b | 2017-02-24 15:01:12 -0800 | [diff] [blame] | 708 | MODULE_DESCRIPTION("LZ4 decompressor"); |
Kyungsik Lee | cffb78b | 2013-07-08 16:01:45 -0700 | [diff] [blame] | 709 | #endif |