laag-xz 5.2.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (393) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +57 -0
  3. data/LICENSE.txt +65 -0
  4. data/README.org +34 -0
  5. data/ext/laag/xz/extconf.rb +21 -0
  6. data/laag-xz.gemspec +20 -0
  7. data/lib/laag/xz.rb +29 -0
  8. data/vendor/git.tukaani.org/xz/.gitignore +66 -0
  9. data/vendor/git.tukaani.org/xz/AUTHORS +27 -0
  10. data/vendor/git.tukaani.org/xz/COPYING +65 -0
  11. data/vendor/git.tukaani.org/xz/COPYING.GPLv2 +339 -0
  12. data/vendor/git.tukaani.org/xz/COPYING.GPLv3 +674 -0
  13. data/vendor/git.tukaani.org/xz/COPYING.LGPLv2.1 +502 -0
  14. data/vendor/git.tukaani.org/xz/ChangeLog +7 -0
  15. data/vendor/git.tukaani.org/xz/Doxyfile.in +1234 -0
  16. data/vendor/git.tukaani.org/xz/INSTALL +618 -0
  17. data/vendor/git.tukaani.org/xz/INSTALL.generic +365 -0
  18. data/vendor/git.tukaani.org/xz/Makefile.am +110 -0
  19. data/vendor/git.tukaani.org/xz/NEWS +571 -0
  20. data/vendor/git.tukaani.org/xz/PACKAGERS +231 -0
  21. data/vendor/git.tukaani.org/xz/README +308 -0
  22. data/vendor/git.tukaani.org/xz/THANKS +124 -0
  23. data/vendor/git.tukaani.org/xz/TODO +111 -0
  24. data/vendor/git.tukaani.org/xz/autogen.sh +22 -0
  25. data/vendor/git.tukaani.org/xz/build-aux/manconv.sh +58 -0
  26. data/vendor/git.tukaani.org/xz/build-aux/version.sh +24 -0
  27. data/vendor/git.tukaani.org/xz/configure.ac +900 -0
  28. data/vendor/git.tukaani.org/xz/debug/Makefile.am +30 -0
  29. data/vendor/git.tukaani.org/xz/debug/README +17 -0
  30. data/vendor/git.tukaani.org/xz/debug/crc32.c +39 -0
  31. data/vendor/git.tukaani.org/xz/debug/full_flush.c +103 -0
  32. data/vendor/git.tukaani.org/xz/debug/hex2bin.c +53 -0
  33. data/vendor/git.tukaani.org/xz/debug/known_sizes.c +129 -0
  34. data/vendor/git.tukaani.org/xz/debug/memusage.c +51 -0
  35. data/vendor/git.tukaani.org/xz/debug/repeat.c +36 -0
  36. data/vendor/git.tukaani.org/xz/debug/sync_flush.c +125 -0
  37. data/vendor/git.tukaani.org/xz/debug/translation.bash +100 -0
  38. data/vendor/git.tukaani.org/xz/doc/examples/00_README.txt +31 -0
  39. data/vendor/git.tukaani.org/xz/doc/examples/01_compress_easy.c +297 -0
  40. data/vendor/git.tukaani.org/xz/doc/examples/02_decompress.c +287 -0
  41. data/vendor/git.tukaani.org/xz/doc/examples/03_compress_custom.c +193 -0
  42. data/vendor/git.tukaani.org/xz/doc/examples/04_compress_easy_mt.c +206 -0
  43. data/vendor/git.tukaani.org/xz/doc/examples/Makefile +24 -0
  44. data/vendor/git.tukaani.org/xz/doc/examples_old/xz_pipe_comp.c +127 -0
  45. data/vendor/git.tukaani.org/xz/doc/examples_old/xz_pipe_decomp.c +123 -0
  46. data/vendor/git.tukaani.org/xz/doc/faq.txt +224 -0
  47. data/vendor/git.tukaani.org/xz/doc/history.txt +150 -0
  48. data/vendor/git.tukaani.org/xz/doc/lzma-file-format.txt +166 -0
  49. data/vendor/git.tukaani.org/xz/doc/xz-file-format.txt +1150 -0
  50. data/vendor/git.tukaani.org/xz/dos/INSTALL.txt +79 -0
  51. data/vendor/git.tukaani.org/xz/dos/Makefile +147 -0
  52. data/vendor/git.tukaani.org/xz/dos/README.txt +123 -0
  53. data/vendor/git.tukaani.org/xz/dos/config.h +136 -0
  54. data/vendor/git.tukaani.org/xz/extra/7z2lzma/7z2lzma.bash +115 -0
  55. data/vendor/git.tukaani.org/xz/extra/scanlzma/scanlzma.c +88 -0
  56. data/vendor/git.tukaani.org/xz/lib/Makefile.am +32 -0
  57. data/vendor/git.tukaani.org/xz/lib/getopt.c +1197 -0
  58. data/vendor/git.tukaani.org/xz/lib/getopt.in.h +226 -0
  59. data/vendor/git.tukaani.org/xz/lib/getopt1.c +171 -0
  60. data/vendor/git.tukaani.org/xz/lib/getopt_int.h +131 -0
  61. data/vendor/git.tukaani.org/xz/m4/.gitignore +38 -0
  62. data/vendor/git.tukaani.org/xz/m4/ax_check_capsicum.m4 +85 -0
  63. data/vendor/git.tukaani.org/xz/m4/ax_pthread.m4 +332 -0
  64. data/vendor/git.tukaani.org/xz/m4/getopt.m4 +71 -0
  65. data/vendor/git.tukaani.org/xz/m4/posix-shell.m4 +63 -0
  66. data/vendor/git.tukaani.org/xz/m4/tuklib_common.m4 +22 -0
  67. data/vendor/git.tukaani.org/xz/m4/tuklib_cpucores.m4 +176 -0
  68. data/vendor/git.tukaani.org/xz/m4/tuklib_integer.m4 +74 -0
  69. data/vendor/git.tukaani.org/xz/m4/tuklib_mbstr.m4 +30 -0
  70. data/vendor/git.tukaani.org/xz/m4/tuklib_physmem.m4 +212 -0
  71. data/vendor/git.tukaani.org/xz/m4/tuklib_progname.m4 +25 -0
  72. data/vendor/git.tukaani.org/xz/macosx/build.sh +113 -0
  73. data/vendor/git.tukaani.org/xz/po/.gitignore +31 -0
  74. data/vendor/git.tukaani.org/xz/po/LINGUAS +6 -0
  75. data/vendor/git.tukaani.org/xz/po/Makevars +46 -0
  76. data/vendor/git.tukaani.org/xz/po/POTFILES.in +13 -0
  77. data/vendor/git.tukaani.org/xz/po/cs.po +949 -0
  78. data/vendor/git.tukaani.org/xz/po/de.po +993 -0
  79. data/vendor/git.tukaani.org/xz/po/fr.po +978 -0
  80. data/vendor/git.tukaani.org/xz/po/it.po +1067 -0
  81. data/vendor/git.tukaani.org/xz/po/pl.po +968 -0
  82. data/vendor/git.tukaani.org/xz/po/vi.po +1039 -0
  83. data/vendor/git.tukaani.org/xz/src/Makefile.am +42 -0
  84. data/vendor/git.tukaani.org/xz/src/common/common_w32res.rc +50 -0
  85. data/vendor/git.tukaani.org/xz/src/common/mythread.h +521 -0
  86. data/vendor/git.tukaani.org/xz/src/common/sysdefs.h +202 -0
  87. data/vendor/git.tukaani.org/xz/src/common/tuklib_common.h +71 -0
  88. data/vendor/git.tukaani.org/xz/src/common/tuklib_config.h +7 -0
  89. data/vendor/git.tukaani.org/xz/src/common/tuklib_cpucores.c +100 -0
  90. data/vendor/git.tukaani.org/xz/src/common/tuklib_cpucores.h +23 -0
  91. data/vendor/git.tukaani.org/xz/src/common/tuklib_exit.c +57 -0
  92. data/vendor/git.tukaani.org/xz/src/common/tuklib_exit.h +25 -0
  93. data/vendor/git.tukaani.org/xz/src/common/tuklib_gettext.h +44 -0
  94. data/vendor/git.tukaani.org/xz/src/common/tuklib_integer.h +534 -0
  95. data/vendor/git.tukaani.org/xz/src/common/tuklib_mbstr.h +66 -0
  96. data/vendor/git.tukaani.org/xz/src/common/tuklib_mbstr_fw.c +31 -0
  97. data/vendor/git.tukaani.org/xz/src/common/tuklib_mbstr_width.c +64 -0
  98. data/vendor/git.tukaani.org/xz/src/common/tuklib_open_stdxxx.c +57 -0
  99. data/vendor/git.tukaani.org/xz/src/common/tuklib_open_stdxxx.h +23 -0
  100. data/vendor/git.tukaani.org/xz/src/common/tuklib_physmem.c +216 -0
  101. data/vendor/git.tukaani.org/xz/src/common/tuklib_physmem.h +28 -0
  102. data/vendor/git.tukaani.org/xz/src/common/tuklib_progname.c +50 -0
  103. data/vendor/git.tukaani.org/xz/src/common/tuklib_progname.h +32 -0
  104. data/vendor/git.tukaani.org/xz/src/liblzma/Makefile.am +122 -0
  105. data/vendor/git.tukaani.org/xz/src/liblzma/api/Makefile.am +23 -0
  106. data/vendor/git.tukaani.org/xz/src/liblzma/api/lzma.h +325 -0
  107. data/vendor/git.tukaani.org/xz/src/liblzma/api/lzma/base.h +659 -0
  108. data/vendor/git.tukaani.org/xz/src/liblzma/api/lzma/bcj.h +90 -0
  109. data/vendor/git.tukaani.org/xz/src/liblzma/api/lzma/block.h +581 -0
  110. data/vendor/git.tukaani.org/xz/src/liblzma/api/lzma/check.h +150 -0
  111. data/vendor/git.tukaani.org/xz/src/liblzma/api/lzma/container.h +632 -0
  112. data/vendor/git.tukaani.org/xz/src/liblzma/api/lzma/delta.h +77 -0
  113. data/vendor/git.tukaani.org/xz/src/liblzma/api/lzma/filter.h +425 -0
  114. data/vendor/git.tukaani.org/xz/src/liblzma/api/lzma/hardware.h +64 -0
  115. data/vendor/git.tukaani.org/xz/src/liblzma/api/lzma/index.h +686 -0
  116. data/vendor/git.tukaani.org/xz/src/liblzma/api/lzma/index_hash.h +107 -0
  117. data/vendor/git.tukaani.org/xz/src/liblzma/api/lzma/lzma12.h +420 -0
  118. data/vendor/git.tukaani.org/xz/src/liblzma/api/lzma/stream_flags.h +223 -0
  119. data/vendor/git.tukaani.org/xz/src/liblzma/api/lzma/version.h +121 -0
  120. data/vendor/git.tukaani.org/xz/src/liblzma/api/lzma/vli.h +166 -0
  121. data/vendor/git.tukaani.org/xz/src/liblzma/check/Makefile.inc +53 -0
  122. data/vendor/git.tukaani.org/xz/src/liblzma/check/check.c +174 -0
  123. data/vendor/git.tukaani.org/xz/src/liblzma/check/check.h +172 -0
  124. data/vendor/git.tukaani.org/xz/src/liblzma/check/crc32_fast.c +82 -0
  125. data/vendor/git.tukaani.org/xz/src/liblzma/check/crc32_small.c +61 -0
  126. data/vendor/git.tukaani.org/xz/src/liblzma/check/crc32_table.c +19 -0
  127. data/vendor/git.tukaani.org/xz/src/liblzma/check/crc32_table_be.h +525 -0
  128. data/vendor/git.tukaani.org/xz/src/liblzma/check/crc32_table_le.h +525 -0
  129. data/vendor/git.tukaani.org/xz/src/liblzma/check/crc32_tablegen.c +117 -0
  130. data/vendor/git.tukaani.org/xz/src/liblzma/check/crc32_x86.S +304 -0
  131. data/vendor/git.tukaani.org/xz/src/liblzma/check/crc64_fast.c +72 -0
  132. data/vendor/git.tukaani.org/xz/src/liblzma/check/crc64_small.c +53 -0
  133. data/vendor/git.tukaani.org/xz/src/liblzma/check/crc64_table.c +19 -0
  134. data/vendor/git.tukaani.org/xz/src/liblzma/check/crc64_table_be.h +521 -0
  135. data/vendor/git.tukaani.org/xz/src/liblzma/check/crc64_table_le.h +521 -0
  136. data/vendor/git.tukaani.org/xz/src/liblzma/check/crc64_tablegen.c +88 -0
  137. data/vendor/git.tukaani.org/xz/src/liblzma/check/crc64_x86.S +287 -0
  138. data/vendor/git.tukaani.org/xz/src/liblzma/check/crc_macros.h +30 -0
  139. data/vendor/git.tukaani.org/xz/src/liblzma/check/sha256.c +196 -0
  140. data/vendor/git.tukaani.org/xz/src/liblzma/common/Makefile.inc +79 -0
  141. data/vendor/git.tukaani.org/xz/src/liblzma/common/alone_decoder.c +243 -0
  142. data/vendor/git.tukaani.org/xz/src/liblzma/common/alone_decoder.h +23 -0
  143. data/vendor/git.tukaani.org/xz/src/liblzma/common/alone_encoder.c +163 -0
  144. data/vendor/git.tukaani.org/xz/src/liblzma/common/auto_decoder.c +195 -0
  145. data/vendor/git.tukaani.org/xz/src/liblzma/common/block_buffer_decoder.c +80 -0
  146. data/vendor/git.tukaani.org/xz/src/liblzma/common/block_buffer_encoder.c +337 -0
  147. data/vendor/git.tukaani.org/xz/src/liblzma/common/block_buffer_encoder.h +24 -0
  148. data/vendor/git.tukaani.org/xz/src/liblzma/common/block_decoder.c +257 -0
  149. data/vendor/git.tukaani.org/xz/src/liblzma/common/block_decoder.h +22 -0
  150. data/vendor/git.tukaani.org/xz/src/liblzma/common/block_encoder.c +223 -0
  151. data/vendor/git.tukaani.org/xz/src/liblzma/common/block_encoder.h +47 -0
  152. data/vendor/git.tukaani.org/xz/src/liblzma/common/block_header_decoder.c +124 -0
  153. data/vendor/git.tukaani.org/xz/src/liblzma/common/block_header_encoder.c +132 -0
  154. data/vendor/git.tukaani.org/xz/src/liblzma/common/block_util.c +90 -0
  155. data/vendor/git.tukaani.org/xz/src/liblzma/common/common.c +445 -0
  156. data/vendor/git.tukaani.org/xz/src/liblzma/common/common.h +314 -0
  157. data/vendor/git.tukaani.org/xz/src/liblzma/common/easy_buffer_encoder.c +27 -0
  158. data/vendor/git.tukaani.org/xz/src/liblzma/common/easy_decoder_memusage.c +24 -0
  159. data/vendor/git.tukaani.org/xz/src/liblzma/common/easy_encoder.c +24 -0
  160. data/vendor/git.tukaani.org/xz/src/liblzma/common/easy_encoder_memusage.c +24 -0
  161. data/vendor/git.tukaani.org/xz/src/liblzma/common/easy_preset.c +27 -0
  162. data/vendor/git.tukaani.org/xz/src/liblzma/common/easy_preset.h +32 -0
  163. data/vendor/git.tukaani.org/xz/src/liblzma/common/filter_buffer_decoder.c +88 -0
  164. data/vendor/git.tukaani.org/xz/src/liblzma/common/filter_buffer_encoder.c +55 -0
  165. data/vendor/git.tukaani.org/xz/src/liblzma/common/filter_common.c +337 -0
  166. data/vendor/git.tukaani.org/xz/src/liblzma/common/filter_common.h +48 -0
  167. data/vendor/git.tukaani.org/xz/src/liblzma/common/filter_decoder.c +184 -0
  168. data/vendor/git.tukaani.org/xz/src/liblzma/common/filter_decoder.h +23 -0
  169. data/vendor/git.tukaani.org/xz/src/liblzma/common/filter_encoder.c +286 -0
  170. data/vendor/git.tukaani.org/xz/src/liblzma/common/filter_encoder.h +27 -0
  171. data/vendor/git.tukaani.org/xz/src/liblzma/common/filter_flags_decoder.c +46 -0
  172. data/vendor/git.tukaani.org/xz/src/liblzma/common/filter_flags_encoder.c +56 -0
  173. data/vendor/git.tukaani.org/xz/src/liblzma/common/hardware_cputhreads.c +22 -0
  174. data/vendor/git.tukaani.org/xz/src/liblzma/common/hardware_physmem.c +25 -0
  175. data/vendor/git.tukaani.org/xz/src/liblzma/common/index.c +1250 -0
  176. data/vendor/git.tukaani.org/xz/src/liblzma/common/index.h +73 -0
  177. data/vendor/git.tukaani.org/xz/src/liblzma/common/index_decoder.c +352 -0
  178. data/vendor/git.tukaani.org/xz/src/liblzma/common/index_encoder.c +256 -0
  179. data/vendor/git.tukaani.org/xz/src/liblzma/common/index_encoder.h +23 -0
  180. data/vendor/git.tukaani.org/xz/src/liblzma/common/index_hash.c +334 -0
  181. data/vendor/git.tukaani.org/xz/src/liblzma/common/memcmplen.h +175 -0
  182. data/vendor/git.tukaani.org/xz/src/liblzma/common/outqueue.c +184 -0
  183. data/vendor/git.tukaani.org/xz/src/liblzma/common/outqueue.h +156 -0
  184. data/vendor/git.tukaani.org/xz/src/liblzma/common/stream_buffer_decoder.c +91 -0
  185. data/vendor/git.tukaani.org/xz/src/liblzma/common/stream_buffer_encoder.c +141 -0
  186. data/vendor/git.tukaani.org/xz/src/liblzma/common/stream_decoder.c +467 -0
  187. data/vendor/git.tukaani.org/xz/src/liblzma/common/stream_decoder.h +22 -0
  188. data/vendor/git.tukaani.org/xz/src/liblzma/common/stream_encoder.c +340 -0
  189. data/vendor/git.tukaani.org/xz/src/liblzma/common/stream_encoder_mt.c +1143 -0
  190. data/vendor/git.tukaani.org/xz/src/liblzma/common/stream_flags_common.c +47 -0
  191. data/vendor/git.tukaani.org/xz/src/liblzma/common/stream_flags_common.h +33 -0
  192. data/vendor/git.tukaani.org/xz/src/liblzma/common/stream_flags_decoder.c +82 -0
  193. data/vendor/git.tukaani.org/xz/src/liblzma/common/stream_flags_encoder.c +86 -0
  194. data/vendor/git.tukaani.org/xz/src/liblzma/common/vli_decoder.c +86 -0
  195. data/vendor/git.tukaani.org/xz/src/liblzma/common/vli_encoder.c +69 -0
  196. data/vendor/git.tukaani.org/xz/src/liblzma/common/vli_size.c +30 -0
  197. data/vendor/git.tukaani.org/xz/src/liblzma/delta/Makefile.inc +23 -0
  198. data/vendor/git.tukaani.org/xz/src/liblzma/delta/delta_common.c +73 -0
  199. data/vendor/git.tukaani.org/xz/src/liblzma/delta/delta_common.h +20 -0
  200. data/vendor/git.tukaani.org/xz/src/liblzma/delta/delta_decoder.c +78 -0
  201. data/vendor/git.tukaani.org/xz/src/liblzma/delta/delta_decoder.h +26 -0
  202. data/vendor/git.tukaani.org/xz/src/liblzma/delta/delta_encoder.c +125 -0
  203. data/vendor/git.tukaani.org/xz/src/liblzma/delta/delta_encoder.h +24 -0
  204. data/vendor/git.tukaani.org/xz/src/liblzma/delta/delta_private.h +37 -0
  205. data/vendor/git.tukaani.org/xz/src/liblzma/liblzma.map +108 -0
  206. data/vendor/git.tukaani.org/xz/src/liblzma/liblzma.pc.in +19 -0
  207. data/vendor/git.tukaani.org/xz/src/liblzma/liblzma_w32res.rc +12 -0
  208. data/vendor/git.tukaani.org/xz/src/liblzma/lz/Makefile.inc +22 -0
  209. data/vendor/git.tukaani.org/xz/src/liblzma/lz/lz_decoder.c +306 -0
  210. data/vendor/git.tukaani.org/xz/src/liblzma/lz/lz_decoder.h +234 -0
  211. data/vendor/git.tukaani.org/xz/src/liblzma/lz/lz_encoder.c +616 -0
  212. data/vendor/git.tukaani.org/xz/src/liblzma/lz/lz_encoder.h +327 -0
  213. data/vendor/git.tukaani.org/xz/src/liblzma/lz/lz_encoder_hash.h +108 -0
  214. data/vendor/git.tukaani.org/xz/src/liblzma/lz/lz_encoder_hash_table.h +68 -0
  215. data/vendor/git.tukaani.org/xz/src/liblzma/lz/lz_encoder_mf.c +744 -0
  216. data/vendor/git.tukaani.org/xz/src/liblzma/lzma/Makefile.inc +47 -0
  217. data/vendor/git.tukaani.org/xz/src/liblzma/lzma/fastpos.h +141 -0
  218. data/vendor/git.tukaani.org/xz/src/liblzma/lzma/fastpos_table.c +519 -0
  219. data/vendor/git.tukaani.org/xz/src/liblzma/lzma/fastpos_tablegen.c +56 -0
  220. data/vendor/git.tukaani.org/xz/src/liblzma/lzma/lzma2_decoder.c +310 -0
  221. data/vendor/git.tukaani.org/xz/src/liblzma/lzma/lzma2_decoder.h +29 -0
  222. data/vendor/git.tukaani.org/xz/src/liblzma/lzma/lzma2_encoder.c +410 -0
  223. data/vendor/git.tukaani.org/xz/src/liblzma/lzma/lzma2_encoder.h +43 -0
  224. data/vendor/git.tukaani.org/xz/src/liblzma/lzma/lzma_common.h +224 -0
  225. data/vendor/git.tukaani.org/xz/src/liblzma/lzma/lzma_decoder.c +1064 -0
  226. data/vendor/git.tukaani.org/xz/src/liblzma/lzma/lzma_decoder.h +53 -0
  227. data/vendor/git.tukaani.org/xz/src/liblzma/lzma/lzma_encoder.c +677 -0
  228. data/vendor/git.tukaani.org/xz/src/liblzma/lzma/lzma_encoder.h +58 -0
  229. data/vendor/git.tukaani.org/xz/src/liblzma/lzma/lzma_encoder_optimum_fast.c +170 -0
  230. data/vendor/git.tukaani.org/xz/src/liblzma/lzma/lzma_encoder_optimum_normal.c +855 -0
  231. data/vendor/git.tukaani.org/xz/src/liblzma/lzma/lzma_encoder_presets.c +64 -0
  232. data/vendor/git.tukaani.org/xz/src/liblzma/lzma/lzma_encoder_private.h +148 -0
  233. data/vendor/git.tukaani.org/xz/src/liblzma/rangecoder/Makefile.inc +21 -0
  234. data/vendor/git.tukaani.org/xz/src/liblzma/rangecoder/price.h +92 -0
  235. data/vendor/git.tukaani.org/xz/src/liblzma/rangecoder/price_table.c +22 -0
  236. data/vendor/git.tukaani.org/xz/src/liblzma/rangecoder/price_tablegen.c +87 -0
  237. data/vendor/git.tukaani.org/xz/src/liblzma/rangecoder/range_common.h +71 -0
  238. data/vendor/git.tukaani.org/xz/src/liblzma/rangecoder/range_decoder.h +185 -0
  239. data/vendor/git.tukaani.org/xz/src/liblzma/rangecoder/range_encoder.h +231 -0
  240. data/vendor/git.tukaani.org/xz/src/liblzma/simple/Makefile.inc +47 -0
  241. data/vendor/git.tukaani.org/xz/src/liblzma/simple/arm.c +71 -0
  242. data/vendor/git.tukaani.org/xz/src/liblzma/simple/armthumb.c +76 -0
  243. data/vendor/git.tukaani.org/xz/src/liblzma/simple/ia64.c +112 -0
  244. data/vendor/git.tukaani.org/xz/src/liblzma/simple/powerpc.c +75 -0
  245. data/vendor/git.tukaani.org/xz/src/liblzma/simple/simple_coder.c +282 -0
  246. data/vendor/git.tukaani.org/xz/src/liblzma/simple/simple_coder.h +72 -0
  247. data/vendor/git.tukaani.org/xz/src/liblzma/simple/simple_decoder.c +40 -0
  248. data/vendor/git.tukaani.org/xz/src/liblzma/simple/simple_decoder.h +22 -0
  249. data/vendor/git.tukaani.org/xz/src/liblzma/simple/simple_encoder.c +38 -0
  250. data/vendor/git.tukaani.org/xz/src/liblzma/simple/simple_encoder.h +23 -0
  251. data/vendor/git.tukaani.org/xz/src/liblzma/simple/simple_private.h +74 -0
  252. data/vendor/git.tukaani.org/xz/src/liblzma/simple/sparc.c +83 -0
  253. data/vendor/git.tukaani.org/xz/src/liblzma/simple/x86.c +159 -0
  254. data/vendor/git.tukaani.org/xz/src/liblzma/validate_map.sh +68 -0
  255. data/vendor/git.tukaani.org/xz/src/lzmainfo/Makefile.am +39 -0
  256. data/vendor/git.tukaani.org/xz/src/lzmainfo/lzmainfo.1 +60 -0
  257. data/vendor/git.tukaani.org/xz/src/lzmainfo/lzmainfo.c +219 -0
  258. data/vendor/git.tukaani.org/xz/src/lzmainfo/lzmainfo_w32res.rc +12 -0
  259. data/vendor/git.tukaani.org/xz/src/scripts/Makefile.am +55 -0
  260. data/vendor/git.tukaani.org/xz/src/scripts/xzdiff.1 +77 -0
  261. data/vendor/git.tukaani.org/xz/src/scripts/xzdiff.in +200 -0
  262. data/vendor/git.tukaani.org/xz/src/scripts/xzgrep.1 +98 -0
  263. data/vendor/git.tukaani.org/xz/src/scripts/xzgrep.in +215 -0
  264. data/vendor/git.tukaani.org/xz/src/scripts/xzless.1 +69 -0
  265. data/vendor/git.tukaani.org/xz/src/scripts/xzless.in +58 -0
  266. data/vendor/git.tukaani.org/xz/src/scripts/xzmore.1 +55 -0
  267. data/vendor/git.tukaani.org/xz/src/scripts/xzmore.in +78 -0
  268. data/vendor/git.tukaani.org/xz/src/xz/Makefile.am +111 -0
  269. data/vendor/git.tukaani.org/xz/src/xz/args.c +700 -0
  270. data/vendor/git.tukaani.org/xz/src/xz/args.h +44 -0
  271. data/vendor/git.tukaani.org/xz/src/xz/coder.c +936 -0
  272. data/vendor/git.tukaani.org/xz/src/xz/coder.h +76 -0
  273. data/vendor/git.tukaani.org/xz/src/xz/file_io.c +1300 -0
  274. data/vendor/git.tukaani.org/xz/src/xz/file_io.h +156 -0
  275. data/vendor/git.tukaani.org/xz/src/xz/hardware.c +150 -0
  276. data/vendor/git.tukaani.org/xz/src/xz/hardware.h +37 -0
  277. data/vendor/git.tukaani.org/xz/src/xz/list.c +1192 -0
  278. data/vendor/git.tukaani.org/xz/src/xz/list.h +18 -0
  279. data/vendor/git.tukaani.org/xz/src/xz/main.c +330 -0
  280. data/vendor/git.tukaani.org/xz/src/xz/main.h +30 -0
  281. data/vendor/git.tukaani.org/xz/src/xz/message.c +1258 -0
  282. data/vendor/git.tukaani.org/xz/src/xz/message.h +167 -0
  283. data/vendor/git.tukaani.org/xz/src/xz/mytime.c +89 -0
  284. data/vendor/git.tukaani.org/xz/src/xz/mytime.h +47 -0
  285. data/vendor/git.tukaani.org/xz/src/xz/options.c +363 -0
  286. data/vendor/git.tukaani.org/xz/src/xz/options.h +31 -0
  287. data/vendor/git.tukaani.org/xz/src/xz/private.h +66 -0
  288. data/vendor/git.tukaani.org/xz/src/xz/signals.c +209 -0
  289. data/vendor/git.tukaani.org/xz/src/xz/signals.h +43 -0
  290. data/vendor/git.tukaani.org/xz/src/xz/suffix.c +399 -0
  291. data/vendor/git.tukaani.org/xz/src/xz/suffix.h +28 -0
  292. data/vendor/git.tukaani.org/xz/src/xz/util.c +288 -0
  293. data/vendor/git.tukaani.org/xz/src/xz/util.h +123 -0
  294. data/vendor/git.tukaani.org/xz/src/xz/xz.1 +2786 -0
  295. data/vendor/git.tukaani.org/xz/src/xz/xz_w32res.rc +12 -0
  296. data/vendor/git.tukaani.org/xz/src/xzdec/Makefile.am +82 -0
  297. data/vendor/git.tukaani.org/xz/src/xzdec/lzmadec_w32res.rc +12 -0
  298. data/vendor/git.tukaani.org/xz/src/xzdec/xzdec.1 +146 -0
  299. data/vendor/git.tukaani.org/xz/src/xzdec/xzdec.c +323 -0
  300. data/vendor/git.tukaani.org/xz/src/xzdec/xzdec_w32res.rc +12 -0
  301. data/vendor/git.tukaani.org/xz/tests/Makefile.am +57 -0
  302. data/vendor/git.tukaani.org/xz/tests/bcj_test.c +65 -0
  303. data/vendor/git.tukaani.org/xz/tests/compress_prepared_bcj_sparc +0 -0
  304. data/vendor/git.tukaani.org/xz/tests/compress_prepared_bcj_x86 +0 -0
  305. data/vendor/git.tukaani.org/xz/tests/create_compress_files.c +158 -0
  306. data/vendor/git.tukaani.org/xz/tests/files/README +240 -0
  307. data/vendor/git.tukaani.org/xz/tests/files/bad-0-backward_size.xz +0 -0
  308. data/vendor/git.tukaani.org/xz/tests/files/bad-0-empty-truncated.xz +0 -0
  309. data/vendor/git.tukaani.org/xz/tests/files/bad-0-footer_magic.xz +0 -0
  310. data/vendor/git.tukaani.org/xz/tests/files/bad-0-header_magic.xz +0 -0
  311. data/vendor/git.tukaani.org/xz/tests/files/bad-0-nonempty_index.xz +0 -0
  312. data/vendor/git.tukaani.org/xz/tests/files/bad-0cat-alone.xz +0 -0
  313. data/vendor/git.tukaani.org/xz/tests/files/bad-0cat-header_magic.xz +0 -0
  314. data/vendor/git.tukaani.org/xz/tests/files/bad-0catpad-empty.xz +0 -0
  315. data/vendor/git.tukaani.org/xz/tests/files/bad-0pad-empty.xz +0 -0
  316. data/vendor/git.tukaani.org/xz/tests/files/bad-1-block_header-1.xz +0 -0
  317. data/vendor/git.tukaani.org/xz/tests/files/bad-1-block_header-2.xz +0 -0
  318. data/vendor/git.tukaani.org/xz/tests/files/bad-1-block_header-3.xz +0 -0
  319. data/vendor/git.tukaani.org/xz/tests/files/bad-1-block_header-4.xz +0 -0
  320. data/vendor/git.tukaani.org/xz/tests/files/bad-1-block_header-5.xz +0 -0
  321. data/vendor/git.tukaani.org/xz/tests/files/bad-1-block_header-6.xz +0 -0
  322. data/vendor/git.tukaani.org/xz/tests/files/bad-1-check-crc32.xz +0 -0
  323. data/vendor/git.tukaani.org/xz/tests/files/bad-1-check-crc64.xz +0 -0
  324. data/vendor/git.tukaani.org/xz/tests/files/bad-1-check-sha256.xz +0 -0
  325. data/vendor/git.tukaani.org/xz/tests/files/bad-1-lzma2-1.xz +0 -0
  326. data/vendor/git.tukaani.org/xz/tests/files/bad-1-lzma2-2.xz +0 -0
  327. data/vendor/git.tukaani.org/xz/tests/files/bad-1-lzma2-3.xz +0 -0
  328. data/vendor/git.tukaani.org/xz/tests/files/bad-1-lzma2-4.xz +0 -0
  329. data/vendor/git.tukaani.org/xz/tests/files/bad-1-lzma2-5.xz +0 -0
  330. data/vendor/git.tukaani.org/xz/tests/files/bad-1-lzma2-6.xz +0 -0
  331. data/vendor/git.tukaani.org/xz/tests/files/bad-1-lzma2-7.xz +0 -0
  332. data/vendor/git.tukaani.org/xz/tests/files/bad-1-lzma2-8.xz +0 -0
  333. data/vendor/git.tukaani.org/xz/tests/files/bad-1-stream_flags-1.xz +0 -0
  334. data/vendor/git.tukaani.org/xz/tests/files/bad-1-stream_flags-2.xz +0 -0
  335. data/vendor/git.tukaani.org/xz/tests/files/bad-1-stream_flags-3.xz +0 -0
  336. data/vendor/git.tukaani.org/xz/tests/files/bad-1-vli-1.xz +0 -0
  337. data/vendor/git.tukaani.org/xz/tests/files/bad-1-vli-2.xz +0 -0
  338. data/vendor/git.tukaani.org/xz/tests/files/bad-2-compressed_data_padding.xz +0 -0
  339. data/vendor/git.tukaani.org/xz/tests/files/bad-2-index-1.xz +0 -0
  340. data/vendor/git.tukaani.org/xz/tests/files/bad-2-index-2.xz +0 -0
  341. data/vendor/git.tukaani.org/xz/tests/files/bad-2-index-3.xz +0 -0
  342. data/vendor/git.tukaani.org/xz/tests/files/bad-2-index-4.xz +0 -0
  343. data/vendor/git.tukaani.org/xz/tests/files/bad-2-index-5.xz +0 -0
  344. data/vendor/git.tukaani.org/xz/tests/files/good-0-empty.xz +0 -0
  345. data/vendor/git.tukaani.org/xz/tests/files/good-0cat-empty.xz +0 -0
  346. data/vendor/git.tukaani.org/xz/tests/files/good-0catpad-empty.xz +0 -0
  347. data/vendor/git.tukaani.org/xz/tests/files/good-0pad-empty.xz +0 -0
  348. data/vendor/git.tukaani.org/xz/tests/files/good-1-3delta-lzma2.xz +0 -0
  349. data/vendor/git.tukaani.org/xz/tests/files/good-1-block_header-1.xz +0 -0
  350. data/vendor/git.tukaani.org/xz/tests/files/good-1-block_header-2.xz +0 -0
  351. data/vendor/git.tukaani.org/xz/tests/files/good-1-block_header-3.xz +0 -0
  352. data/vendor/git.tukaani.org/xz/tests/files/good-1-check-crc32.xz +0 -0
  353. data/vendor/git.tukaani.org/xz/tests/files/good-1-check-crc64.xz +0 -0
  354. data/vendor/git.tukaani.org/xz/tests/files/good-1-check-none.xz +0 -0
  355. data/vendor/git.tukaani.org/xz/tests/files/good-1-check-sha256.xz +0 -0
  356. data/vendor/git.tukaani.org/xz/tests/files/good-1-delta-lzma2.tiff.xz +0 -0
  357. data/vendor/git.tukaani.org/xz/tests/files/good-1-lzma2-1.xz +0 -0
  358. data/vendor/git.tukaani.org/xz/tests/files/good-1-lzma2-2.xz +0 -0
  359. data/vendor/git.tukaani.org/xz/tests/files/good-1-lzma2-3.xz +0 -0
  360. data/vendor/git.tukaani.org/xz/tests/files/good-1-lzma2-4.xz +0 -0
  361. data/vendor/git.tukaani.org/xz/tests/files/good-1-lzma2-5.xz +0 -0
  362. data/vendor/git.tukaani.org/xz/tests/files/good-1-sparc-lzma2.xz +0 -0
  363. data/vendor/git.tukaani.org/xz/tests/files/good-1-x86-lzma2.xz +0 -0
  364. data/vendor/git.tukaani.org/xz/tests/files/good-2-lzma2.xz +0 -0
  365. data/vendor/git.tukaani.org/xz/tests/files/unsupported-block_header.xz +0 -0
  366. data/vendor/git.tukaani.org/xz/tests/files/unsupported-check.xz +0 -0
  367. data/vendor/git.tukaani.org/xz/tests/files/unsupported-filter_flags-1.xz +0 -0
  368. data/vendor/git.tukaani.org/xz/tests/files/unsupported-filter_flags-2.xz +0 -0
  369. data/vendor/git.tukaani.org/xz/tests/files/unsupported-filter_flags-3.xz +0 -0
  370. data/vendor/git.tukaani.org/xz/tests/test_bcj_exact_size.c +113 -0
  371. data/vendor/git.tukaani.org/xz/tests/test_block_header.c +240 -0
  372. data/vendor/git.tukaani.org/xz/tests/test_check.c +83 -0
  373. data/vendor/git.tukaani.org/xz/tests/test_compress.sh +142 -0
  374. data/vendor/git.tukaani.org/xz/tests/test_files.sh +57 -0
  375. data/vendor/git.tukaani.org/xz/tests/test_filter_flags.c +258 -0
  376. data/vendor/git.tukaani.org/xz/tests/test_index.c +689 -0
  377. data/vendor/git.tukaani.org/xz/tests/test_scripts.sh +76 -0
  378. data/vendor/git.tukaani.org/xz/tests/test_stream_flags.c +180 -0
  379. data/vendor/git.tukaani.org/xz/tests/tests.h +124 -0
  380. data/vendor/git.tukaani.org/xz/tests/xzgrep_expected_output +39 -0
  381. data/vendor/git.tukaani.org/xz/windows/INSTALL-MSVC.txt +47 -0
  382. data/vendor/git.tukaani.org/xz/windows/INSTALL-MinGW.txt +138 -0
  383. data/vendor/git.tukaani.org/xz/windows/README-Windows.txt +122 -0
  384. data/vendor/git.tukaani.org/xz/windows/build.bash +203 -0
  385. data/vendor/git.tukaani.org/xz/windows/vs2013/config.h +148 -0
  386. data/vendor/git.tukaani.org/xz/windows/vs2013/liblzma.vcxproj +354 -0
  387. data/vendor/git.tukaani.org/xz/windows/vs2013/liblzma_dll.vcxproj +383 -0
  388. data/vendor/git.tukaani.org/xz/windows/vs2013/xz_win.sln +48 -0
  389. data/vendor/git.tukaani.org/xz/windows/vs2017/config.h +148 -0
  390. data/vendor/git.tukaani.org/xz/windows/vs2017/liblzma.vcxproj +355 -0
  391. data/vendor/git.tukaani.org/xz/windows/vs2017/liblzma_dll.vcxproj +384 -0
  392. data/vendor/git.tukaani.org/xz/windows/vs2017/xz_win.sln +48 -0
  393. metadata +457 -0
@@ -0,0 +1,43 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ /// \file lzma2_encoder.h
4
+ /// \brief LZMA2 encoder
5
+ ///
6
+ // Authors: Igor Pavlov
7
+ // Lasse Collin
8
+ //
9
+ // This file has been put into the public domain.
10
+ // You can do whatever you want with this file.
11
+ //
12
+ ///////////////////////////////////////////////////////////////////////////////
13
+
14
+ #ifndef LZMA_LZMA2_ENCODER_H
15
+ #define LZMA_LZMA2_ENCODER_H
16
+
17
+ #include "common.h"
18
+
19
+
20
+ /// Maximum number of bytes of actual data per chunk (no headers)
21
+ #define LZMA2_CHUNK_MAX (UINT32_C(1) << 16)
22
+
23
+ /// Maximum uncompressed size of LZMA chunk (no headers)
24
+ #define LZMA2_UNCOMPRESSED_MAX (UINT32_C(1) << 21)
25
+
26
+ /// Maximum size of LZMA2 headers
27
+ #define LZMA2_HEADER_MAX 6
28
+
29
+ /// Size of a header for uncompressed chunk
30
+ #define LZMA2_HEADER_UNCOMPRESSED 3
31
+
32
+
33
+ extern lzma_ret lzma_lzma2_encoder_init(
34
+ lzma_next_coder *next, const lzma_allocator *allocator,
35
+ const lzma_filter_info *filters);
36
+
37
+ extern uint64_t lzma_lzma2_encoder_memusage(const void *options);
38
+
39
+ extern lzma_ret lzma_lzma2_props_encode(const void *options, uint8_t *out);
40
+
41
+ extern uint64_t lzma_lzma2_block_size(const void *options);
42
+
43
+ #endif
@@ -0,0 +1,224 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ /// \file lzma_common.h
4
+ /// \brief Private definitions common to LZMA encoder and decoder
5
+ ///
6
+ // Authors: Igor Pavlov
7
+ // Lasse Collin
8
+ //
9
+ // This file has been put into the public domain.
10
+ // You can do whatever you want with this file.
11
+ //
12
+ ///////////////////////////////////////////////////////////////////////////////
13
+
14
+ #ifndef LZMA_LZMA_COMMON_H
15
+ #define LZMA_LZMA_COMMON_H
16
+
17
+ #include "common.h"
18
+ #include "range_common.h"
19
+
20
+
21
+ ///////////////////
22
+ // Miscellaneous //
23
+ ///////////////////
24
+
25
+ /// Maximum number of position states. A position state is the lowest pos bits
26
+ /// number of bits of the current uncompressed offset. In some places there
27
+ /// are different sets of probabilities for different pos states.
28
+ #define POS_STATES_MAX (1 << LZMA_PB_MAX)
29
+
30
+
31
+ /// Validates lc, lp, and pb.
32
+ static inline bool
33
+ is_lclppb_valid(const lzma_options_lzma *options)
34
+ {
35
+ return options->lc <= LZMA_LCLP_MAX && options->lp <= LZMA_LCLP_MAX
36
+ && options->lc + options->lp <= LZMA_LCLP_MAX
37
+ && options->pb <= LZMA_PB_MAX;
38
+ }
39
+
40
+
41
+ ///////////
42
+ // State //
43
+ ///////////
44
+
45
+ /// This enum is used to track which events have occurred most recently and
46
+ /// in which order. This information is used to predict the next event.
47
+ ///
48
+ /// Events:
49
+ /// - Literal: One 8-bit byte
50
+ /// - Match: Repeat a chunk of data at some distance
51
+ /// - Long repeat: Multi-byte match at a recently seen distance
52
+ /// - Short repeat: One-byte repeat at a recently seen distance
53
+ ///
54
+ /// The event names are in from STATE_oldest_older_previous. REP means
55
+ /// either short or long repeated match, and NONLIT means any non-literal.
56
+ typedef enum {
57
+ STATE_LIT_LIT,
58
+ STATE_MATCH_LIT_LIT,
59
+ STATE_REP_LIT_LIT,
60
+ STATE_SHORTREP_LIT_LIT,
61
+ STATE_MATCH_LIT,
62
+ STATE_REP_LIT,
63
+ STATE_SHORTREP_LIT,
64
+ STATE_LIT_MATCH,
65
+ STATE_LIT_LONGREP,
66
+ STATE_LIT_SHORTREP,
67
+ STATE_NONLIT_MATCH,
68
+ STATE_NONLIT_REP,
69
+ } lzma_lzma_state;
70
+
71
+
72
+ /// Total number of states
73
+ #define STATES 12
74
+
75
+ /// The lowest 7 states indicate that the previous state was a literal.
76
+ #define LIT_STATES 7
77
+
78
+
79
+ /// Indicate that the latest state was a literal.
80
+ #define update_literal(state) \
81
+ state = ((state) <= STATE_SHORTREP_LIT_LIT \
82
+ ? STATE_LIT_LIT \
83
+ : ((state) <= STATE_LIT_SHORTREP \
84
+ ? (state) - 3 \
85
+ : (state) - 6))
86
+
87
+ /// Indicate that the latest state was a match.
88
+ #define update_match(state) \
89
+ state = ((state) < LIT_STATES ? STATE_LIT_MATCH : STATE_NONLIT_MATCH)
90
+
91
+ /// Indicate that the latest state was a long repeated match.
92
+ #define update_long_rep(state) \
93
+ state = ((state) < LIT_STATES ? STATE_LIT_LONGREP : STATE_NONLIT_REP)
94
+
95
+ /// Indicate that the latest state was a short match.
96
+ #define update_short_rep(state) \
97
+ state = ((state) < LIT_STATES ? STATE_LIT_SHORTREP : STATE_NONLIT_REP)
98
+
99
+ /// Test if the previous state was a literal.
100
+ #define is_literal_state(state) \
101
+ ((state) < LIT_STATES)
102
+
103
+
104
+ /////////////
105
+ // Literal //
106
+ /////////////
107
+
108
+ /// Each literal coder is divided in three sections:
109
+ /// - 0x001-0x0FF: Without match byte
110
+ /// - 0x101-0x1FF: With match byte; match bit is 0
111
+ /// - 0x201-0x2FF: With match byte; match bit is 1
112
+ ///
113
+ /// Match byte is used when the previous LZMA symbol was something else than
114
+ /// a literal (that is, it was some kind of match).
115
+ #define LITERAL_CODER_SIZE 0x300
116
+
117
+ /// Maximum number of literal coders
118
+ #define LITERAL_CODERS_MAX (1 << LZMA_LCLP_MAX)
119
+
120
+ /// Locate the literal coder for the next literal byte. The choice depends on
121
+ /// - the lowest literal_pos_bits bits of the position of the current
122
+ /// byte; and
123
+ /// - the highest literal_context_bits bits of the previous byte.
124
+ #define literal_subcoder(probs, lc, lp_mask, pos, prev_byte) \
125
+ ((probs)[(((pos) & lp_mask) << lc) + ((prev_byte) >> (8 - lc))])
126
+
127
+
128
+ static inline void
129
+ literal_init(probability (*probs)[LITERAL_CODER_SIZE],
130
+ uint32_t lc, uint32_t lp)
131
+ {
132
+ assert(lc + lp <= LZMA_LCLP_MAX);
133
+
134
+ const uint32_t coders = 1U << (lc + lp);
135
+
136
+ for (uint32_t i = 0; i < coders; ++i)
137
+ for (uint32_t j = 0; j < LITERAL_CODER_SIZE; ++j)
138
+ bit_reset(probs[i][j]);
139
+
140
+ return;
141
+ }
142
+
143
+
144
+ //////////////////
145
+ // Match length //
146
+ //////////////////
147
+
148
+ // Minimum length of a match is two bytes.
149
+ #define MATCH_LEN_MIN 2
150
+
151
+ // Match length is encoded with 4, 5, or 10 bits.
152
+ //
153
+ // Length Bits
154
+ // 2-9 4 = Choice=0 + 3 bits
155
+ // 10-17 5 = Choice=1 + Choice2=0 + 3 bits
156
+ // 18-273 10 = Choice=1 + Choice2=1 + 8 bits
157
+ #define LEN_LOW_BITS 3
158
+ #define LEN_LOW_SYMBOLS (1 << LEN_LOW_BITS)
159
+ #define LEN_MID_BITS 3
160
+ #define LEN_MID_SYMBOLS (1 << LEN_MID_BITS)
161
+ #define LEN_HIGH_BITS 8
162
+ #define LEN_HIGH_SYMBOLS (1 << LEN_HIGH_BITS)
163
+ #define LEN_SYMBOLS (LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS + LEN_HIGH_SYMBOLS)
164
+
165
+ // Maximum length of a match is 273 which is a result of the encoding
166
+ // described above.
167
+ #define MATCH_LEN_MAX (MATCH_LEN_MIN + LEN_SYMBOLS - 1)
168
+
169
+
170
+ ////////////////////
171
+ // Match distance //
172
+ ////////////////////
173
+
174
+ // Different sets of probabilities are used for match distances that have very
175
+ // short match length: Lengths of 2, 3, and 4 bytes have a separate set of
176
+ // probabilities for each length. The matches with longer length use a shared
177
+ // set of probabilities.
178
+ #define DIST_STATES 4
179
+
180
+ // Macro to get the index of the appropriate probability array.
181
+ #define get_dist_state(len) \
182
+ ((len) < DIST_STATES + MATCH_LEN_MIN \
183
+ ? (len) - MATCH_LEN_MIN \
184
+ : DIST_STATES - 1)
185
+
186
+ // The highest two bits of a match distance (distance slot) are encoded
187
+ // using six bits. See fastpos.h for more explanation.
188
+ #define DIST_SLOT_BITS 6
189
+ #define DIST_SLOTS (1 << DIST_SLOT_BITS)
190
+
191
+ // Match distances up to 127 are fully encoded using probabilities. Since
192
+ // the highest two bits (distance slot) are always encoded using six bits,
193
+ // the distances 0-3 don't need any additional bits to encode, since the
194
+ // distance slot itself is the same as the actual distance. DIST_MODEL_START
195
+ // indicates the first distance slot where at least one additional bit is
196
+ // needed.
197
+ #define DIST_MODEL_START 4
198
+
199
+ // Match distances greater than 127 are encoded in three pieces:
200
+ // - distance slot: the highest two bits
201
+ // - direct bits: 2-26 bits below the highest two bits
202
+ // - alignment bits: four lowest bits
203
+ //
204
+ // Direct bits don't use any probabilities.
205
+ //
206
+ // The distance slot value of 14 is for distances 128-191 (see the table in
207
+ // fastpos.h to understand why).
208
+ #define DIST_MODEL_END 14
209
+
210
+ // Distance slots that indicate a distance <= 127.
211
+ #define FULL_DISTANCES_BITS (DIST_MODEL_END / 2)
212
+ #define FULL_DISTANCES (1 << FULL_DISTANCES_BITS)
213
+
214
+ // For match distances greater than 127, only the highest two bits and the
215
+ // lowest four bits (alignment) is encoded using probabilities.
216
+ #define ALIGN_BITS 4
217
+ #define ALIGN_SIZE (1 << ALIGN_BITS)
218
+ #define ALIGN_MASK (ALIGN_SIZE - 1)
219
+
220
+ // LZMA remembers the four most recent match distances. Reusing these distances
221
+ // tends to take less space than re-encoding the actual distance value.
222
+ #define REPS 4
223
+
224
+ #endif
@@ -0,0 +1,1064 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ //
3
+ /// \file lzma_decoder.c
4
+ /// \brief LZMA decoder
5
+ ///
6
+ // Authors: Igor Pavlov
7
+ // Lasse Collin
8
+ //
9
+ // This file has been put into the public domain.
10
+ // You can do whatever you want with this file.
11
+ //
12
+ ///////////////////////////////////////////////////////////////////////////////
13
+
14
+ #include "lz_decoder.h"
15
+ #include "lzma_common.h"
16
+ #include "lzma_decoder.h"
17
+ #include "range_decoder.h"
18
+
19
+ // The macros unroll loops with switch statements.
20
+ // Silence warnings about missing fall-through comments.
21
+ #if TUKLIB_GNUC_REQ(7, 0)
22
+ # pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
23
+ #endif
24
+
25
+
26
+ #ifdef HAVE_SMALL
27
+
28
+ // Macros for (somewhat) size-optimized code.
29
+ #define seq_4(seq) seq
30
+
31
+ #define seq_6(seq) seq
32
+
33
+ #define seq_8(seq) seq
34
+
35
+ #define seq_len(seq) \
36
+ seq ## _CHOICE, \
37
+ seq ## _CHOICE2, \
38
+ seq ## _BITTREE
39
+
40
+ #define len_decode(target, ld, pos_state, seq) \
41
+ do { \
42
+ case seq ## _CHOICE: \
43
+ rc_if_0(ld.choice, seq ## _CHOICE) { \
44
+ rc_update_0(ld.choice); \
45
+ probs = ld.low[pos_state];\
46
+ limit = LEN_LOW_SYMBOLS; \
47
+ target = MATCH_LEN_MIN; \
48
+ } else { \
49
+ rc_update_1(ld.choice); \
50
+ case seq ## _CHOICE2: \
51
+ rc_if_0(ld.choice2, seq ## _CHOICE2) { \
52
+ rc_update_0(ld.choice2); \
53
+ probs = ld.mid[pos_state]; \
54
+ limit = LEN_MID_SYMBOLS; \
55
+ target = MATCH_LEN_MIN + LEN_LOW_SYMBOLS; \
56
+ } else { \
57
+ rc_update_1(ld.choice2); \
58
+ probs = ld.high; \
59
+ limit = LEN_HIGH_SYMBOLS; \
60
+ target = MATCH_LEN_MIN + LEN_LOW_SYMBOLS \
61
+ + LEN_MID_SYMBOLS; \
62
+ } \
63
+ } \
64
+ symbol = 1; \
65
+ case seq ## _BITTREE: \
66
+ do { \
67
+ rc_bit(probs[symbol], , , seq ## _BITTREE); \
68
+ } while (symbol < limit); \
69
+ target += symbol - limit; \
70
+ } while (0)
71
+
72
+ #else // HAVE_SMALL
73
+
74
+ // Unrolled versions
75
+ #define seq_4(seq) \
76
+ seq ## 0, \
77
+ seq ## 1, \
78
+ seq ## 2, \
79
+ seq ## 3
80
+
81
+ #define seq_6(seq) \
82
+ seq ## 0, \
83
+ seq ## 1, \
84
+ seq ## 2, \
85
+ seq ## 3, \
86
+ seq ## 4, \
87
+ seq ## 5
88
+
89
+ #define seq_8(seq) \
90
+ seq ## 0, \
91
+ seq ## 1, \
92
+ seq ## 2, \
93
+ seq ## 3, \
94
+ seq ## 4, \
95
+ seq ## 5, \
96
+ seq ## 6, \
97
+ seq ## 7
98
+
99
+ #define seq_len(seq) \
100
+ seq ## _CHOICE, \
101
+ seq ## _LOW0, \
102
+ seq ## _LOW1, \
103
+ seq ## _LOW2, \
104
+ seq ## _CHOICE2, \
105
+ seq ## _MID0, \
106
+ seq ## _MID1, \
107
+ seq ## _MID2, \
108
+ seq ## _HIGH0, \
109
+ seq ## _HIGH1, \
110
+ seq ## _HIGH2, \
111
+ seq ## _HIGH3, \
112
+ seq ## _HIGH4, \
113
+ seq ## _HIGH5, \
114
+ seq ## _HIGH6, \
115
+ seq ## _HIGH7
116
+
117
+ #define len_decode(target, ld, pos_state, seq) \
118
+ do { \
119
+ symbol = 1; \
120
+ case seq ## _CHOICE: \
121
+ rc_if_0(ld.choice, seq ## _CHOICE) { \
122
+ rc_update_0(ld.choice); \
123
+ rc_bit_case(ld.low[pos_state][symbol], , , seq ## _LOW0); \
124
+ rc_bit_case(ld.low[pos_state][symbol], , , seq ## _LOW1); \
125
+ rc_bit_case(ld.low[pos_state][symbol], , , seq ## _LOW2); \
126
+ target = symbol - LEN_LOW_SYMBOLS + MATCH_LEN_MIN; \
127
+ } else { \
128
+ rc_update_1(ld.choice); \
129
+ case seq ## _CHOICE2: \
130
+ rc_if_0(ld.choice2, seq ## _CHOICE2) { \
131
+ rc_update_0(ld.choice2); \
132
+ rc_bit_case(ld.mid[pos_state][symbol], , , \
133
+ seq ## _MID0); \
134
+ rc_bit_case(ld.mid[pos_state][symbol], , , \
135
+ seq ## _MID1); \
136
+ rc_bit_case(ld.mid[pos_state][symbol], , , \
137
+ seq ## _MID2); \
138
+ target = symbol - LEN_MID_SYMBOLS \
139
+ + MATCH_LEN_MIN + LEN_LOW_SYMBOLS; \
140
+ } else { \
141
+ rc_update_1(ld.choice2); \
142
+ rc_bit_case(ld.high[symbol], , , seq ## _HIGH0); \
143
+ rc_bit_case(ld.high[symbol], , , seq ## _HIGH1); \
144
+ rc_bit_case(ld.high[symbol], , , seq ## _HIGH2); \
145
+ rc_bit_case(ld.high[symbol], , , seq ## _HIGH3); \
146
+ rc_bit_case(ld.high[symbol], , , seq ## _HIGH4); \
147
+ rc_bit_case(ld.high[symbol], , , seq ## _HIGH5); \
148
+ rc_bit_case(ld.high[symbol], , , seq ## _HIGH6); \
149
+ rc_bit_case(ld.high[symbol], , , seq ## _HIGH7); \
150
+ target = symbol - LEN_HIGH_SYMBOLS \
151
+ + MATCH_LEN_MIN \
152
+ + LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS; \
153
+ } \
154
+ } \
155
+ } while (0)
156
+
157
+ #endif // HAVE_SMALL
158
+
159
+
160
+ /// Length decoder probabilities; see comments in lzma_common.h.
161
+ typedef struct {
162
+ probability choice;
163
+ probability choice2;
164
+ probability low[POS_STATES_MAX][LEN_LOW_SYMBOLS];
165
+ probability mid[POS_STATES_MAX][LEN_MID_SYMBOLS];
166
+ probability high[LEN_HIGH_SYMBOLS];
167
+ } lzma_length_decoder;
168
+
169
+
170
+ typedef struct {
171
+ ///////////////////
172
+ // Probabilities //
173
+ ///////////////////
174
+
175
+ /// Literals; see comments in lzma_common.h.
176
+ probability literal[LITERAL_CODERS_MAX][LITERAL_CODER_SIZE];
177
+
178
+ /// If 1, it's a match. Otherwise it's a single 8-bit literal.
179
+ probability is_match[STATES][POS_STATES_MAX];
180
+
181
+ /// If 1, it's a repeated match. The distance is one of rep0 .. rep3.
182
+ probability is_rep[STATES];
183
+
184
+ /// If 0, distance of a repeated match is rep0.
185
+ /// Otherwise check is_rep1.
186
+ probability is_rep0[STATES];
187
+
188
+ /// If 0, distance of a repeated match is rep1.
189
+ /// Otherwise check is_rep2.
190
+ probability is_rep1[STATES];
191
+
192
+ /// If 0, distance of a repeated match is rep2. Otherwise it is rep3.
193
+ probability is_rep2[STATES];
194
+
195
+ /// If 1, the repeated match has length of one byte. Otherwise
196
+ /// the length is decoded from rep_len_decoder.
197
+ probability is_rep0_long[STATES][POS_STATES_MAX];
198
+
199
+ /// Probability tree for the highest two bits of the match distance.
200
+ /// There is a separate probability tree for match lengths of
201
+ /// 2 (i.e. MATCH_LEN_MIN), 3, 4, and [5, 273].
202
+ probability dist_slot[DIST_STATES][DIST_SLOTS];
203
+
204
+ /// Probability trees for additional bits for match distance when the
205
+ /// distance is in the range [4, 127].
206
+ probability pos_special[FULL_DISTANCES - DIST_MODEL_END];
207
+
208
+ /// Probability tree for the lowest four bits of a match distance
209
+ /// that is equal to or greater than 128.
210
+ probability pos_align[ALIGN_SIZE];
211
+
212
+ /// Length of a normal match
213
+ lzma_length_decoder match_len_decoder;
214
+
215
+ /// Length of a repeated match
216
+ lzma_length_decoder rep_len_decoder;
217
+
218
+ ///////////////////
219
+ // Decoder state //
220
+ ///////////////////
221
+
222
+ // Range coder
223
+ lzma_range_decoder rc;
224
+
225
+ // Types of the most recently seen LZMA symbols
226
+ lzma_lzma_state state;
227
+
228
+ uint32_t rep0; ///< Distance of the latest match
229
+ uint32_t rep1; ///< Distance of second latest match
230
+ uint32_t rep2; ///< Distance of third latest match
231
+ uint32_t rep3; ///< Distance of fourth latest match
232
+
233
+ uint32_t pos_mask; // (1U << pb) - 1
234
+ uint32_t literal_context_bits;
235
+ uint32_t literal_pos_mask;
236
+
237
+ /// Uncompressed size as bytes, or LZMA_VLI_UNKNOWN if end of
238
+ /// payload marker is expected.
239
+ lzma_vli uncompressed_size;
240
+
241
+ ////////////////////////////////
242
+ // State of incomplete symbol //
243
+ ////////////////////////////////
244
+
245
+ /// Position where to continue the decoder loop
246
+ enum {
247
+ SEQ_NORMALIZE,
248
+ SEQ_IS_MATCH,
249
+ seq_8(SEQ_LITERAL),
250
+ seq_8(SEQ_LITERAL_MATCHED),
251
+ SEQ_LITERAL_WRITE,
252
+ SEQ_IS_REP,
253
+ seq_len(SEQ_MATCH_LEN),
254
+ seq_6(SEQ_DIST_SLOT),
255
+ SEQ_DIST_MODEL,
256
+ SEQ_DIRECT,
257
+ seq_4(SEQ_ALIGN),
258
+ SEQ_EOPM,
259
+ SEQ_IS_REP0,
260
+ SEQ_SHORTREP,
261
+ SEQ_IS_REP0_LONG,
262
+ SEQ_IS_REP1,
263
+ SEQ_IS_REP2,
264
+ seq_len(SEQ_REP_LEN),
265
+ SEQ_COPY,
266
+ } sequence;
267
+
268
+ /// Base of the current probability tree
269
+ probability *probs;
270
+
271
+ /// Symbol being decoded. This is also used as an index variable in
272
+ /// bittree decoders: probs[symbol]
273
+ uint32_t symbol;
274
+
275
+ /// Used as a loop termination condition on bittree decoders and
276
+ /// direct bits decoder.
277
+ uint32_t limit;
278
+
279
+ /// Matched literal decoder: 0x100 or 0 to help avoiding branches.
280
+ /// Bittree reverse decoders: Offset of the next bit: 1 << offset
281
+ uint32_t offset;
282
+
283
+ /// If decoding a literal: match byte.
284
+ /// If decoding a match: length of the match.
285
+ uint32_t len;
286
+ } lzma_lzma1_decoder;
287
+
288
+
289
+ static lzma_ret
290
+ lzma_decode(void *coder_ptr, lzma_dict *restrict dictptr,
291
+ const uint8_t *restrict in,
292
+ size_t *restrict in_pos, size_t in_size)
293
+ {
294
+ lzma_lzma1_decoder *restrict coder = coder_ptr;
295
+
296
+ ////////////////////
297
+ // Initialization //
298
+ ////////////////////
299
+
300
+ {
301
+ const lzma_ret ret = rc_read_init(
302
+ &coder->rc, in, in_pos, in_size);
303
+ if (ret != LZMA_STREAM_END)
304
+ return ret;
305
+ }
306
+
307
+ ///////////////
308
+ // Variables //
309
+ ///////////////
310
+
311
+ // Making local copies of often-used variables improves both
312
+ // speed and readability.
313
+
314
+ lzma_dict dict = *dictptr;
315
+
316
+ const size_t dict_start = dict.pos;
317
+
318
+ // Range decoder
319
+ rc_to_local(coder->rc, *in_pos);
320
+
321
+ // State
322
+ uint32_t state = coder->state;
323
+ uint32_t rep0 = coder->rep0;
324
+ uint32_t rep1 = coder->rep1;
325
+ uint32_t rep2 = coder->rep2;
326
+ uint32_t rep3 = coder->rep3;
327
+
328
+ const uint32_t pos_mask = coder->pos_mask;
329
+
330
+ // These variables are actually needed only if we last time ran
331
+ // out of input in the middle of the decoder loop.
332
+ probability *probs = coder->probs;
333
+ uint32_t symbol = coder->symbol;
334
+ uint32_t limit = coder->limit;
335
+ uint32_t offset = coder->offset;
336
+ uint32_t len = coder->len;
337
+
338
+ const uint32_t literal_pos_mask = coder->literal_pos_mask;
339
+ const uint32_t literal_context_bits = coder->literal_context_bits;
340
+
341
+ // Temporary variables
342
+ uint32_t pos_state = dict.pos & pos_mask;
343
+
344
+ lzma_ret ret = LZMA_OK;
345
+
346
+ // If uncompressed size is known, there must be no end of payload
347
+ // marker.
348
+ const bool no_eopm = coder->uncompressed_size
349
+ != LZMA_VLI_UNKNOWN;
350
+ if (no_eopm && coder->uncompressed_size < dict.limit - dict.pos)
351
+ dict.limit = dict.pos + (size_t)(coder->uncompressed_size);
352
+
353
+ // The main decoder loop. The "switch" is used to restart the decoder at
354
+ // correct location. Once restarted, the "switch" is no longer used.
355
+ switch (coder->sequence)
356
+ while (true) {
357
+ // Calculate new pos_state. This is skipped on the first loop
358
+ // since we already calculated it when setting up the local
359
+ // variables.
360
+ pos_state = dict.pos & pos_mask;
361
+
362
+ case SEQ_NORMALIZE:
363
+ case SEQ_IS_MATCH:
364
+ if (unlikely(no_eopm && dict.pos == dict.limit))
365
+ break;
366
+
367
+ rc_if_0(coder->is_match[state][pos_state], SEQ_IS_MATCH) {
368
+ rc_update_0(coder->is_match[state][pos_state]);
369
+
370
+ // It's a literal i.e. a single 8-bit byte.
371
+
372
+ probs = literal_subcoder(coder->literal,
373
+ literal_context_bits, literal_pos_mask,
374
+ dict.pos, dict_get(&dict, 0));
375
+ symbol = 1;
376
+
377
+ if (is_literal_state(state)) {
378
+ // Decode literal without match byte.
379
+ #ifdef HAVE_SMALL
380
+ case SEQ_LITERAL:
381
+ do {
382
+ rc_bit(probs[symbol], , , SEQ_LITERAL);
383
+ } while (symbol < (1 << 8));
384
+ #else
385
+ rc_bit_case(probs[symbol], , , SEQ_LITERAL0);
386
+ rc_bit_case(probs[symbol], , , SEQ_LITERAL1);
387
+ rc_bit_case(probs[symbol], , , SEQ_LITERAL2);
388
+ rc_bit_case(probs[symbol], , , SEQ_LITERAL3);
389
+ rc_bit_case(probs[symbol], , , SEQ_LITERAL4);
390
+ rc_bit_case(probs[symbol], , , SEQ_LITERAL5);
391
+ rc_bit_case(probs[symbol], , , SEQ_LITERAL6);
392
+ rc_bit_case(probs[symbol], , , SEQ_LITERAL7);
393
+ #endif
394
+ } else {
395
+ // Decode literal with match byte.
396
+ //
397
+ // We store the byte we compare against
398
+ // ("match byte") to "len" to minimize the
399
+ // number of variables we need to store
400
+ // between decoder calls.
401
+ len = dict_get(&dict, rep0) << 1;
402
+
403
+ // The usage of "offset" allows omitting some
404
+ // branches, which should give tiny speed
405
+ // improvement on some CPUs. "offset" gets
406
+ // set to zero if match_bit didn't match.
407
+ offset = 0x100;
408
+
409
+ #ifdef HAVE_SMALL
410
+ case SEQ_LITERAL_MATCHED:
411
+ do {
412
+ const uint32_t match_bit
413
+ = len & offset;
414
+ const uint32_t subcoder_index
415
+ = offset + match_bit
416
+ + symbol;
417
+
418
+ rc_bit(probs[subcoder_index],
419
+ offset &= ~match_bit,
420
+ offset &= match_bit,
421
+ SEQ_LITERAL_MATCHED);
422
+
423
+ // It seems to be faster to do this
424
+ // here instead of putting it to the
425
+ // beginning of the loop and then
426
+ // putting the "case" in the middle
427
+ // of the loop.
428
+ len <<= 1;
429
+
430
+ } while (symbol < (1 << 8));
431
+ #else
432
+ // Unroll the loop.
433
+ uint32_t match_bit;
434
+ uint32_t subcoder_index;
435
+
436
+ # define d(seq) \
437
+ case seq: \
438
+ match_bit = len & offset; \
439
+ subcoder_index = offset + match_bit + symbol; \
440
+ rc_bit(probs[subcoder_index], \
441
+ offset &= ~match_bit, \
442
+ offset &= match_bit, \
443
+ seq)
444
+
445
+ d(SEQ_LITERAL_MATCHED0);
446
+ len <<= 1;
447
+ d(SEQ_LITERAL_MATCHED1);
448
+ len <<= 1;
449
+ d(SEQ_LITERAL_MATCHED2);
450
+ len <<= 1;
451
+ d(SEQ_LITERAL_MATCHED3);
452
+ len <<= 1;
453
+ d(SEQ_LITERAL_MATCHED4);
454
+ len <<= 1;
455
+ d(SEQ_LITERAL_MATCHED5);
456
+ len <<= 1;
457
+ d(SEQ_LITERAL_MATCHED6);
458
+ len <<= 1;
459
+ d(SEQ_LITERAL_MATCHED7);
460
+ # undef d
461
+ #endif
462
+ }
463
+
464
+ //update_literal(state);
465
+ // Use a lookup table to update to literal state,
466
+ // since compared to other state updates, this would
467
+ // need two branches.
468
+ static const lzma_lzma_state next_state[] = {
469
+ STATE_LIT_LIT,
470
+ STATE_LIT_LIT,
471
+ STATE_LIT_LIT,
472
+ STATE_LIT_LIT,
473
+ STATE_MATCH_LIT_LIT,
474
+ STATE_REP_LIT_LIT,
475
+ STATE_SHORTREP_LIT_LIT,
476
+ STATE_MATCH_LIT,
477
+ STATE_REP_LIT,
478
+ STATE_SHORTREP_LIT,
479
+ STATE_MATCH_LIT,
480
+ STATE_REP_LIT
481
+ };
482
+ state = next_state[state];
483
+
484
+ case SEQ_LITERAL_WRITE:
485
+ if (unlikely(dict_put(&dict, symbol))) {
486
+ coder->sequence = SEQ_LITERAL_WRITE;
487
+ goto out;
488
+ }
489
+
490
+ continue;
491
+ }
492
+
493
+ // Instead of a new byte we are going to get a byte range
494
+ // (distance and length) which will be repeated from our
495
+ // output history.
496
+
497
+ rc_update_1(coder->is_match[state][pos_state]);
498
+
499
+ case SEQ_IS_REP:
500
+ rc_if_0(coder->is_rep[state], SEQ_IS_REP) {
501
+ // Not a repeated match
502
+ rc_update_0(coder->is_rep[state]);
503
+ update_match(state);
504
+
505
+ // The latest three match distances are kept in
506
+ // memory in case there are repeated matches.
507
+ rep3 = rep2;
508
+ rep2 = rep1;
509
+ rep1 = rep0;
510
+
511
+ // Decode the length of the match.
512
+ len_decode(len, coder->match_len_decoder,
513
+ pos_state, SEQ_MATCH_LEN);
514
+
515
+ // Prepare to decode the highest two bits of the
516
+ // match distance.
517
+ probs = coder->dist_slot[get_dist_state(len)];
518
+ symbol = 1;
519
+
520
+ #ifdef HAVE_SMALL
521
+ case SEQ_DIST_SLOT:
522
+ do {
523
+ rc_bit(probs[symbol], , , SEQ_DIST_SLOT);
524
+ } while (symbol < DIST_SLOTS);
525
+ #else
526
+ rc_bit_case(probs[symbol], , , SEQ_DIST_SLOT0);
527
+ rc_bit_case(probs[symbol], , , SEQ_DIST_SLOT1);
528
+ rc_bit_case(probs[symbol], , , SEQ_DIST_SLOT2);
529
+ rc_bit_case(probs[symbol], , , SEQ_DIST_SLOT3);
530
+ rc_bit_case(probs[symbol], , , SEQ_DIST_SLOT4);
531
+ rc_bit_case(probs[symbol], , , SEQ_DIST_SLOT5);
532
+ #endif
533
+ // Get rid of the highest bit that was needed for
534
+ // indexing of the probability array.
535
+ symbol -= DIST_SLOTS;
536
+ assert(symbol <= 63);
537
+
538
+ if (symbol < DIST_MODEL_START) {
539
+ // Match distances [0, 3] have only two bits.
540
+ rep0 = symbol;
541
+ } else {
542
+ // Decode the lowest [1, 29] bits of
543
+ // the match distance.
544
+ limit = (symbol >> 1) - 1;
545
+ assert(limit >= 1 && limit <= 30);
546
+ rep0 = 2 + (symbol & 1);
547
+
548
+ if (symbol < DIST_MODEL_END) {
549
+ // Prepare to decode the low bits for
550
+ // a distance of [4, 127].
551
+ assert(limit <= 5);
552
+ rep0 <<= limit;
553
+ assert(rep0 <= 96);
554
+ // -1 is fine, because we start
555
+ // decoding at probs[1], not probs[0].
556
+ // NOTE: This violates the C standard,
557
+ // since we are doing pointer
558
+ // arithmetic past the beginning of
559
+ // the array.
560
+ assert((int32_t)(rep0 - symbol - 1)
561
+ >= -1);
562
+ assert((int32_t)(rep0 - symbol - 1)
563
+ <= 82);
564
+ probs = coder->pos_special + rep0
565
+ - symbol - 1;
566
+ symbol = 1;
567
+ offset = 0;
568
+ case SEQ_DIST_MODEL:
569
+ #ifdef HAVE_SMALL
570
+ do {
571
+ rc_bit(probs[symbol], ,
572
+ rep0 += 1 << offset,
573
+ SEQ_DIST_MODEL);
574
+ } while (++offset < limit);
575
+ #else
576
+ switch (limit) {
577
+ case 5:
578
+ assert(offset == 0);
579
+ rc_bit(probs[symbol], ,
580
+ rep0 += 1,
581
+ SEQ_DIST_MODEL);
582
+ ++offset;
583
+ --limit;
584
+ case 4:
585
+ rc_bit(probs[symbol], ,
586
+ rep0 += 1 << offset,
587
+ SEQ_DIST_MODEL);
588
+ ++offset;
589
+ --limit;
590
+ case 3:
591
+ rc_bit(probs[symbol], ,
592
+ rep0 += 1 << offset,
593
+ SEQ_DIST_MODEL);
594
+ ++offset;
595
+ --limit;
596
+ case 2:
597
+ rc_bit(probs[symbol], ,
598
+ rep0 += 1 << offset,
599
+ SEQ_DIST_MODEL);
600
+ ++offset;
601
+ --limit;
602
+ case 1:
603
+ // We need "symbol" only for
604
+ // indexing the probability
605
+ // array, thus we can use
606
+ // rc_bit_last() here to omit
607
+ // the unneeded updating of
608
+ // "symbol".
609
+ rc_bit_last(probs[symbol], ,
610
+ rep0 += 1 << offset,
611
+ SEQ_DIST_MODEL);
612
+ }
613
+ #endif
614
+ } else {
615
+ // The distance is >= 128. Decode the
616
+ // lower bits without probabilities
617
+ // except the lowest four bits.
618
+ assert(symbol >= 14);
619
+ assert(limit >= 6);
620
+ limit -= ALIGN_BITS;
621
+ assert(limit >= 2);
622
+ case SEQ_DIRECT:
623
+ // Not worth manual unrolling
624
+ do {
625
+ rc_direct(rep0, SEQ_DIRECT);
626
+ } while (--limit > 0);
627
+
628
+ // Decode the lowest four bits using
629
+ // probabilities.
630
+ rep0 <<= ALIGN_BITS;
631
+ symbol = 1;
632
+ #ifdef HAVE_SMALL
633
+ offset = 0;
634
+ case SEQ_ALIGN:
635
+ do {
636
+ rc_bit(coder->pos_align[
637
+ symbol], ,
638
+ rep0 += 1 << offset,
639
+ SEQ_ALIGN);
640
+ } while (++offset < ALIGN_BITS);
641
+ #else
642
+ case SEQ_ALIGN0:
643
+ rc_bit(coder->pos_align[symbol], ,
644
+ rep0 += 1, SEQ_ALIGN0);
645
+ case SEQ_ALIGN1:
646
+ rc_bit(coder->pos_align[symbol], ,
647
+ rep0 += 2, SEQ_ALIGN1);
648
+ case SEQ_ALIGN2:
649
+ rc_bit(coder->pos_align[symbol], ,
650
+ rep0 += 4, SEQ_ALIGN2);
651
+ case SEQ_ALIGN3:
652
+ // Like in SEQ_DIST_MODEL, we don't
653
+ // need "symbol" for anything else
654
+ // than indexing the probability array.
655
+ rc_bit_last(coder->pos_align[symbol], ,
656
+ rep0 += 8, SEQ_ALIGN3);
657
+ #endif
658
+
659
+ if (rep0 == UINT32_MAX) {
660
+ // End of payload marker was
661
+ // found. It must not be
662
+ // present if uncompressed
663
+ // size is known.
664
+ if (coder->uncompressed_size
665
+ != LZMA_VLI_UNKNOWN) {
666
+ ret = LZMA_DATA_ERROR;
667
+ goto out;
668
+ }
669
+
670
+ case SEQ_EOPM:
671
+ // LZMA1 stream with
672
+ // end-of-payload marker.
673
+ rc_normalize(SEQ_EOPM);
674
+ ret = LZMA_STREAM_END;
675
+ goto out;
676
+ }
677
+ }
678
+ }
679
+
680
+ // Validate the distance we just decoded.
681
+ if (unlikely(!dict_is_distance_valid(&dict, rep0))) {
682
+ ret = LZMA_DATA_ERROR;
683
+ goto out;
684
+ }
685
+
686
+ } else {
687
+ rc_update_1(coder->is_rep[state]);
688
+
689
+ // Repeated match
690
+ //
691
+ // The match distance is a value that we have had
692
+ // earlier. The latest four match distances are
693
+ // available as rep0, rep1, rep2 and rep3. We will
694
+ // now decode which of them is the new distance.
695
+ //
696
+ // There cannot be a match if we haven't produced
697
+ // any output, so check that first.
698
+ if (unlikely(!dict_is_distance_valid(&dict, 0))) {
699
+ ret = LZMA_DATA_ERROR;
700
+ goto out;
701
+ }
702
+
703
+ case SEQ_IS_REP0:
704
+ rc_if_0(coder->is_rep0[state], SEQ_IS_REP0) {
705
+ rc_update_0(coder->is_rep0[state]);
706
+ // The distance is rep0.
707
+
708
+ case SEQ_IS_REP0_LONG:
709
+ rc_if_0(coder->is_rep0_long[state][pos_state],
710
+ SEQ_IS_REP0_LONG) {
711
+ rc_update_0(coder->is_rep0_long[
712
+ state][pos_state]);
713
+
714
+ update_short_rep(state);
715
+
716
+ case SEQ_SHORTREP:
717
+ if (unlikely(dict_put(&dict, dict_get(
718
+ &dict, rep0)))) {
719
+ coder->sequence = SEQ_SHORTREP;
720
+ goto out;
721
+ }
722
+
723
+ continue;
724
+ }
725
+
726
+ // Repeating more than one byte at
727
+ // distance of rep0.
728
+ rc_update_1(coder->is_rep0_long[
729
+ state][pos_state]);
730
+
731
+ } else {
732
+ rc_update_1(coder->is_rep0[state]);
733
+
734
+ case SEQ_IS_REP1:
735
+ // The distance is rep1, rep2 or rep3. Once
736
+ // we find out which one of these three, it
737
+ // is stored to rep0 and rep1, rep2 and rep3
738
+ // are updated accordingly.
739
+ rc_if_0(coder->is_rep1[state], SEQ_IS_REP1) {
740
+ rc_update_0(coder->is_rep1[state]);
741
+
742
+ const uint32_t distance = rep1;
743
+ rep1 = rep0;
744
+ rep0 = distance;
745
+
746
+ } else {
747
+ rc_update_1(coder->is_rep1[state]);
748
+ case SEQ_IS_REP2:
749
+ rc_if_0(coder->is_rep2[state],
750
+ SEQ_IS_REP2) {
751
+ rc_update_0(coder->is_rep2[
752
+ state]);
753
+
754
+ const uint32_t distance = rep2;
755
+ rep2 = rep1;
756
+ rep1 = rep0;
757
+ rep0 = distance;
758
+
759
+ } else {
760
+ rc_update_1(coder->is_rep2[
761
+ state]);
762
+
763
+ const uint32_t distance = rep3;
764
+ rep3 = rep2;
765
+ rep2 = rep1;
766
+ rep1 = rep0;
767
+ rep0 = distance;
768
+ }
769
+ }
770
+ }
771
+
772
+ update_long_rep(state);
773
+
774
+ // Decode the length of the repeated match.
775
+ len_decode(len, coder->rep_len_decoder,
776
+ pos_state, SEQ_REP_LEN);
777
+ }
778
+
779
+ /////////////////////////////////
780
+ // Repeat from history buffer. //
781
+ /////////////////////////////////
782
+
783
+ // The length is always between these limits. There is no way
784
+ // to trigger the algorithm to set len outside this range.
785
+ assert(len >= MATCH_LEN_MIN);
786
+ assert(len <= MATCH_LEN_MAX);
787
+
788
+ case SEQ_COPY:
789
+ // Repeat len bytes from distance of rep0.
790
+ if (unlikely(dict_repeat(&dict, rep0, &len))) {
791
+ coder->sequence = SEQ_COPY;
792
+ goto out;
793
+ }
794
+ }
795
+
796
+ rc_normalize(SEQ_NORMALIZE);
797
+ coder->sequence = SEQ_IS_MATCH;
798
+
799
+ out:
800
+ // Save state
801
+
802
+ // NOTE: Must not copy dict.limit.
803
+ dictptr->pos = dict.pos;
804
+ dictptr->full = dict.full;
805
+
806
+ rc_from_local(coder->rc, *in_pos);
807
+
808
+ coder->state = state;
809
+ coder->rep0 = rep0;
810
+ coder->rep1 = rep1;
811
+ coder->rep2 = rep2;
812
+ coder->rep3 = rep3;
813
+
814
+ coder->probs = probs;
815
+ coder->symbol = symbol;
816
+ coder->limit = limit;
817
+ coder->offset = offset;
818
+ coder->len = len;
819
+
820
+ // Update the remaining amount of uncompressed data if uncompressed
821
+ // size was known.
822
+ if (coder->uncompressed_size != LZMA_VLI_UNKNOWN) {
823
+ coder->uncompressed_size -= dict.pos - dict_start;
824
+
825
+ // Since there cannot be end of payload marker if the
826
+ // uncompressed size was known, we check here if we
827
+ // finished decoding.
828
+ if (coder->uncompressed_size == 0 && ret == LZMA_OK
829
+ && coder->sequence != SEQ_NORMALIZE)
830
+ ret = coder->sequence == SEQ_IS_MATCH
831
+ ? LZMA_STREAM_END : LZMA_DATA_ERROR;
832
+ }
833
+
834
+ // We can do an additional check in the range decoder to catch some
835
+ // corrupted files.
836
+ if (ret == LZMA_STREAM_END) {
837
+ if (!rc_is_finished(coder->rc))
838
+ ret = LZMA_DATA_ERROR;
839
+
840
+ // Reset the range decoder so that it is ready to reinitialize
841
+ // for a new LZMA2 chunk.
842
+ rc_reset(coder->rc);
843
+ }
844
+
845
+ return ret;
846
+ }
847
+
848
+
849
+
850
+ static void
851
+ lzma_decoder_uncompressed(void *coder_ptr, lzma_vli uncompressed_size)
852
+ {
853
+ lzma_lzma1_decoder *coder = coder_ptr;
854
+ coder->uncompressed_size = uncompressed_size;
855
+ }
856
+
857
+
858
+ static void
859
+ lzma_decoder_reset(void *coder_ptr, const void *opt)
860
+ {
861
+ lzma_lzma1_decoder *coder = coder_ptr;
862
+ const lzma_options_lzma *options = opt;
863
+
864
+ // NOTE: We assume that lc/lp/pb are valid since they were
865
+ // successfully decoded with lzma_lzma_decode_properties().
866
+
867
+ // Calculate pos_mask. We don't need pos_bits as is for anything.
868
+ coder->pos_mask = (1U << options->pb) - 1;
869
+
870
+ // Initialize the literal decoder.
871
+ literal_init(coder->literal, options->lc, options->lp);
872
+
873
+ coder->literal_context_bits = options->lc;
874
+ coder->literal_pos_mask = (1U << options->lp) - 1;
875
+
876
+ // State
877
+ coder->state = STATE_LIT_LIT;
878
+ coder->rep0 = 0;
879
+ coder->rep1 = 0;
880
+ coder->rep2 = 0;
881
+ coder->rep3 = 0;
882
+ coder->pos_mask = (1U << options->pb) - 1;
883
+
884
+ // Range decoder
885
+ rc_reset(coder->rc);
886
+
887
+ // Bit and bittree decoders
888
+ for (uint32_t i = 0; i < STATES; ++i) {
889
+ for (uint32_t j = 0; j <= coder->pos_mask; ++j) {
890
+ bit_reset(coder->is_match[i][j]);
891
+ bit_reset(coder->is_rep0_long[i][j]);
892
+ }
893
+
894
+ bit_reset(coder->is_rep[i]);
895
+ bit_reset(coder->is_rep0[i]);
896
+ bit_reset(coder->is_rep1[i]);
897
+ bit_reset(coder->is_rep2[i]);
898
+ }
899
+
900
+ for (uint32_t i = 0; i < DIST_STATES; ++i)
901
+ bittree_reset(coder->dist_slot[i], DIST_SLOT_BITS);
902
+
903
+ for (uint32_t i = 0; i < FULL_DISTANCES - DIST_MODEL_END; ++i)
904
+ bit_reset(coder->pos_special[i]);
905
+
906
+ bittree_reset(coder->pos_align, ALIGN_BITS);
907
+
908
+ // Len decoders (also bit/bittree)
909
+ const uint32_t num_pos_states = 1U << options->pb;
910
+ bit_reset(coder->match_len_decoder.choice);
911
+ bit_reset(coder->match_len_decoder.choice2);
912
+ bit_reset(coder->rep_len_decoder.choice);
913
+ bit_reset(coder->rep_len_decoder.choice2);
914
+
915
+ for (uint32_t pos_state = 0; pos_state < num_pos_states; ++pos_state) {
916
+ bittree_reset(coder->match_len_decoder.low[pos_state],
917
+ LEN_LOW_BITS);
918
+ bittree_reset(coder->match_len_decoder.mid[pos_state],
919
+ LEN_MID_BITS);
920
+
921
+ bittree_reset(coder->rep_len_decoder.low[pos_state],
922
+ LEN_LOW_BITS);
923
+ bittree_reset(coder->rep_len_decoder.mid[pos_state],
924
+ LEN_MID_BITS);
925
+ }
926
+
927
+ bittree_reset(coder->match_len_decoder.high, LEN_HIGH_BITS);
928
+ bittree_reset(coder->rep_len_decoder.high, LEN_HIGH_BITS);
929
+
930
+ coder->sequence = SEQ_IS_MATCH;
931
+ coder->probs = NULL;
932
+ coder->symbol = 0;
933
+ coder->limit = 0;
934
+ coder->offset = 0;
935
+ coder->len = 0;
936
+
937
+ return;
938
+ }
939
+
940
+
941
+ extern lzma_ret
942
+ lzma_lzma_decoder_create(lzma_lz_decoder *lz, const lzma_allocator *allocator,
943
+ const void *opt, lzma_lz_options *lz_options)
944
+ {
945
+ if (lz->coder == NULL) {
946
+ lz->coder = lzma_alloc(sizeof(lzma_lzma1_decoder), allocator);
947
+ if (lz->coder == NULL)
948
+ return LZMA_MEM_ERROR;
949
+
950
+ lz->code = &lzma_decode;
951
+ lz->reset = &lzma_decoder_reset;
952
+ lz->set_uncompressed = &lzma_decoder_uncompressed;
953
+ }
954
+
955
+ // All dictionary sizes are OK here. LZ decoder will take care of
956
+ // the special cases.
957
+ const lzma_options_lzma *options = opt;
958
+ lz_options->dict_size = options->dict_size;
959
+ lz_options->preset_dict = options->preset_dict;
960
+ lz_options->preset_dict_size = options->preset_dict_size;
961
+
962
+ return LZMA_OK;
963
+ }
964
+
965
+
966
+ /// Allocate and initialize LZMA decoder. This is used only via LZ
967
+ /// initialization (lzma_lzma_decoder_init() passes function pointer to
968
+ /// the LZ initialization).
969
+ static lzma_ret
970
+ lzma_decoder_init(lzma_lz_decoder *lz, const lzma_allocator *allocator,
971
+ const void *options, lzma_lz_options *lz_options)
972
+ {
973
+ if (!is_lclppb_valid(options))
974
+ return LZMA_PROG_ERROR;
975
+
976
+ return_if_error(lzma_lzma_decoder_create(
977
+ lz, allocator, options, lz_options));
978
+
979
+ lzma_decoder_reset(lz->coder, options);
980
+ lzma_decoder_uncompressed(lz->coder, LZMA_VLI_UNKNOWN);
981
+
982
+ return LZMA_OK;
983
+ }
984
+
985
+
986
+ extern lzma_ret
987
+ lzma_lzma_decoder_init(lzma_next_coder *next, const lzma_allocator *allocator,
988
+ const lzma_filter_info *filters)
989
+ {
990
+ // LZMA can only be the last filter in the chain. This is enforced
991
+ // by the raw_decoder initialization.
992
+ assert(filters[1].init == NULL);
993
+
994
+ return lzma_lz_decoder_init(next, allocator, filters,
995
+ &lzma_decoder_init);
996
+ }
997
+
998
+
999
+ extern bool
1000
+ lzma_lzma_lclppb_decode(lzma_options_lzma *options, uint8_t byte)
1001
+ {
1002
+ if (byte > (4 * 5 + 4) * 9 + 8)
1003
+ return true;
1004
+
1005
+ // See the file format specification to understand this.
1006
+ options->pb = byte / (9 * 5);
1007
+ byte -= options->pb * 9 * 5;
1008
+ options->lp = byte / 9;
1009
+ options->lc = byte - options->lp * 9;
1010
+
1011
+ return options->lc + options->lp > LZMA_LCLP_MAX;
1012
+ }
1013
+
1014
+
1015
+ extern uint64_t
1016
+ lzma_lzma_decoder_memusage_nocheck(const void *options)
1017
+ {
1018
+ const lzma_options_lzma *const opt = options;
1019
+ return sizeof(lzma_lzma1_decoder)
1020
+ + lzma_lz_decoder_memusage(opt->dict_size);
1021
+ }
1022
+
1023
+
1024
+ extern uint64_t
1025
+ lzma_lzma_decoder_memusage(const void *options)
1026
+ {
1027
+ if (!is_lclppb_valid(options))
1028
+ return UINT64_MAX;
1029
+
1030
+ return lzma_lzma_decoder_memusage_nocheck(options);
1031
+ }
1032
+
1033
+
1034
+ extern lzma_ret
1035
+ lzma_lzma_props_decode(void **options, const lzma_allocator *allocator,
1036
+ const uint8_t *props, size_t props_size)
1037
+ {
1038
+ if (props_size != 5)
1039
+ return LZMA_OPTIONS_ERROR;
1040
+
1041
+ lzma_options_lzma *opt
1042
+ = lzma_alloc(sizeof(lzma_options_lzma), allocator);
1043
+ if (opt == NULL)
1044
+ return LZMA_MEM_ERROR;
1045
+
1046
+ if (lzma_lzma_lclppb_decode(opt, props[0]))
1047
+ goto error;
1048
+
1049
+ // All dictionary sizes are accepted, including zero. LZ decoder
1050
+ // will automatically use a dictionary at least a few KiB even if
1051
+ // a smaller dictionary is requested.
1052
+ opt->dict_size = unaligned_read32le(props + 1);
1053
+
1054
+ opt->preset_dict = NULL;
1055
+ opt->preset_dict_size = 0;
1056
+
1057
+ *options = opt;
1058
+
1059
+ return LZMA_OK;
1060
+
1061
+ error:
1062
+ lzma_free(opt, allocator);
1063
+ return LZMA_OPTIONS_ERROR;
1064
+ }