extzstd 0.0.3.CONCEPT → 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.ja +5 -0
  3. data/LICENSE +6 -6
  4. data/README.md +35 -22
  5. data/contrib/zstd/LICENSE +13 -9
  6. data/contrib/zstd/README.md +37 -44
  7. data/contrib/zstd/common/entropy_common.c +33 -39
  8. data/contrib/zstd/common/error_private.c +43 -0
  9. data/contrib/zstd/common/error_private.h +11 -60
  10. data/contrib/zstd/common/fse.h +11 -5
  11. data/contrib/zstd/common/fse_decompress.c +14 -16
  12. data/contrib/zstd/common/huf.h +1 -1
  13. data/contrib/zstd/common/mem.h +36 -43
  14. data/contrib/zstd/common/xxhash.c +31 -18
  15. data/contrib/zstd/common/xxhash.h +71 -35
  16. data/contrib/zstd/common/zbuff.h +29 -35
  17. data/contrib/zstd/common/zstd_common.c +24 -32
  18. data/contrib/zstd/common/zstd_errors.h +60 -0
  19. data/contrib/zstd/common/zstd_internal.h +109 -80
  20. data/contrib/zstd/compress/fse_compress.c +9 -6
  21. data/contrib/zstd/compress/huf_compress.c +30 -74
  22. data/contrib/zstd/compress/zbuff_compress.c +43 -51
  23. data/contrib/zstd/compress/zstd_compress.c +953 -763
  24. data/contrib/zstd/compress/zstd_opt.h +115 -261
  25. data/contrib/zstd/decompress/huf_decompress.c +29 -40
  26. data/contrib/zstd/decompress/zbuff_decompress.c +36 -78
  27. data/contrib/zstd/decompress/zstd_decompress.c +976 -496
  28. data/contrib/zstd/dictBuilder/divsufsort.h +5 -5
  29. data/contrib/zstd/dictBuilder/zdict.c +194 -229
  30. data/contrib/zstd/dictBuilder/zdict.h +66 -68
  31. data/contrib/zstd/legacy/zstd_legacy.h +168 -49
  32. data/contrib/zstd/legacy/zstd_v01.c +95 -178
  33. data/contrib/zstd/legacy/zstd_v01.h +12 -32
  34. data/contrib/zstd/legacy/zstd_v02.c +48 -274
  35. data/contrib/zstd/legacy/zstd_v02.h +12 -32
  36. data/contrib/zstd/legacy/zstd_v03.c +48 -274
  37. data/contrib/zstd/legacy/zstd_v03.h +12 -32
  38. data/contrib/zstd/legacy/zstd_v04.c +63 -320
  39. data/contrib/zstd/legacy/zstd_v04.h +13 -33
  40. data/contrib/zstd/legacy/zstd_v05.c +80 -345
  41. data/contrib/zstd/legacy/zstd_v05.h +9 -31
  42. data/contrib/zstd/legacy/zstd_v06.c +48 -458
  43. data/contrib/zstd/legacy/zstd_v06.h +41 -67
  44. data/contrib/zstd/legacy/zstd_v07.c +4544 -0
  45. data/contrib/zstd/legacy/zstd_v07.h +173 -0
  46. data/contrib/zstd/zstd.h +640 -0
  47. data/ext/extconf.rb +7 -3
  48. data/ext/extzstd.c +263 -106
  49. data/ext/extzstd.h +8 -6
  50. data/ext/extzstd_nogvls.h +0 -117
  51. data/ext/extzstd_stream.c +347 -0
  52. data/ext/zstd_common.c +8 -0
  53. data/ext/zstd_compress.c +6 -0
  54. data/ext/zstd_decompress.c +5 -0
  55. data/ext/zstd_dictbuilder.c +5 -0
  56. data/ext/zstd_legacy_v07.c +1 -0
  57. data/gemstub.rb +18 -16
  58. data/lib/extzstd/version.rb +1 -1
  59. data/lib/extzstd.rb +77 -43
  60. data/test/test_basic.rb +11 -6
  61. metadata +23 -10
  62. data/contrib/zstd/common/error_public.h +0 -77
  63. data/contrib/zstd/common/zstd.h +0 -475
  64. data/ext/extzstd_buffered.c +0 -265
  65. data/ext/zstd_amalgam.c +0 -18
@@ -1,43 +1,19 @@
1
- /* ******************************************************************
2
- ZSTD_v01
3
- Zstandard decoder, compatible with v0.1.x format
4
- Copyright (C) 2013-2015, Yann Collet.
5
-
6
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
7
-
8
- Redistribution and use in source and binary forms, with or without
9
- modification, are permitted provided that the following conditions are
10
- met:
11
-
12
- * Redistributions of source code must retain the above copyright
13
- notice, this list of conditions and the following disclaimer.
14
- * Redistributions in binary form must reproduce the above
15
- copyright notice, this list of conditions and the following disclaimer
16
- in the documentation and/or other materials provided with the
17
- distribution.
18
-
19
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30
-
31
- You can contact the author at :
32
- - Source repository : https://github.com/Cyan4973/FiniteStateEntropy
33
- - Public forum : https://groups.google.com/forum/#!forum/lz4c
34
- ****************************************************************** */
1
+ /**
2
+ * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ */
9
+
35
10
 
36
11
  /******************************************
37
12
  * Includes
38
13
  ******************************************/
39
14
  #include <stddef.h> /* size_t, ptrdiff_t */
40
15
  #include "zstd_v01.h"
16
+ #include "error_private.h"
41
17
 
42
18
 
43
19
  /******************************************
@@ -164,11 +140,15 @@ typedef struct
164
140
  # pragma warning(disable : 4214) /* disable: C4214: non-int bitfields */
165
141
  #else
166
142
  # define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
167
- # ifdef __GNUC__
168
- # define FORCE_INLINE static inline __attribute__((always_inline))
143
+ # if defined (__cplusplus) || defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L /* C99 */
144
+ # ifdef __GNUC__
145
+ # define FORCE_INLINE static inline __attribute__((always_inline))
146
+ # else
147
+ # define FORCE_INLINE static inline
148
+ # endif
169
149
  # else
170
- # define FORCE_INLINE static inline
171
- # endif
150
+ # define FORCE_INLINE static
151
+ # endif /* __STDC_VERSION__ */
172
152
  #endif
173
153
 
174
154
 
@@ -225,7 +205,7 @@ typedef signed long long S64;
225
205
  #ifndef FSE_FORCE_MEMORY_ACCESS /* can be defined externally, on command line for example */
226
206
  # if defined(__GNUC__) && ( defined(__ARM_ARCH_6__) || defined(__ARM_ARCH_6J__) || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6Z__) || defined(__ARM_ARCH_6ZK__) || defined(__ARM_ARCH_6T2__) )
227
207
  # define FSE_FORCE_MEMORY_ACCESS 2
228
- # elif defined(__INTEL_COMPILER) || \
208
+ # elif (defined(__INTEL_COMPILER) && !defined(WIN32)) || \
229
209
  (defined(__GNUC__) && ( defined(__ARM_ARCH_7__) || defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_7R__) || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7S__) ))
230
210
  # define FSE_FORCE_MEMORY_ACCESS 1
231
211
  # endif
@@ -978,13 +958,16 @@ static size_t HUF_readDTable (U16* DTable, const void* src, size_t srcSize)
978
958
  U32 weightTotal;
979
959
  U32 maxBits;
980
960
  const BYTE* ip = (const BYTE*) src;
981
- size_t iSize = ip[0];
961
+ size_t iSize;
982
962
  size_t oSize;
983
963
  U32 n;
984
964
  U32 nextRankStart;
985
965
  void* ptr = DTable+1;
986
966
  HUF_DElt* const dt = (HUF_DElt*)ptr;
987
967
 
968
+ if (!srcSize) return (size_t)-FSE_ERROR_srcSize_wrong;
969
+ iSize = ip[0];
970
+
988
971
  FSE_STATIC_ASSERT(sizeof(HUF_DElt) == sizeof(U16)); /* if compilation fails here, assertion is false */
989
972
  //memset(huffWeight, 0, sizeof(huffWeight)); /* should not be necessary, but some analyzer complain ... */
990
973
  if (iSize >= 128) /* special header */
@@ -1025,6 +1008,7 @@ static size_t HUF_readDTable (U16* DTable, const void* src, size_t srcSize)
1025
1008
  rankVal[huffWeight[n]]++;
1026
1009
  weightTotal += (1 << huffWeight[n]) >> 1;
1027
1010
  }
1011
+ if (weightTotal == 0) return (size_t)-FSE_ERROR_corruptionDetected;
1028
1012
 
1029
1013
  /* get last non-null symbol weight (implied, total must be 2^n) */
1030
1014
  maxBits = FSE_highbit32(weightTotal) + 1;
@@ -1196,57 +1180,6 @@ static size_t HUF_decompress (void* dst, size_t maxDstSize, const void* cSrc, si
1196
1180
 
1197
1181
  #endif /* FSE_COMMONDEFS_ONLY */
1198
1182
 
1199
- /*
1200
- zstd - standard compression library
1201
- Header File for static linking only
1202
- Copyright (C) 2014-2015, Yann Collet.
1203
-
1204
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1205
-
1206
- Redistribution and use in source and binary forms, with or without
1207
- modification, are permitted provided that the following conditions are
1208
- met:
1209
- * Redistributions of source code must retain the above copyright
1210
- notice, this list of conditions and the following disclaimer.
1211
- * Redistributions in binary form must reproduce the above
1212
- copyright notice, this list of conditions and the following disclaimer
1213
- in the documentation and/or other materials provided with the
1214
- distribution.
1215
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1216
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1217
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1218
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1219
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1220
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1221
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1222
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1223
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1224
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1225
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1226
-
1227
- You can contact the author at :
1228
- - zstd source repository : https://github.com/Cyan4973/zstd
1229
- - ztsd public forum : https://groups.google.com/forum/#!forum/lz4c
1230
- */
1231
-
1232
- /* The objects defined into this file should be considered experimental.
1233
- * They are not labelled stable, as their prototype may change in the future.
1234
- * You can use them for tests, provide feedback, or if you can endure risk of future changes.
1235
- */
1236
-
1237
- /**************************************
1238
- * Error management
1239
- **************************************/
1240
- #define ZSTD_LIST_ERRORS(ITEM) \
1241
- ITEM(ZSTD_OK_NoError) ITEM(ZSTD_ERROR_GENERIC) \
1242
- ITEM(ZSTD_ERROR_MagicNumber) \
1243
- ITEM(ZSTD_ERROR_SrcSize) ITEM(ZSTD_ERROR_maxDstSize_tooSmall) \
1244
- ITEM(ZSTD_ERROR_corruption) \
1245
- ITEM(ZSTD_ERROR_maxCode)
1246
-
1247
- #define ZSTD_GENERATE_ENUM(ENUM) ENUM,
1248
- typedef enum { ZSTD_LIST_ERRORS(ZSTD_GENERATE_ENUM) } ZSTD_errorCodes; /* exposed list of errors; static linking only */
1249
-
1250
1183
  /*
1251
1184
  zstd - standard compression library
1252
1185
  Copyright (C) 2014-2015, Yann Collet.
@@ -1325,17 +1258,9 @@ typedef enum { ZSTD_LIST_ERRORS(ZSTD_GENERATE_ENUM) } ZSTD_errorCodes; /* expo
1325
1258
  #endif
1326
1259
 
1327
1260
  #ifdef _MSC_VER /* Visual Studio */
1328
- # define FORCE_INLINE static __forceinline
1329
1261
  # include <intrin.h> /* For Visual 2005 */
1330
1262
  # pragma warning(disable : 4127) /* disable: C4127: conditional expression is constant */
1331
1263
  # pragma warning(disable : 4324) /* disable: C4324: padded structure */
1332
- #else
1333
- # define GCC_VERSION (__GNUC__ * 100 + __GNUC_MINOR__)
1334
- # ifdef __GNUC__
1335
- # define FORCE_INLINE static inline __attribute__((always_inline))
1336
- # else
1337
- # define FORCE_INLINE static inline
1338
- # endif
1339
1264
  #endif
1340
1265
 
1341
1266
 
@@ -1516,11 +1441,8 @@ typedef struct ZSTD_Cctx_s
1516
1441
  /**************************************
1517
1442
  * Error Management
1518
1443
  **************************************/
1519
- /* tells if a return value is an error code */
1520
- static unsigned ZSTD_isError(size_t code) { return (code > (size_t)(-ZSTD_ERROR_maxCode)); }
1521
-
1522
1444
  /* published entry point */
1523
- unsigned ZSTDv01_isError(size_t code) { return ZSTD_isError(code); }
1445
+ unsigned ZSTDv01_isError(size_t code) { return ERR_isError(code); }
1524
1446
 
1525
1447
 
1526
1448
  /**************************************
@@ -1535,13 +1457,13 @@ unsigned ZSTDv01_isError(size_t code) { return ZSTD_isError(code); }
1535
1457
  * Decompression code
1536
1458
  **************************************************************/
1537
1459
 
1538
- static size_t ZSTD_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr)
1460
+ size_t ZSTDv01_getcBlockSize(const void* src, size_t srcSize, blockProperties_t* bpPtr)
1539
1461
  {
1540
1462
  const BYTE* const in = (const BYTE* const)src;
1541
1463
  BYTE headerFlags;
1542
1464
  U32 cSize;
1543
1465
 
1544
- if (srcSize < 3) return (size_t)-ZSTD_ERROR_SrcSize;
1466
+ if (srcSize < 3) return ERROR(srcSize_wrong);
1545
1467
 
1546
1468
  headerFlags = *in;
1547
1469
  cSize = in[2] + (in[1]<<8) + ((in[0] & 7)<<16);
@@ -1557,7 +1479,7 @@ static size_t ZSTD_getcBlockSize(const void* src, size_t srcSize, blockPropertie
1557
1479
 
1558
1480
  static size_t ZSTD_copyUncompressedBlock(void* dst, size_t maxDstSize, const void* src, size_t srcSize)
1559
1481
  {
1560
- if (srcSize > maxDstSize) return (size_t)-ZSTD_ERROR_maxDstSize_tooSmall;
1482
+ if (srcSize > maxDstSize) return ERROR(dstSize_tooSmall);
1561
1483
  memcpy(dst, src, srcSize);
1562
1484
  return srcSize;
1563
1485
  }
@@ -1574,21 +1496,21 @@ static size_t ZSTD_decompressLiterals(void* ctx,
1574
1496
  size_t litSize;
1575
1497
 
1576
1498
  /* check : minimum 2, for litSize, +1, for content */
1577
- if (srcSize <= 3) return (size_t)-ZSTD_ERROR_corruption;
1499
+ if (srcSize <= 3) return ERROR(corruption_detected);
1578
1500
 
1579
1501
  litSize = ip[1] + (ip[0]<<8);
1580
1502
  litSize += ((ip[-3] >> 3) & 7) << 16; // mmmmh....
1581
1503
  op = oend - litSize;
1582
1504
 
1583
1505
  (void)ctx;
1584
- if (litSize > maxDstSize) return (size_t)-ZSTD_ERROR_maxDstSize_tooSmall;
1506
+ if (litSize > maxDstSize) return ERROR(dstSize_tooSmall);
1585
1507
  errorCode = HUF_decompress(op, litSize, ip+2, srcSize-2);
1586
- if (FSE_isError(errorCode)) return (size_t)-ZSTD_ERROR_GENERIC;
1508
+ if (FSE_isError(errorCode)) return ERROR(GENERIC);
1587
1509
  return litSize;
1588
1510
  }
1589
1511
 
1590
1512
 
1591
- static size_t ZSTD_decodeLiteralsBlock(void* ctx,
1513
+ size_t ZSTDv01_decodeLiteralsBlock(void* ctx,
1592
1514
  void* dst, size_t maxDstSize,
1593
1515
  const BYTE** litStart, size_t* litSize,
1594
1516
  const void* src, size_t srcSize)
@@ -1599,9 +1521,9 @@ static size_t ZSTD_decodeLiteralsBlock(void* ctx,
1599
1521
  BYTE* const oend = ostart + maxDstSize;
1600
1522
  blockProperties_t litbp;
1601
1523
 
1602
- size_t litcSize = ZSTD_getcBlockSize(src, srcSize, &litbp);
1603
- if (ZSTD_isError(litcSize)) return litcSize;
1604
- if (litcSize > srcSize - ZSTD_blockHeaderSize) return (size_t)-ZSTD_ERROR_SrcSize;
1524
+ size_t litcSize = ZSTDv01_getcBlockSize(src, srcSize, &litbp);
1525
+ if (ZSTDv01_isError(litcSize)) return litcSize;
1526
+ if (litcSize > srcSize - ZSTD_blockHeaderSize) return ERROR(srcSize_wrong);
1605
1527
  ip += ZSTD_blockHeaderSize;
1606
1528
 
1607
1529
  switch(litbp.blockType)
@@ -1614,7 +1536,8 @@ static size_t ZSTD_decodeLiteralsBlock(void* ctx,
1614
1536
  case bt_rle:
1615
1537
  {
1616
1538
  size_t rleSize = litbp.origSize;
1617
- if (rleSize>maxDstSize) return (size_t)-ZSTD_ERROR_maxDstSize_tooSmall;
1539
+ if (rleSize>maxDstSize) return ERROR(dstSize_tooSmall);
1540
+ if (!srcSize) return ERROR(srcSize_wrong);
1618
1541
  memset(oend - rleSize, *ip, rleSize);
1619
1542
  *litStart = oend - rleSize;
1620
1543
  *litSize = rleSize;
@@ -1624,7 +1547,7 @@ static size_t ZSTD_decodeLiteralsBlock(void* ctx,
1624
1547
  case bt_compressed:
1625
1548
  {
1626
1549
  size_t decodedLitSize = ZSTD_decompressLiterals(ctx, dst, maxDstSize, ip, litcSize);
1627
- if (ZSTD_isError(decodedLitSize)) return decodedLitSize;
1550
+ if (ZSTDv01_isError(decodedLitSize)) return decodedLitSize;
1628
1551
  *litStart = oend - decodedLitSize;
1629
1552
  *litSize = decodedLitSize;
1630
1553
  ip += litcSize;
@@ -1632,14 +1555,14 @@ static size_t ZSTD_decodeLiteralsBlock(void* ctx,
1632
1555
  }
1633
1556
  case bt_end:
1634
1557
  default:
1635
- return (size_t)-ZSTD_ERROR_GENERIC;
1558
+ return ERROR(GENERIC);
1636
1559
  }
1637
1560
 
1638
1561
  return ip-istart;
1639
1562
  }
1640
1563
 
1641
1564
 
1642
- static size_t ZSTD_decodeSeqHeaders(int* nbSeq, const BYTE** dumpsPtr, size_t* dumpsLengthPtr,
1565
+ size_t ZSTDv01_decodeSeqHeaders(int* nbSeq, const BYTE** dumpsPtr, size_t* dumpsLengthPtr,
1643
1566
  FSE_DTable* DTableLL, FSE_DTable* DTableML, FSE_DTable* DTableOffb,
1644
1567
  const void* src, size_t srcSize)
1645
1568
  {
@@ -1651,7 +1574,7 @@ static size_t ZSTD_decodeSeqHeaders(int* nbSeq, const BYTE** dumpsPtr, size_t* d
1651
1574
  size_t dumpsLength;
1652
1575
 
1653
1576
  /* check */
1654
- if (srcSize < 5) return (size_t)-ZSTD_ERROR_SrcSize;
1577
+ if (srcSize < 5) return ERROR(srcSize_wrong);
1655
1578
 
1656
1579
  /* SeqHead */
1657
1580
  *nbSeq = ZSTD_readLE16(ip); ip+=2;
@@ -1675,7 +1598,7 @@ static size_t ZSTD_decodeSeqHeaders(int* nbSeq, const BYTE** dumpsPtr, size_t* d
1675
1598
  *dumpsLengthPtr = dumpsLength;
1676
1599
 
1677
1600
  /* check */
1678
- if (ip > iend-3) return (size_t)-ZSTD_ERROR_SrcSize; /* min : all 3 are "raw", hence no header, but at least xxLog bits per type */
1601
+ if (ip > iend-3) return ERROR(srcSize_wrong); /* min : all 3 are "raw", hence no header, but at least xxLog bits per type */
1679
1602
 
1680
1603
  /* sequences */
1681
1604
  {
@@ -1685,7 +1608,6 @@ static size_t ZSTD_decodeSeqHeaders(int* nbSeq, const BYTE** dumpsPtr, size_t* d
1685
1608
  /* Build DTables */
1686
1609
  switch(LLtype)
1687
1610
  {
1688
- U32 max;
1689
1611
  case bt_rle :
1690
1612
  LLlog = 0;
1691
1613
  FSE_buildDTable_rle(DTableLL, *ip++); break;
@@ -1693,52 +1615,49 @@ static size_t ZSTD_decodeSeqHeaders(int* nbSeq, const BYTE** dumpsPtr, size_t* d
1693
1615
  LLlog = LLbits;
1694
1616
  FSE_buildDTable_raw(DTableLL, LLbits); break;
1695
1617
  default :
1696
- max = MaxLL;
1697
- headerSize = FSE_readNCount(norm, &max, &LLlog, ip, iend-ip);
1698
- if (FSE_isError(headerSize)) return (size_t)-ZSTD_ERROR_GENERIC;
1699
- if (LLlog > LLFSELog) return (size_t)-ZSTD_ERROR_corruption;
1700
- ip += headerSize;
1701
- FSE_buildDTable(DTableLL, norm, max, LLlog);
1702
- }
1618
+ { U32 max = MaxLL;
1619
+ headerSize = FSE_readNCount(norm, &max, &LLlog, ip, iend-ip);
1620
+ if (FSE_isError(headerSize)) return ERROR(GENERIC);
1621
+ if (LLlog > LLFSELog) return ERROR(corruption_detected);
1622
+ ip += headerSize;
1623
+ FSE_buildDTable(DTableLL, norm, max, LLlog);
1624
+ } }
1703
1625
 
1704
1626
  switch(Offtype)
1705
1627
  {
1706
- U32 max;
1707
1628
  case bt_rle :
1708
1629
  Offlog = 0;
1709
- if (ip > iend-2) return (size_t)-ZSTD_ERROR_SrcSize; /* min : "raw", hence no header, but at least xxLog bits */
1630
+ if (ip > iend-2) return ERROR(srcSize_wrong); /* min : "raw", hence no header, but at least xxLog bits */
1710
1631
  FSE_buildDTable_rle(DTableOffb, *ip++); break;
1711
1632
  case bt_raw :
1712
1633
  Offlog = Offbits;
1713
1634
  FSE_buildDTable_raw(DTableOffb, Offbits); break;
1714
1635
  default :
1715
- max = MaxOff;
1716
- headerSize = FSE_readNCount(norm, &max, &Offlog, ip, iend-ip);
1717
- if (FSE_isError(headerSize)) return (size_t)-ZSTD_ERROR_GENERIC;
1718
- if (Offlog > OffFSELog) return (size_t)-ZSTD_ERROR_corruption;
1719
- ip += headerSize;
1720
- FSE_buildDTable(DTableOffb, norm, max, Offlog);
1721
- }
1636
+ { U32 max = MaxOff;
1637
+ headerSize = FSE_readNCount(norm, &max, &Offlog, ip, iend-ip);
1638
+ if (FSE_isError(headerSize)) return ERROR(GENERIC);
1639
+ if (Offlog > OffFSELog) return ERROR(corruption_detected);
1640
+ ip += headerSize;
1641
+ FSE_buildDTable(DTableOffb, norm, max, Offlog);
1642
+ } }
1722
1643
 
1723
1644
  switch(MLtype)
1724
1645
  {
1725
- U32 max;
1726
1646
  case bt_rle :
1727
1647
  MLlog = 0;
1728
- if (ip > iend-2) return (size_t)-ZSTD_ERROR_SrcSize; /* min : "raw", hence no header, but at least xxLog bits */
1648
+ if (ip > iend-2) return ERROR(srcSize_wrong); /* min : "raw", hence no header, but at least xxLog bits */
1729
1649
  FSE_buildDTable_rle(DTableML, *ip++); break;
1730
1650
  case bt_raw :
1731
1651
  MLlog = MLbits;
1732
1652
  FSE_buildDTable_raw(DTableML, MLbits); break;
1733
1653
  default :
1734
- max = MaxML;
1735
- headerSize = FSE_readNCount(norm, &max, &MLlog, ip, iend-ip);
1736
- if (FSE_isError(headerSize)) return (size_t)-ZSTD_ERROR_GENERIC;
1737
- if (MLlog > MLFSELog) return (size_t)-ZSTD_ERROR_corruption;
1738
- ip += headerSize;
1739
- FSE_buildDTable(DTableML, norm, max, MLlog);
1740
- }
1741
- }
1654
+ { U32 max = MaxML;
1655
+ headerSize = FSE_readNCount(norm, &max, &MLlog, ip, iend-ip);
1656
+ if (FSE_isError(headerSize)) return ERROR(GENERIC);
1657
+ if (MLlog > MLFSELog) return ERROR(corruption_detected);
1658
+ ip += headerSize;
1659
+ FSE_buildDTable(DTableML, norm, max, MLlog);
1660
+ } } }
1742
1661
 
1743
1662
  return ip-istart;
1744
1663
  }
@@ -1838,9 +1757,9 @@ static size_t ZSTD_execSequence(BYTE* op,
1838
1757
  const BYTE* const litEnd = *litPtr + litLength;
1839
1758
 
1840
1759
  /* check */
1841
- if (endMatch > oend) return (size_t)-ZSTD_ERROR_maxDstSize_tooSmall; /* overwrite beyond dst buffer */
1842
- if (litEnd > litLimit) return (size_t)-ZSTD_ERROR_corruption;
1843
- if (sequence.matchLength > (size_t)(*litPtr-op)) return (size_t)-ZSTD_ERROR_maxDstSize_tooSmall; /* overwrite literal segment */
1760
+ if (endMatch > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
1761
+ if (litEnd > litLimit) return ERROR(corruption_detected);
1762
+ if (sequence.matchLength > (size_t)(*litPtr-op)) return ERROR(dstSize_tooSmall); /* overwrite literal segment */
1844
1763
 
1845
1764
  /* copy Literals */
1846
1765
  if (((size_t)(*litPtr - op) < 8) || ((size_t)(oend-litEnd) < 8) || (op+litLength > oend-8))
@@ -1851,7 +1770,7 @@ static size_t ZSTD_execSequence(BYTE* op,
1851
1770
  *litPtr = litEnd; /* update for next sequence */
1852
1771
 
1853
1772
  /* check : last match must be at a minimum distance of 8 from end of dest buffer */
1854
- if (oend-op < 8) return (size_t)-ZSTD_ERROR_maxDstSize_tooSmall;
1773
+ if (oend-op < 8) return ERROR(dstSize_tooSmall);
1855
1774
 
1856
1775
  /* copy Match */
1857
1776
  {
@@ -1861,8 +1780,8 @@ static size_t ZSTD_execSequence(BYTE* op,
1861
1780
  U64 saved[2];
1862
1781
 
1863
1782
  /* check */
1864
- if (match < base) return (size_t)-ZSTD_ERROR_corruption;
1865
- if (sequence.offset > (size_t)base) return (size_t)-ZSTD_ERROR_corruption;
1783
+ if (match < base) return ERROR(corruption_detected);
1784
+ if (sequence.offset > (size_t)base) return ERROR(corruption_detected);
1866
1785
 
1867
1786
  /* save beginning of literal sequence, in case of write overlap */
1868
1787
  if (overlapRisk)
@@ -1940,10 +1859,10 @@ static size_t ZSTD_decompressSequences(
1940
1859
  BYTE* const base = (BYTE*) (dctx->base);
1941
1860
 
1942
1861
  /* Build Decoding Tables */
1943
- errorCode = ZSTD_decodeSeqHeaders(&nbSeq, &dumps, &dumpsLength,
1862
+ errorCode = ZSTDv01_decodeSeqHeaders(&nbSeq, &dumps, &dumpsLength,
1944
1863
  DTableLL, DTableML, DTableOffb,
1945
1864
  ip, iend-ip);
1946
- if (ZSTD_isError(errorCode)) return errorCode;
1865
+ if (ZSTDv01_isError(errorCode)) return errorCode;
1947
1866
  ip += errorCode;
1948
1867
 
1949
1868
  /* Regen sequences */
@@ -1956,7 +1875,7 @@ static size_t ZSTD_decompressSequences(
1956
1875
  seqState.dumpsEnd = dumps + dumpsLength;
1957
1876
  seqState.prevOffset = 1;
1958
1877
  errorCode = FSE_initDStream(&(seqState.DStream), ip, iend-ip);
1959
- if (FSE_isError(errorCode)) return (size_t)-ZSTD_ERROR_corruption;
1878
+ if (FSE_isError(errorCode)) return ERROR(corruption_detected);
1960
1879
  FSE_initDState(&(seqState.stateLL), &(seqState.DStream), DTableLL);
1961
1880
  FSE_initDState(&(seqState.stateOffb), &(seqState.DStream), DTableOffb);
1962
1881
  FSE_initDState(&(seqState.stateML), &(seqState.DStream), DTableML);
@@ -1967,18 +1886,18 @@ static size_t ZSTD_decompressSequences(
1967
1886
  nbSeq--;
1968
1887
  ZSTD_decodeSequence(&sequence, &seqState);
1969
1888
  oneSeqSize = ZSTD_execSequence(op, sequence, &litPtr, litEnd, base, oend);
1970
- if (ZSTD_isError(oneSeqSize)) return oneSeqSize;
1889
+ if (ZSTDv01_isError(oneSeqSize)) return oneSeqSize;
1971
1890
  op += oneSeqSize;
1972
1891
  }
1973
1892
 
1974
1893
  /* check if reached exact end */
1975
- if ( !FSE_endOfDStream(&(seqState.DStream)) ) return (size_t)-ZSTD_ERROR_corruption; /* requested too much : data is corrupted */
1976
- if (nbSeq<0) return (size_t)-ZSTD_ERROR_corruption; /* requested too many sequences : data is corrupted */
1894
+ if ( !FSE_endOfDStream(&(seqState.DStream)) ) return ERROR(corruption_detected); /* requested too much : data is corrupted */
1895
+ if (nbSeq<0) return ERROR(corruption_detected); /* requested too many sequences : data is corrupted */
1977
1896
 
1978
1897
  /* last literal segment */
1979
1898
  {
1980
1899
  size_t lastLLSize = litEnd - litPtr;
1981
- if (op+lastLLSize > oend) return (size_t)-ZSTD_ERROR_maxDstSize_tooSmall;
1900
+ if (op+lastLLSize > oend) return ERROR(dstSize_tooSmall);
1982
1901
  if (op != litPtr) memmove(op, litPtr, lastLLSize);
1983
1902
  op += lastLLSize;
1984
1903
  }
@@ -2000,8 +1919,8 @@ static size_t ZSTD_decompressBlock(
2000
1919
  size_t errorCode;
2001
1920
 
2002
1921
  /* Decode literals sub-block */
2003
- errorCode = ZSTD_decodeLiteralsBlock(ctx, dst, maxDstSize, &litPtr, &litSize, src, srcSize);
2004
- if (ZSTD_isError(errorCode)) return errorCode;
1922
+ errorCode = ZSTDv01_decodeLiteralsBlock(ctx, dst, maxDstSize, &litPtr, &litSize, src, srcSize);
1923
+ if (ZSTDv01_isError(errorCode)) return errorCode;
2005
1924
  ip += errorCode;
2006
1925
  srcSize -= errorCode;
2007
1926
 
@@ -2022,20 +1941,20 @@ size_t ZSTDv01_decompressDCtx(void* ctx, void* dst, size_t maxDstSize, const voi
2022
1941
  blockProperties_t blockProperties;
2023
1942
 
2024
1943
  /* Frame Header */
2025
- if (srcSize < ZSTD_frameHeaderSize+ZSTD_blockHeaderSize) return (size_t)-ZSTD_ERROR_SrcSize;
1944
+ if (srcSize < ZSTD_frameHeaderSize+ZSTD_blockHeaderSize) return ERROR(srcSize_wrong);
2026
1945
  magicNumber = ZSTD_readBE32(src);
2027
- if (magicNumber != ZSTD_magicNumber) return (size_t)-ZSTD_ERROR_MagicNumber;
1946
+ if (magicNumber != ZSTD_magicNumber) return ERROR(prefix_unknown);
2028
1947
  ip += ZSTD_frameHeaderSize; remainingSize -= ZSTD_frameHeaderSize;
2029
1948
 
2030
1949
  /* Loop on each block */
2031
1950
  while (1)
2032
1951
  {
2033
- size_t blockSize = ZSTD_getcBlockSize(ip, iend-ip, &blockProperties);
2034
- if (ZSTD_isError(blockSize)) return blockSize;
1952
+ size_t blockSize = ZSTDv01_getcBlockSize(ip, iend-ip, &blockProperties);
1953
+ if (ZSTDv01_isError(blockSize)) return blockSize;
2035
1954
 
2036
1955
  ip += ZSTD_blockHeaderSize;
2037
1956
  remainingSize -= ZSTD_blockHeaderSize;
2038
- if (blockSize > remainingSize) return (size_t)-ZSTD_ERROR_SrcSize;
1957
+ if (blockSize > remainingSize) return ERROR(srcSize_wrong);
2039
1958
 
2040
1959
  switch(blockProperties.blockType)
2041
1960
  {
@@ -2046,18 +1965,18 @@ size_t ZSTDv01_decompressDCtx(void* ctx, void* dst, size_t maxDstSize, const voi
2046
1965
  errorCode = ZSTD_copyUncompressedBlock(op, oend-op, ip, blockSize);
2047
1966
  break;
2048
1967
  case bt_rle :
2049
- return (size_t)-ZSTD_ERROR_GENERIC; /* not yet supported */
1968
+ return ERROR(GENERIC); /* not yet supported */
2050
1969
  break;
2051
1970
  case bt_end :
2052
1971
  /* end of frame */
2053
- if (remainingSize) return (size_t)-ZSTD_ERROR_SrcSize;
1972
+ if (remainingSize) return ERROR(srcSize_wrong);
2054
1973
  break;
2055
1974
  default:
2056
- return (size_t)-ZSTD_ERROR_GENERIC;
1975
+ return ERROR(GENERIC);
2057
1976
  }
2058
1977
  if (blockSize == 0) break; /* bt_end */
2059
1978
 
2060
- if (ZSTD_isError(errorCode)) return errorCode;
1979
+ if (ZSTDv01_isError(errorCode)) return errorCode;
2061
1980
  op += errorCode;
2062
1981
  ip += blockSize;
2063
1982
  remainingSize -= blockSize;
@@ -2111,7 +2030,7 @@ size_t ZSTDv01_decompressContinue(ZSTDv01_Dctx* dctx, void* dst, size_t maxDstSi
2111
2030
  dctx_t* ctx = (dctx_t*)dctx;
2112
2031
 
2113
2032
  /* Sanity check */
2114
- if (srcSize != ctx->expected) return (size_t)-ZSTD_ERROR_SrcSize;
2033
+ if (srcSize != ctx->expected) return ERROR(srcSize_wrong);
2115
2034
  if (dst != ctx->previousDstEnd) /* not contiguous */
2116
2035
  ctx->base = dst;
2117
2036
 
@@ -2120,7 +2039,7 @@ size_t ZSTDv01_decompressContinue(ZSTDv01_Dctx* dctx, void* dst, size_t maxDstSi
2120
2039
  {
2121
2040
  /* Check frame magic header */
2122
2041
  U32 magicNumber = ZSTD_readBE32(src);
2123
- if (magicNumber != ZSTD_magicNumber) return (size_t)-ZSTD_ERROR_MagicNumber;
2042
+ if (magicNumber != ZSTD_magicNumber) return ERROR(prefix_unknown);
2124
2043
  ctx->phase = 1;
2125
2044
  ctx->expected = ZSTD_blockHeaderSize;
2126
2045
  return 0;
@@ -2130,8 +2049,8 @@ size_t ZSTDv01_decompressContinue(ZSTDv01_Dctx* dctx, void* dst, size_t maxDstSi
2130
2049
  if (ctx->phase == 1)
2131
2050
  {
2132
2051
  blockProperties_t bp;
2133
- size_t blockSize = ZSTD_getcBlockSize(src, ZSTD_blockHeaderSize, &bp);
2134
- if (ZSTD_isError(blockSize)) return blockSize;
2052
+ size_t blockSize = ZSTDv01_getcBlockSize(src, ZSTD_blockHeaderSize, &bp);
2053
+ if (ZSTDv01_isError(blockSize)) return blockSize;
2135
2054
  if (bp.blockType == bt_end)
2136
2055
  {
2137
2056
  ctx->expected = 0;
@@ -2159,13 +2078,13 @@ size_t ZSTDv01_decompressContinue(ZSTDv01_Dctx* dctx, void* dst, size_t maxDstSi
2159
2078
  rSize = ZSTD_copyUncompressedBlock(dst, maxDstSize, src, srcSize);
2160
2079
  break;
2161
2080
  case bt_rle :
2162
- return (size_t)-ZSTD_ERROR_GENERIC; /* not yet handled */
2081
+ return ERROR(GENERIC); /* not yet handled */
2163
2082
  break;
2164
2083
  case bt_end : /* should never happen (filtered at phase 1) */
2165
2084
  rSize = 0;
2166
2085
  break;
2167
2086
  default:
2168
- return (size_t)-ZSTD_ERROR_GENERIC;
2087
+ return ERROR(GENERIC);
2169
2088
  }
2170
2089
  ctx->phase = 1;
2171
2090
  ctx->expected = ZSTD_blockHeaderSize;
@@ -2174,5 +2093,3 @@ size_t ZSTDv01_decompressContinue(ZSTDv01_Dctx* dctx, void* dst, size_t maxDstSi
2174
2093
  }
2175
2094
 
2176
2095
  }
2177
-
2178
-
@@ -1,36 +1,14 @@
1
- /*
2
- zstd - standard compression library
3
- Header File
4
- Copyright (C) 2014-2015, Yann Collet.
5
-
6
- BSD 2-Clause License (http://www.opensource.org/licenses/bsd-license.php)
1
+ /**
2
+ * Copyright (c) 2016-present, Yann Collet, Facebook, Inc.
3
+ * All rights reserved.
4
+ *
5
+ * This source code is licensed under the BSD-style license found in the
6
+ * LICENSE file in the root directory of this source tree. An additional grant
7
+ * of patent rights can be found in the PATENTS file in the same directory.
8
+ */
7
9
 
8
- Redistribution and use in source and binary forms, with or without
9
- modification, are permitted provided that the following conditions are
10
- met:
11
- * Redistributions of source code must retain the above copyright
12
- notice, this list of conditions and the following disclaimer.
13
- * Redistributions in binary form must reproduce the above
14
- copyright notice, this list of conditions and the following disclaimer
15
- in the documentation and/or other materials provided with the
16
- distribution.
17
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
-
29
- You can contact the author at :
30
- - zstd source repository : https://github.com/Cyan4973/zstd
31
- - ztsd public forum : https://groups.google.com/forum/#!forum/lz4c
32
- */
33
- #pragma once
10
+ #ifndef ZSTD_V01_H_28739879432
11
+ #define ZSTD_V01_H_28739879432
34
12
 
35
13
  #if defined (__cplusplus)
36
14
  extern "C" {
@@ -98,3 +76,5 @@ size_t ZSTDv01_decompressContinue(ZSTDv01_Dctx* dctx, void* dst, size_t maxDstSi
98
76
  #if defined (__cplusplus)
99
77
  }
100
78
  #endif
79
+
80
+ #endif /* ZSTD_V01_H_28739879432 */