busybox-1.29.1_lzip-0.diff 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270
  1. diff -urdN busybox-1.29.1.old/archival/Config.src busybox-1.29.1.new/archival/Config.src
  2. --- busybox-1.29.1.old/archival/Config.src 2018-07-02 13:23:06.000000000 +0200
  3. +++ busybox-1.29.1.new/archival/Config.src 2018-07-17 00:03:25.000000000 +0200
  4. @@ -21,6 +21,10 @@
  5. bool "Make tar, rpm, modprobe etc understand .gz data"
  6. default y
  7. +config FEATURE_SEAMLESS_LZ
  8. + bool "Make tar, rpm, modprobe etc understand .lz data"
  9. + default y
  10. +
  11. config FEATURE_SEAMLESS_Z
  12. bool "Make tar, rpm, modprobe etc understand .Z data"
  13. default n # it is ancient
  14. diff -urdN busybox-1.29.1.old/archival/bbunzip.c busybox-1.29.1.new/archival/bbunzip.c
  15. --- busybox-1.29.1.old/archival/bbunzip.c 2018-07-02 13:23:06.000000000 +0200
  16. +++ busybox-1.29.1.new/archival/bbunzip.c 2018-07-19 12:53:03.000000000 +0200
  17. @@ -194,18 +194,31 @@
  18. #if ENABLE_UNCOMPRESS \
  19. || ENABLE_FEATURE_BZIP2_DECOMPRESS \
  20. + || ENABLE_FEATURE_LZIP_DECOMPRESS \
  21. || ENABLE_UNLZMA || ENABLE_LZCAT || ENABLE_LZMA \
  22. || ENABLE_UNXZ || ENABLE_XZCAT || ENABLE_XZ
  23. static
  24. char* FAST_FUNC make_new_name_generic(char *filename, const char *expected_ext)
  25. {
  26. char *extension = strrchr(filename, '.');
  27. - if (!extension || strcmp(extension + 1, expected_ext) != 0) {
  28. +
  29. + if (!extension)
  30. + return NULL;
  31. +
  32. + if (strcmp(extension + 1, expected_ext) == 0) {
  33. + *extension = '\0';
  34. + } else if (extension[1] == 't' && strlen(expected_ext) >= 2 &&
  35. + strcmp(extension + 2, expected_ext) == 0) {
  36. + filename = xstrdup(filename);
  37. + extension = strrchr(filename, '.');
  38. + extension[2] = 'a';
  39. + extension[3] = 'r';
  40. + extension[4] = '\0';
  41. + } else {
  42. /* Mimic GNU gunzip - "real" bunzip2 tries to */
  43. /* unpack file anyway, to file.out */
  44. return NULL;
  45. }
  46. - *extension = '\0';
  47. return filename;
  48. }
  49. #endif
  50. @@ -449,6 +462,38 @@
  51. }
  52. #endif
  53. +
  54. +//config:config LUNZIP
  55. +//config: bool "lunzip"
  56. +//config: default y
  57. +//config: select FEATURE_LZIP_DECOMPRESS
  58. +//config: help
  59. +//config: lunzip is used to decompress archives created by lzip.
  60. +//config: You can use the '-t' option to test the integrity of
  61. +//config: an archive, without decompressing it.
  62. +
  63. +//applet:IF_LUNZIP(APPLET(lunzip, BB_DIR_USR_BIN, BB_SUID_DROP))
  64. +//kbuild:lib-$(CONFIG_LUNZIP) += bbunzip.o
  65. +
  66. +//usage:#define lunzip_trivial_usage
  67. +//usage: "[-cft] [FILE]..."
  68. +//usage:#define lunzip_full_usage "\n\n"
  69. +//usage: "Decompress FILEs (or stdin)\n"
  70. +//usage: "\n -c Write to stdout"
  71. +//usage: "\n -f Force"
  72. +//usage: "\n -k Keep input files"
  73. +//usage: "\n -t Test file integrity"
  74. +#if ENABLE_FEATURE_LZIP_DECOMPRESS
  75. +int lunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  76. +int lunzip_main(int argc UNUSED_PARAM, char **argv)
  77. +{
  78. + getopt32(argv, BBUNPK_OPTSTR "dt");
  79. + argv += optind;
  80. +
  81. + return bbunpack(argv, unpack_lz_stream, make_new_name_generic, "lz");
  82. +}
  83. +#endif
  84. +
  85. /*
  86. * Small lzma deflate implementation.
  87. diff -urdN busybox-1.29.1.old/archival/dpkg.c busybox-1.29.1.new/archival/dpkg.c
  88. --- busybox-1.29.1.old/archival/dpkg.c 2018-07-02 13:23:06.000000000 +0200
  89. +++ busybox-1.29.1.new/archival/dpkg.c 2018-07-17 00:03:25.000000000 +0200
  90. @@ -1482,6 +1482,9 @@
  91. #if ENABLE_FEATURE_SEAMLESS_XZ
  92. llist_add_to(&(ar_handle->accept), (char*)"control.tar.xz");
  93. #endif
  94. +#if ENABLE_FEATURE_SEAMLESS_LZ
  95. + llist_add_to(&(ar_handle->accept), (char*)"control.tar.lz");
  96. +#endif
  97. /* Assign the tar handle as a subarchive of the ar handle */
  98. ar_handle->dpkg__sub_archive = tar_handle;
  99. @@ -1509,6 +1512,9 @@
  100. #if ENABLE_FEATURE_SEAMLESS_XZ
  101. llist_add_to(&(ar_handle->accept), (char*)"data.tar.xz");
  102. #endif
  103. +#if ENABLE_FEATURE_SEAMLESS_LZ
  104. + llist_add_to(&(ar_handle->accept), (char*)"data.tar.lz");
  105. +#endif
  106. /* Assign the tar handle as a subarchive of the ar handle */
  107. ar_handle->dpkg__sub_archive = tar_handle;
  108. diff -urdN busybox-1.29.1.old/archival/dpkg_deb.c busybox-1.29.1.new/archival/dpkg_deb.c
  109. --- busybox-1.29.1.old/archival/dpkg_deb.c 2018-07-02 13:23:06.000000000 +0200
  110. +++ busybox-1.29.1.new/archival/dpkg_deb.c 2018-07-17 00:03:25.000000000 +0200
  111. @@ -69,6 +69,10 @@
  112. llist_add_to(&ar_archive->accept, (char*)"data.tar.bz2");
  113. llist_add_to(&control_tar_llist, (char*)"control.tar.bz2");
  114. #endif
  115. +#if ENABLE_FEATURE_SEAMLESS_LZ
  116. + llist_add_to(&ar_archive->accept, (char*)"data.tar.lz");
  117. + llist_add_to(&control_tar_llist, (char*)"control.tar.lz");
  118. +#endif
  119. #if ENABLE_FEATURE_SEAMLESS_LZMA
  120. llist_add_to(&ar_archive->accept, (char*)"data.tar.lzma");
  121. llist_add_to(&control_tar_llist, (char*)"control.tar.lzma");
  122. diff -urdN busybox-1.29.1.old/archival/libarchive/Kbuild.src busybox-1.29.1.new/archival/libarchive/Kbuild.src
  123. --- busybox-1.29.1.old/archival/libarchive/Kbuild.src 2018-07-02 13:23:06.000000000 +0200
  124. +++ busybox-1.29.1.new/archival/libarchive/Kbuild.src 2018-07-19 13:03:34.000000000 +0200
  125. @@ -37,6 +37,7 @@
  126. get_header_tar.o \
  127. get_header_tar_gz.o \
  128. get_header_tar_bz2.o \
  129. + get_header_tar_lz.o \
  130. get_header_tar_lzma.o \
  131. get_header_tar_xz.o \
  132. @@ -56,6 +57,8 @@
  133. # 'bzip2 -d', bunzip2 or bzcat selects FEATURE_BZIP2_DECOMPRESS
  134. lib-$(CONFIG_FEATURE_BZIP2_DECOMPRESS) += open_transformer.o decompress_bunzip2.o
  135. lib-$(CONFIG_FEATURE_UNZIP_BZIP2) += open_transformer.o decompress_bunzip2.o
  136. +# 'lzip -d' or lunzip select FEATURE_LZIP_DECOMPRESS
  137. +lib-$(CONFIG_FEATURE_LZIP_DECOMPRESS) += open_transformer.o decompress_lunzip.o
  138. lib-$(CONFIG_UNLZMA) += open_transformer.o decompress_unlzma.o
  139. lib-$(CONFIG_LZCAT) += open_transformer.o decompress_unlzma.o
  140. lib-$(CONFIG_LZMA) += open_transformer.o decompress_unlzma.o
  141. @@ -72,6 +75,7 @@
  142. lib-$(CONFIG_RPM) += open_transformer.o decompress_gunzip.o get_header_cpio.o
  143. lib-$(CONFIG_GZIP) += open_transformer.o
  144. lib-$(CONFIG_BZIP2) += open_transformer.o
  145. +lib-$(CONFIG_LZIP) += open_transformer.o
  146. lib-$(CONFIG_LZOP) += open_transformer.o
  147. lib-$(CONFIG_MAN) += open_transformer.o
  148. lib-$(CONFIG_SETFONT) += open_transformer.o
  149. @@ -87,6 +91,7 @@
  150. lib-$(CONFIG_FEATURE_SEAMLESS_Z) += open_transformer.o decompress_uncompress.o
  151. lib-$(CONFIG_FEATURE_SEAMLESS_GZ) += open_transformer.o decompress_gunzip.o
  152. lib-$(CONFIG_FEATURE_SEAMLESS_BZ2) += open_transformer.o decompress_bunzip2.o
  153. +lib-$(CONFIG_FEATURE_SEAMLESS_LZ) += open_transformer.o decompress_lunzip.o
  154. lib-$(CONFIG_FEATURE_SEAMLESS_LZMA) += open_transformer.o decompress_unlzma.o
  155. lib-$(CONFIG_FEATURE_SEAMLESS_XZ) += open_transformer.o decompress_unxz.o
  156. lib-$(CONFIG_FEATURE_COMPRESS_USAGE) += open_transformer.o decompress_bunzip2.o
  157. diff -urdN busybox-1.29.1.old/archival/libarchive/decompress_lunzip.c busybox-1.29.1.new/archival/libarchive/decompress_lunzip.c
  158. --- busybox-1.29.1.old/archival/libarchive/decompress_lunzip.c 1970-01-01 01:00:00.000000000 +0100
  159. +++ busybox-1.29.1.new/archival/libarchive/decompress_lunzip.c 2018-07-18 12:26:07.000000000 +0200
  160. @@ -0,0 +1,497 @@
  161. +/*
  162. + * lunzip implementation for busybox
  163. + *
  164. + * Copyright (C) 2012-2018 Antonio Diaz Diaz.
  165. + *
  166. + * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  167. + */
  168. +
  169. +#include "libbb.h"
  170. +#include "bb_archive.h"
  171. +#include "lzip.h"
  172. +
  173. +/* Some functions have been marked with __always_inline because xz does
  174. + it, giving the impression that unxz is much faster than lunzip. */
  175. +#ifndef __always_inline
  176. +# ifdef __GNUC__
  177. +# define __always_inline \
  178. + inline __attribute__((__always_inline__))
  179. +# else
  180. +# define __always_inline inline
  181. +# endif
  182. +#endif
  183. +
  184. +
  185. +enum { rd_buffer_size = 16384 };
  186. +
  187. +struct Range_decoder {
  188. + unsigned long long partial_member_pos;
  189. + uint8_t *buffer; /* input buffer */
  190. + int pos; /* current pos in buffer */
  191. + int stream_pos; /* when reached, a new block must be read */
  192. + uint32_t code;
  193. + uint32_t range;
  194. + int infd; /* input file descriptor */
  195. + bool at_stream_end;
  196. +};
  197. +
  198. +
  199. +static bool Rd_read_block(struct Range_decoder * const rdec)
  200. +{
  201. + if (!rdec->at_stream_end) {
  202. + rdec->stream_pos =
  203. + full_read(rdec->infd, rdec->buffer, rd_buffer_size);
  204. + rdec->at_stream_end = (rdec->stream_pos < rd_buffer_size);
  205. + rdec->partial_member_pos += rdec->pos;
  206. + rdec->pos = 0;
  207. + }
  208. + return rdec->pos < rdec->stream_pos;
  209. +}
  210. +
  211. +
  212. +static bool Rd_init(struct Range_decoder * const rdec, const int ifd,
  213. + const bool magic_skipped)
  214. +{
  215. + rdec->partial_member_pos = (magic_skipped ? 4 : 0);
  216. + rdec->buffer = (uint8_t *) malloc(rd_buffer_size);
  217. + if (!rdec->buffer) return false;
  218. + rdec->pos = 0;
  219. + rdec->stream_pos = 0;
  220. + rdec->code = 0;
  221. + rdec->range = 0xFFFFFFFFU;
  222. + rdec->infd = ifd;
  223. + rdec->at_stream_end = false;
  224. + return true;
  225. +}
  226. +
  227. +static __always_inline bool Rd_finished(struct Range_decoder * const rdec)
  228. +{
  229. + return rdec->pos >= rdec->stream_pos && !Rd_read_block(rdec);
  230. +}
  231. +
  232. +static inline unsigned long long
  233. +Rd_member_position(const struct Range_decoder * const rdec)
  234. +{
  235. + return rdec->partial_member_pos + rdec->pos;
  236. +}
  237. +
  238. +static inline void Rd_reset_member_position(struct Range_decoder * const rdec)
  239. +{
  240. + rdec->partial_member_pos = 0; rdec->partial_member_pos -= rdec->pos;
  241. +}
  242. +
  243. +static __always_inline uint8_t Rd_get_byte(struct Range_decoder * const rdec)
  244. +{
  245. + /* 0xFF avoids decoder error if member is truncated at EOS marker */
  246. + if (Rd_finished(rdec)) return 0xFF;
  247. + return rdec->buffer[rdec->pos++];
  248. +}
  249. +
  250. +static void Rd_load(struct Range_decoder * const rdec)
  251. +{
  252. + int i;
  253. + rdec->code = 0;
  254. + for (i = 0; i < 5; ++i)
  255. + rdec->code = (rdec->code << 8) | Rd_get_byte(rdec);
  256. + rdec->range = 0xFFFFFFFFU;
  257. +}
  258. +
  259. +static __always_inline void Rd_normalize(struct Range_decoder * const rdec)
  260. +{
  261. + if (rdec->range <= 0x00FFFFFFU) {
  262. + rdec->range <<= 8;
  263. + rdec->code = (rdec->code << 8) | Rd_get_byte(rdec);
  264. + }
  265. +}
  266. +
  267. +static unsigned Rd_decode(struct Range_decoder * const rdec,
  268. + const int num_bits)
  269. +{
  270. + unsigned symbol = 0;
  271. + int i;
  272. + for (i = num_bits; i > 0; --i) {
  273. + bool bit;
  274. + Rd_normalize(rdec);
  275. + rdec->range >>= 1;
  276. + /* symbol <<= 1; */
  277. + /* if(rdec->code >= rdec->range) { rdec->code -= rdec->range; symbol |= 1; } */
  278. + bit = (rdec->code >= rdec->range);
  279. + symbol = (symbol << 1) + bit;
  280. + rdec->code -= rdec->range & (0U - bit);
  281. + }
  282. + return symbol;
  283. +}
  284. +
  285. +static __always_inline unsigned Rd_decode_bit(struct Range_decoder * const rdec,
  286. + Bit_model * const probability)
  287. +{
  288. + uint32_t bound;
  289. + Rd_normalize(rdec);
  290. + bound = (rdec->range >> bit_model_total_bits) * *probability;
  291. + if (rdec->code < bound) {
  292. + rdec->range = bound;
  293. + *probability += (bit_model_total - *probability) >> bit_model_move_bits;
  294. + return 0;
  295. + } else {
  296. + rdec->range -= bound;
  297. + rdec->code -= bound;
  298. + *probability -= *probability >> bit_model_move_bits;
  299. + return 1;
  300. + }
  301. +}
  302. +
  303. +static __always_inline unsigned Rd_decode_tree(struct Range_decoder * const rdec,
  304. + Bit_model bm[], const int num_bits)
  305. +{
  306. + unsigned symbol = 1;
  307. + int i;
  308. + for (i = num_bits; i > 0; --i)
  309. + symbol = (symbol << 1) | Rd_decode_bit(rdec, &bm[symbol]);
  310. + return symbol - (1 << num_bits);
  311. +}
  312. +
  313. +static __always_inline unsigned Rd_decode_tree_reversed(struct Range_decoder * const rdec,
  314. + Bit_model bm[], const int num_bits)
  315. +{
  316. + unsigned model = 1;
  317. + unsigned symbol = 0;
  318. + int i;
  319. + for (i = 0; i < num_bits; ++i) {
  320. + const unsigned bit = Rd_decode_bit(rdec, &bm[model]);
  321. + model = (model << 1) + bit;
  322. + symbol |= (bit << i);
  323. + }
  324. + return symbol;
  325. +}
  326. +
  327. +static unsigned Rd_decode_matched(struct Range_decoder * const rdec,
  328. + Bit_model bm[], unsigned match_byte)
  329. +{
  330. + unsigned symbol = 1;
  331. + unsigned mask = 0x100;
  332. + while(true) {
  333. + const unsigned match_bit = (match_byte <<= 1) & mask;
  334. + const unsigned bit = Rd_decode_bit(rdec, &bm[symbol+match_bit+mask]);
  335. + symbol = (symbol << 1) + bit;
  336. + if (symbol >= 0x100) return symbol & 0xFF;
  337. + mask &= ~(match_bit ^ (bit << 8)); /* if( match_bit != bit ) mask = 0; */
  338. + }
  339. +}
  340. +
  341. +static __always_inline unsigned Rd_decode_len(struct Range_decoder * const rdec,
  342. + struct Len_model * const lm,
  343. + const int pos_state)
  344. +{
  345. + if (Rd_decode_bit(rdec, &lm->choice1) == 0)
  346. + return Rd_decode_tree(rdec, lm->bm_low[pos_state], len_low_bits);
  347. + if (Rd_decode_bit(rdec, &lm->choice2) == 0)
  348. + return len_low_symbols +
  349. + Rd_decode_tree(rdec, lm->bm_mid[pos_state], len_mid_bits);
  350. + return len_low_symbols + len_mid_symbols +
  351. + Rd_decode_tree(rdec, lm->bm_high, len_high_bits);
  352. +}
  353. +
  354. +
  355. +struct LZ_decoder {
  356. + unsigned long long partial_data_pos;
  357. + struct Range_decoder *rdec;
  358. + unsigned dictionary_size;
  359. + uint8_t *buffer; /* output buffer */
  360. + unsigned pos; /* current pos in buffer */
  361. + unsigned stream_pos; /* first byte not yet written to file */
  362. + uint32_t crc;
  363. + int outfd; /* output file descriptor */
  364. + bool pos_wrapped;
  365. + bool write_error;
  366. +};
  367. +
  368. +static void LZd_flush_data(struct LZ_decoder * const d)
  369. +{
  370. + if (d->pos > d->stream_pos) {
  371. + const int size = d->pos - d->stream_pos;
  372. + d->crc = crc32_block_endian0(d->crc, d->buffer + d->stream_pos,
  373. + size, global_crc32_table);
  374. + if (d->outfd >= 0 && full_write(d->outfd,
  375. + d->buffer + d->stream_pos, size) != size)
  376. + d->write_error = true;
  377. + if (d->pos >= d->dictionary_size) {
  378. + d->partial_data_pos += d->pos;
  379. + d->pos = 0;
  380. + d->pos_wrapped = true;
  381. + }
  382. + d->stream_pos = d->pos;
  383. + }
  384. +}
  385. +
  386. +static __always_inline uint8_t LZd_peek_prev(const struct LZ_decoder * const d)
  387. +{
  388. + const unsigned i = ((d->pos > 0) ? d->pos : d->dictionary_size) - 1;
  389. + return d->buffer[i];
  390. +}
  391. +
  392. +static __always_inline uint8_t LZd_peek(const struct LZ_decoder * const d,
  393. + const unsigned distance)
  394. +{
  395. + unsigned i = d->pos - distance - 1;
  396. + if (d->pos <= distance) i += d->dictionary_size;
  397. + return d->buffer[i];
  398. +}
  399. +
  400. +static __always_inline void LZd_put_byte(struct LZ_decoder * const d,
  401. + const uint8_t b)
  402. +{
  403. + d->buffer[d->pos] = b;
  404. + if (++d->pos >= d->dictionary_size) LZd_flush_data(d);
  405. +}
  406. +
  407. +static void LZd_copy_block(struct LZ_decoder * const d,
  408. + const unsigned distance, unsigned len)
  409. +{
  410. + unsigned i = d->pos - distance - 1;
  411. + bool fast;
  412. + if (d->pos <= distance) {
  413. + i += d->dictionary_size;
  414. + fast = (len <= d->dictionary_size - i && len <= i - d->pos);
  415. + }
  416. + else
  417. + fast = (len < d->dictionary_size - d->pos && len <= d->pos - i);
  418. + if( fast ) { /* no wrap, no overlap */
  419. + memcpy(d->buffer + d->pos, d->buffer + i, len);
  420. + d->pos += len;
  421. + } else for (; len > 0; --len) {
  422. + d->buffer[d->pos] = d->buffer[i];
  423. + if (++d->pos >= d->dictionary_size) LZd_flush_data(d);
  424. + if (++i >= d->dictionary_size) i = 0;
  425. + }
  426. +}
  427. +
  428. +static bool LZd_init(struct LZ_decoder * const d,
  429. + struct Range_decoder * const rde,
  430. + const unsigned dict_size, const int ofd)
  431. +{
  432. + d->partial_data_pos = 0;
  433. + d->rdec = rde;
  434. + d->dictionary_size = dict_size;
  435. + d->buffer = (uint8_t *) malloc(d->dictionary_size);
  436. + if (!d->buffer) return false;
  437. + d->pos = 0;
  438. + d->stream_pos = 0;
  439. + d->crc = 0xFFFFFFFFU;
  440. + d->outfd = ofd;
  441. + d->pos_wrapped = false;
  442. + d->write_error = false;
  443. + d->buffer[d->dictionary_size - 1] = 0; /* prev_byte of first byte */
  444. + return true;
  445. +}
  446. +
  447. +static inline uint32_t LZd_crc(const struct LZ_decoder * const d)
  448. +{
  449. + return d->crc ^ 0xFFFFFFFFU;
  450. +}
  451. +
  452. +static __always_inline unsigned long long
  453. +LZd_data_position(const struct LZ_decoder * const d)
  454. +{
  455. + return d->partial_data_pos + d->pos;
  456. +}
  457. +
  458. +
  459. +static bool LZd_verify_trailer(struct LZ_decoder * const d)
  460. +{
  461. + Lzip_trailer trailer;
  462. + int i = 0;
  463. + while (i < Lt_size)
  464. + trailer[i++] = Rd_get_byte(d->rdec);
  465. +
  466. + return (Lt_get_data_crc(trailer) == LZd_crc(d) &&
  467. + Lt_get_data_size(trailer) == LZd_data_position(d) &&
  468. + Lt_get_member_size(trailer) == Rd_member_position(d->rdec));
  469. +}
  470. +
  471. +
  472. +/* Return value: -1 = write error, 0 = OK, 1 = data error. */
  473. +static int LZd_decode_member(struct LZ_decoder * const d)
  474. +{
  475. + struct Range_decoder * const rdec = d->rdec;
  476. + Bit_model bm_literal[1 << literal_context_bits][0x300];
  477. + Bit_model bm_match[states][pos_states];
  478. + Bit_model bm_rep[states];
  479. + Bit_model bm_rep0[states];
  480. + Bit_model bm_rep1[states];
  481. + Bit_model bm_rep2[states];
  482. + Bit_model bm_len[states][pos_states];
  483. + Bit_model bm_dis_slot[len_states][1 << dis_slot_bits];
  484. + Bit_model bm_dis[modeled_distances-end_dis_model+1];
  485. + Bit_model bm_align[dis_align_size];
  486. + struct Len_model match_len_model;
  487. + struct Len_model rep_len_model;
  488. + unsigned rep0 = 0; /* rep[0-3] latest four distances */
  489. + unsigned rep1 = 0; /* used for efficient coding of */
  490. + unsigned rep2 = 0; /* repeated distances */
  491. + unsigned rep3 = 0;
  492. + State state = 0;
  493. +
  494. + Bm_array_init(bm_literal[0], (1 << literal_context_bits) * 0x300);
  495. + Bm_array_init(bm_match[0], states * pos_states);
  496. + Bm_array_init(bm_rep, states);
  497. + Bm_array_init(bm_rep0, states);
  498. + Bm_array_init(bm_rep1, states);
  499. + Bm_array_init(bm_rep2, states);
  500. + Bm_array_init(bm_len[0], states * pos_states);
  501. + Bm_array_init(bm_dis_slot[0], len_states * (1 << dis_slot_bits));
  502. + Bm_array_init(bm_dis, modeled_distances - end_dis_model + 1);
  503. + Bm_array_init(bm_align, dis_align_size);
  504. + Lm_init(&match_len_model);
  505. + Lm_init(&rep_len_model);
  506. +
  507. + Rd_load(rdec);
  508. + while (!Rd_finished(rdec)) {
  509. + int len;
  510. + const int pos_state = LZd_data_position(d) & pos_state_mask;
  511. + if (Rd_decode_bit(rdec, &bm_match[state][pos_state]) == 0) {
  512. + /* literal byte */
  513. + Bit_model * const bm = bm_literal[get_lit_state(LZd_peek_prev(d))];
  514. + if (St_is_char(state)) {
  515. + state -= (state < 4) ? state : 3;
  516. + LZd_put_byte(d, Rd_decode_tree(rdec, bm, 8));
  517. + } else {
  518. + state -= (state < 10) ? 3 : 6;
  519. + LZd_put_byte(d, Rd_decode_matched(rdec, bm, LZd_peek(d, rep0)));
  520. + }
  521. + continue;
  522. + }
  523. + /* match or repeated match */
  524. + if (Rd_decode_bit(rdec, &bm_rep[state]) != 0) {
  525. + if (Rd_decode_bit(rdec, &bm_rep0[state]) == 0) {
  526. + if (Rd_decode_bit(rdec, &bm_len[state][pos_state]) == 0) {
  527. + state = St_set_short_rep(state);
  528. + LZd_put_byte(d, LZd_peek(d, rep0));
  529. + continue;
  530. + }
  531. + } else {
  532. + unsigned distance;
  533. + if (Rd_decode_bit(rdec, &bm_rep1[state]) == 0)
  534. + distance = rep1;
  535. + else {
  536. + if (Rd_decode_bit(rdec, &bm_rep2[state]) == 0)
  537. + distance = rep2;
  538. + else {
  539. + distance = rep3;
  540. + rep3 = rep2;
  541. + }
  542. + rep2 = rep1;
  543. + }
  544. + rep1 = rep0;
  545. + rep0 = distance;
  546. + }
  547. + state = St_set_rep(state);
  548. + len = min_match_len + Rd_decode_len(rdec, &rep_len_model, pos_state);
  549. + } else { /* match */
  550. + unsigned distance;
  551. + len = min_match_len + Rd_decode_len(rdec, &match_len_model, pos_state);
  552. + distance = Rd_decode_tree(rdec, bm_dis_slot[get_len_state(len)], 6);
  553. + if (distance >= start_dis_model) {
  554. + const unsigned dis_slot = distance;
  555. + const int direct_bits = (dis_slot >> 1) - 1;
  556. + distance = (2 | (dis_slot & 1)) << direct_bits;
  557. + if (dis_slot < end_dis_model)
  558. + distance += Rd_decode_tree_reversed(rdec,
  559. + bm_dis + (distance - dis_slot), direct_bits);
  560. + else {
  561. + distance +=
  562. + Rd_decode(rdec, direct_bits - dis_align_bits) << dis_align_bits;
  563. + distance += Rd_decode_tree_reversed(rdec, bm_align, dis_align_bits);
  564. + if (distance == 0xFFFFFFFFU) { /* marker found */
  565. + Rd_normalize(rdec);
  566. + LZd_flush_data(d);
  567. + if (d->write_error) return -1;
  568. + if (len == min_match_len && /* End Of Stream marker */
  569. + LZd_verify_trailer(d))
  570. + return 0;
  571. + if (len == min_match_len + 1) { /* Sync Flush marker */
  572. + Rd_load(rdec);
  573. + continue;
  574. + }
  575. + return 1;
  576. + }
  577. + }
  578. + }
  579. + rep3 = rep2; rep2 = rep1; rep1 = rep0; rep0 = distance;
  580. + state = St_set_match(state);
  581. + if (rep0 >= d->dictionary_size ||
  582. + (rep0 >= d->pos && !d->pos_wrapped)) {
  583. + LZd_flush_data(d);
  584. + return 1;
  585. + }
  586. + }
  587. + LZd_copy_block(d, rep0, len);
  588. + }
  589. + LZd_flush_data(d);
  590. + return 1;
  591. +}
  592. +
  593. +
  594. +IF_DESKTOP(long long) int FAST_FUNC
  595. +unpack_lz_stream(transformer_state_t *xstate)
  596. +{
  597. + IF_DESKTOP(long long) int total = 0;
  598. + struct Range_decoder rdec;
  599. + bool first_member;
  600. + const bool magic_skipped = (xstate->signature_skipped != 0);
  601. +
  602. + if (!global_crc32_table)
  603. + global_crc32_new_table_le();
  604. +
  605. + if (!Rd_init(&rdec, xstate->src_fd, magic_skipped))
  606. + return -1;
  607. +
  608. + for (first_member = true;; first_member = false) {
  609. + int tmp = 0;
  610. + Lzip_header header;
  611. + struct LZ_decoder decoder;
  612. +
  613. + if (first_member && magic_skipped) {
  614. + Lh_set_magic(header);
  615. + tmp = 4;
  616. + } else {
  617. + Rd_reset_member_position(&rdec);
  618. + }
  619. + while (tmp < Lh_size)
  620. + header[tmp++] = Rd_get_byte(&rdec);
  621. + if (Rd_finished(&rdec)) { /* End Of File */
  622. + if (first_member) {
  623. + bb_error_msg(bb_msg_read_error);
  624. + total = -1;
  625. + }
  626. + break;
  627. + }
  628. + tmp = Lh_get_dictionary_size(header);
  629. + if (!Lh_verify_magic(header) || tmp < min_dictionary_size ||
  630. + tmp > max_dictionary_size) {
  631. + if (!first_member)
  632. + break; /* trailing garbage */
  633. + bb_error_msg("invalid magic");
  634. + total = -1;
  635. + break;
  636. + }
  637. +
  638. + if (!LZd_init(&decoder, &rdec, tmp, xstate->dst_fd)) {
  639. + bb_error_msg(bb_msg_memory_exhausted);
  640. + total = -1;
  641. + break;
  642. + }
  643. + tmp = LZd_decode_member(&decoder);
  644. + IF_DESKTOP(total += Rd_member_position(&rdec);)
  645. + free(decoder.buffer);
  646. + if (tmp != 0) {
  647. + if (tmp < 0)
  648. + bb_perror_msg(bb_msg_write_error);
  649. + else
  650. + bb_error_msg("corrupted data");
  651. + total = -1;
  652. + break;
  653. + }
  654. + }
  655. + free(rdec.buffer);
  656. + return total;
  657. +}
  658. diff -urdN busybox-1.29.1.old/archival/libarchive/filter_accept_list_reassign.c busybox-1.29.1.new/archival/libarchive/filter_accept_list_reassign.c
  659. --- busybox-1.29.1.old/archival/libarchive/filter_accept_list_reassign.c 2018-07-02 13:23:06.000000000 +0200
  660. +++ busybox-1.29.1.new/archival/libarchive/filter_accept_list_reassign.c 2018-07-17 00:03:25.000000000 +0200
  661. @@ -43,6 +43,12 @@
  662. archive_handle->dpkg__action_data_subarchive = get_header_tar_bz2;
  663. return EXIT_SUCCESS;
  664. }
  665. + if (ENABLE_FEATURE_SEAMLESS_LZ
  666. + && strcmp(name_ptr, "lz") == 0
  667. + ) {
  668. + archive_handle->dpkg__action_data_subarchive = get_header_tar_lz;
  669. + return EXIT_SUCCESS;
  670. + }
  671. if (ENABLE_FEATURE_SEAMLESS_LZMA
  672. && strcmp(name_ptr, "lzma") == 0
  673. ) {
  674. diff -urdN busybox-1.29.1.old/archival/libarchive/get_header_tar_lz.c busybox-1.29.1.new/archival/libarchive/get_header_tar_lz.c
  675. --- busybox-1.29.1.old/archival/libarchive/get_header_tar_lz.c 1970-01-01 01:00:00.000000000 +0100
  676. +++ busybox-1.29.1.new/archival/libarchive/get_header_tar_lz.c 2018-07-19 20:26:44.000000000 +0200
  677. @@ -0,0 +1,20 @@
  678. +/* vi: set sw=4 ts=4: */
  679. +/*
  680. + * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  681. + */
  682. +#include "libbb.h"
  683. +#include "bb_archive.h"
  684. +
  685. +char FAST_FUNC get_header_tar_lz(archive_handle_t *archive_handle)
  686. +{
  687. + /* Can't lseek over pipes */
  688. + archive_handle->seek = seek_by_read;
  689. +
  690. + fork_transformer_with_sig(archive_handle->src_fd, unpack_lz_stream, "lunzip");
  691. + archive_handle->offset = 0;
  692. + while (get_header_tar(archive_handle) == EXIT_SUCCESS)
  693. + continue;
  694. +
  695. + /* Can only do one file at a time */
  696. + return EXIT_FAILURE;
  697. +}
  698. diff -urdN busybox-1.29.1.old/archival/libarchive/lzip.h busybox-1.29.1.new/archival/libarchive/lzip.h
  699. --- busybox-1.29.1.old/archival/libarchive/lzip.h 1970-01-01 01:00:00.000000000 +0100
  700. +++ busybox-1.29.1.new/archival/libarchive/lzip.h 2018-07-17 14:06:36.000000000 +0200
  701. @@ -0,0 +1,249 @@
  702. +/* Lzip - LZMA lossless data compressor
  703. + Copyright (C) 2008-2018 Antonio Diaz Diaz.
  704. +
  705. + This program is free software: you can redistribute it and/or modify
  706. + it under the terms of the GNU General Public License as published by
  707. + the Free Software Foundation, either version 2 of the License, or
  708. + (at your option) any later version.
  709. +
  710. + This program is distributed in the hope that it will be useful,
  711. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  712. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  713. + GNU General Public License for more details.
  714. +
  715. + You should have received a copy of the GNU General Public License
  716. + along with this program. If not, see <http://www.gnu.org/licenses/>.
  717. +*/
  718. +
  719. +typedef int State;
  720. +
  721. +enum { states = 12 };
  722. +
  723. +static inline bool St_is_char(const State st) { return st < 7; }
  724. +
  725. +static inline State St_set_char(const State st)
  726. +{
  727. + static const State next[states] = { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 };
  728. + return next[st];
  729. +}
  730. +
  731. +static inline State St_set_match(const State st)
  732. +{
  733. + return ((st < 7) ? 7 : 10);
  734. +}
  735. +
  736. +static inline State St_set_rep(const State st)
  737. +{
  738. + return ((st < 7) ? 8 : 11);
  739. +}
  740. +
  741. +static inline State St_set_short_rep(const State st)
  742. +{
  743. + return ((st < 7) ? 9 : 11);
  744. +}
  745. +
  746. +
  747. +enum {
  748. + min_dictionary_bits = 12,
  749. + min_dictionary_size = 1 << min_dictionary_bits, /* >= modeled_distances */
  750. + max_dictionary_bits = 29,
  751. + max_dictionary_size = 1 << max_dictionary_bits,
  752. + literal_context_bits = 3,
  753. + pos_state_bits = 2,
  754. + pos_states = 1 << pos_state_bits,
  755. + pos_state_mask = pos_states - 1,
  756. +
  757. + len_states = 4,
  758. + dis_slot_bits = 6,
  759. + start_dis_model = 4,
  760. + end_dis_model = 14,
  761. + modeled_distances = 1 << (end_dis_model / 2), /* 128 */
  762. + dis_align_bits = 4,
  763. + dis_align_size = 1 << dis_align_bits,
  764. +
  765. + len_low_bits = 3,
  766. + len_mid_bits = 3,
  767. + len_high_bits = 8,
  768. + len_low_symbols = 1 << len_low_bits,
  769. + len_mid_symbols = 1 << len_mid_bits,
  770. + len_high_symbols = 1 << len_high_bits,
  771. + max_len_symbols = len_low_symbols + len_mid_symbols + len_high_symbols,
  772. +
  773. + min_match_len = 2, /* must be 2 */
  774. + max_match_len = min_match_len + max_len_symbols - 1, /* 273 */
  775. + min_match_len_limit = 5,
  776. +
  777. + lz_num_models =
  778. + ((1 << literal_context_bits) * 0x300) +
  779. + (2 * states * pos_states) +
  780. + (4 * states) +
  781. + (len_states * (1 << dis_slot_bits)) +
  782. + (modeled_distances - end_dis_model + 1) +
  783. + dis_align_size,
  784. +};
  785. +
  786. +static inline int get_len_state(const int len)
  787. +{
  788. + return MIN(len - min_match_len, len_states - 1);
  789. +}
  790. +
  791. +static inline int get_lit_state(const uint8_t prev_byte)
  792. +{
  793. + return (prev_byte >> (8 - literal_context_bits));
  794. +}
  795. +
  796. +
  797. +enum { bit_model_move_bits = 5,
  798. + bit_model_total_bits = 11,
  799. + bit_model_total = 1 << bit_model_total_bits
  800. +};
  801. +
  802. +typedef int Bit_model;
  803. +
  804. +static inline void Bm_init(Bit_model * const probability)
  805. +{
  806. + *probability = bit_model_total / 2;
  807. +}
  808. +
  809. +static inline void Bm_array_init(Bit_model bm[], const int size)
  810. +{
  811. + int i;
  812. + for (i = 0; i < size; ++i)
  813. + Bm_init(&bm[i]);
  814. +}
  815. +
  816. +struct Len_model {
  817. + Bit_model choice1;
  818. + Bit_model choice2;
  819. + Bit_model bm_low[pos_states][len_low_symbols];
  820. + Bit_model bm_mid[pos_states][len_mid_symbols];
  821. + Bit_model bm_high[len_high_symbols];
  822. +};
  823. +
  824. +static inline void Lm_init(struct Len_model * const lm)
  825. +{
  826. + Bm_init(&lm->choice1);
  827. + Bm_init(&lm->choice2);
  828. + Bm_array_init(lm->bm_low[0], pos_states * len_low_symbols);
  829. + Bm_array_init(lm->bm_mid[0], pos_states * len_mid_symbols);
  830. + Bm_array_init(lm->bm_high, len_high_symbols);
  831. +}
  832. +
  833. +
  834. +static inline int real_bits(unsigned value)
  835. +{
  836. + int bits = 0;
  837. + while(value > 0) { value >>= 1; ++bits; }
  838. + return bits;
  839. +}
  840. +
  841. +
  842. +static const uint8_t lzip_magic[4] = { 0x4C, 0x5A, 0x49, 0x50 }; /* "LZIP" */
  843. +
  844. +typedef uint8_t Lzip_header[6]; /* 0-3 magic bytes */
  845. + /* 4 version */
  846. + /* 5 coded_dict_size */
  847. +enum { Lh_size = 6 };
  848. +
  849. +static inline void Lh_set_magic(Lzip_header data)
  850. +{
  851. + memcpy(data, lzip_magic, 4);
  852. + data[4] = 1;
  853. +}
  854. +
  855. +static inline bool Lh_verify_magic(const Lzip_header data)
  856. +{
  857. + return (memcmp(data, lzip_magic, 4) == 0 && data[4] == 1);
  858. +}
  859. +
  860. +static inline unsigned Lh_get_dictionary_size(const Lzip_header data)
  861. +{
  862. + unsigned sz = (1 << (data[5] & 0x1F));
  863. + if (sz > min_dictionary_size)
  864. + sz -= (sz / 16) * ((data[5] >> 5) & 7);
  865. + return sz;
  866. +}
  867. +
  868. +static inline bool Lh_set_dictionary_size(Lzip_header data, const unsigned sz)
  869. +{
  870. + if (sz < min_dictionary_size || sz > max_dictionary_size) return false;
  871. + data[5] = real_bits(sz - 1);
  872. + if (sz > min_dictionary_size) {
  873. + const unsigned base_size = 1 << data[5];
  874. + const unsigned fraction = base_size / 16;
  875. + unsigned i;
  876. + for (i = 7; i >= 1; --i)
  877. + if (base_size - (i * fraction) >= sz) {
  878. + data[5] |= (i << 5);
  879. + break;
  880. + }
  881. + }
  882. + return true;
  883. +}
  884. +
  885. +
  886. +typedef uint8_t Lzip_trailer[20];
  887. + /* 0-3 CRC32 of the uncompressed data */
  888. + /* 4-11 size of the uncompressed data */
  889. + /* 12-19 member size including header and trailer */
  890. +enum { Lt_size = 20 };
  891. +
  892. +static inline unsigned Lt_get_data_crc(const Lzip_trailer data)
  893. +{
  894. + unsigned tmp = 0;
  895. + int i;
  896. + for (i = 3; i >= 0; --i) {
  897. + tmp <<= 8;
  898. + tmp += data[i];
  899. + }
  900. + return tmp;
  901. +}
  902. +
  903. +static inline void Lt_set_data_crc(Lzip_trailer data, unsigned crc)
  904. +{
  905. + int i;
  906. + for (i = 0; i <= 3; ++i) {
  907. + data[i] = (uint8_t)crc;
  908. + crc >>= 8;
  909. + }
  910. +}
  911. +
  912. +static inline unsigned long long Lt_get_data_size(const Lzip_trailer data)
  913. +{
  914. + unsigned long long tmp = 0;
  915. + int i;
  916. + for (i = 11; i >= 4; --i) {
  917. + tmp <<= 8;
  918. + tmp += data[i];
  919. + }
  920. + return tmp;
  921. +}
  922. +
  923. +static inline void Lt_set_data_size(Lzip_trailer data, unsigned long long sz)
  924. +{
  925. + int i;
  926. + for (i = 4; i <= 11; ++i) {
  927. + data[i] = (uint8_t)sz;
  928. + sz >>= 8;
  929. + }
  930. +}
  931. +
  932. +static inline unsigned long long Lt_get_member_size(const Lzip_trailer data)
  933. +{
  934. + unsigned long long tmp = 0;
  935. + int i;
  936. + for (i = 19; i >= 12; --i) {
  937. + tmp <<= 8;
  938. + tmp += data[i];
  939. + }
  940. + return tmp;
  941. +}
  942. +
  943. +static inline void Lt_set_member_size(Lzip_trailer data, unsigned long long sz)
  944. +{
  945. + int i;
  946. + for (i = 12; i <= 19; ++i) {
  947. + data[i] = (uint8_t)sz;
  948. + sz >>= 8;
  949. + }
  950. +}
  951. diff -urdN busybox-1.29.1.old/archival/libarchive/open_transformer.c busybox-1.29.1.new/archival/libarchive/open_transformer.c
  952. --- busybox-1.29.1.old/archival/libarchive/open_transformer.c 2018-07-02 13:23:06.000000000 +0200
  953. +++ busybox-1.29.1.new/archival/libarchive/open_transformer.c 2018-07-17 00:03:25.000000000 +0200
  954. @@ -194,6 +194,17 @@
  955. USE_FOR_NOMMU(xstate->xformer_prog = "bunzip2";)
  956. goto found_magic;
  957. }
  958. + if (ENABLE_FEATURE_SEAMLESS_LZ
  959. + && magic.b16[0] == LZIP_MAGIC1
  960. + ) {
  961. + xstate->signature_skipped = 4;
  962. + xread(fd, magic.b16, sizeof(magic.b16[0]));
  963. + if (magic.b16[0] == LZIP_MAGIC2) {
  964. + xstate->xformer = unpack_lz_stream;
  965. + USE_FOR_NOMMU(xstate->xformer_prog = "lunzip";)
  966. + goto found_magic;
  967. + }
  968. + }
  969. if (ENABLE_FEATURE_SEAMLESS_XZ
  970. && magic.b16[0] == XZ_MAGIC1
  971. ) {
  972. @@ -210,6 +221,7 @@
  973. if (fail_if_not_compressed)
  974. bb_error_msg_and_die("no gzip"
  975. IF_FEATURE_SEAMLESS_BZ2("/bzip2")
  976. + IF_FEATURE_SEAMLESS_LZ("/lzip")
  977. IF_FEATURE_SEAMLESS_XZ("/xz")
  978. " magic");
  979. diff -urdN busybox-1.29.1.old/archival/lzip.c busybox-1.29.1.new/archival/lzip.c
  980. --- busybox-1.29.1.old/archival/lzip.c 1970-01-01 01:00:00.000000000 +0100
  981. +++ busybox-1.29.1.new/archival/lzip.c 2018-07-20 16:23:47.000000000 +0200
  982. @@ -0,0 +1,1433 @@
  983. +/*
  984. + * lzip implementation for busybox
  985. + *
  986. + * Copyright (C) 2012-2018 Antonio Diaz Diaz.
  987. + *
  988. + * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  989. + */
  990. +
  991. +//config:config LZIP
  992. +//config: bool "lzip"
  993. +//config: default y
  994. +//config: help
  995. +//config: lzip is a lossless data compressor with a user interface similar to
  996. +//config: the one of gzip or bzip2. lzip can compress about as fast as gzip or
  997. +//config: compress most files more than bzip2 (depending on compression level).
  998. +//config: Decompression speed is intermediate between gzip and bzip2. lzip is
  999. +//config: better than gzip and bzip2 from a data recovery perspective.
  1000. +//config:
  1001. +//config:config FEATURE_LZIP_DECOMPRESS
  1002. +//config: bool "Enable decompression"
  1003. +//config: default y
  1004. +//config: depends on LZIP || LUNZIP
  1005. +//config: help
  1006. +//config: Enable -d (--decompress) and -t (--test) options for lzip.
  1007. +//config: This will be automatically selected if lunzip is enabled.
  1008. +
  1009. +//applet:IF_LZIP(APPLET(lzip, BB_DIR_USR_BIN, BB_SUID_DROP))
  1010. +
  1011. +//kbuild:lib-$(CONFIG_LZIP) += lzip.o
  1012. +
  1013. +//usage:#define lzip_trivial_usage
  1014. +//usage: "[-123456789c"
  1015. +//usage: IF_FEATURE_LZIP_DECOMPRESS("d") "fk"
  1016. +//usage: IF_FEATURE_LZIP_DECOMPRESS("t")
  1017. +//usage: "] [-m MATCH_LENGTH] [-s DICT_SIZE] [FILE]..."
  1018. +//usage:#define lzip_full_usage "\n\n"
  1019. +//usage: "Compress FILEs (or stdin) with lzip algorithm\n"
  1020. +//usage: "\n -1..9 Compression level"
  1021. +//usage: "\n -c Write to stdout"
  1022. +//usage: IF_FEATURE_LZIP_DECOMPRESS("\n -d Decompress")
  1023. +//usage: "\n -f Force"
  1024. +//usage: "\n -k Keep input files"
  1025. +//usage: "\n -m Match length limit [36]"
  1026. +//usage: "\n -s Dictionary size limit [8MiB]"
  1027. +//usage: IF_FEATURE_LZIP_DECOMPRESS("\n -t Test compressed file integrity")
  1028. +
  1029. +
  1030. +#include "libbb.h"
  1031. +#include "bb_archive.h"
  1032. +#include "libarchive/lzip.h"
  1033. +
  1034. +
  1035. +#if CHAR_BIT != 8
  1036. +#error "Environments where CHAR_BIT != 8 are not supported."
  1037. +#endif
  1038. +
  1039. +
  1040. +static void CRC32_update_byte(uint32_t * crc, const uint8_t byte)
  1041. +{
  1042. + *crc = global_crc32_table[(*crc ^ byte) & 0xFF] ^ (*crc >> 8);
  1043. +}
  1044. +
  1045. +
  1046. +enum { max_num_trials = 1 << 12,
  1047. + price_shift_bits = 6,
  1048. + price_step_bits = 2,
  1049. + price_step = 1 << price_step_bits
  1050. +};
  1051. +
  1052. +
  1053. +static uint8_t * dis_slots;
  1054. +
  1055. +static void Dis_slots_init(void)
  1056. +{
  1057. + int i, size, slot;
  1058. + dis_slots = xmalloc((1 << 10) * sizeof dis_slots[0]);
  1059. +
  1060. + for (slot = 0; slot < 4; ++slot) dis_slots[slot] = slot;
  1061. + for (i = 4, size = 2, slot = 4; slot < 20; slot += 2) {
  1062. + memset(&dis_slots[i], slot, size);
  1063. + memset(&dis_slots[i + size], slot + 1, size);
  1064. + size <<= 1;
  1065. + i += size;
  1066. + }
  1067. +}
  1068. +
  1069. +static uint8_t get_slot(const unsigned dis)
  1070. +{
  1071. + if (dis < (1 << 10)) return dis_slots[dis];
  1072. + if (dis < (1 << 19)) return dis_slots[dis>> 9] + 18;
  1073. + if (dis < (1 << 28)) return dis_slots[dis>>18] + 36;
  1074. + return dis_slots[dis>>27] + 54;
  1075. +}
  1076. +
  1077. +
  1078. +static int * prob_prices;
  1079. +
  1080. +static void Prob_prices_init(void)
  1081. +{
  1082. + int i, j;
  1083. + prob_prices =
  1084. + xmalloc((bit_model_total >> price_step_bits) * sizeof prob_prices[0]);
  1085. + for( i = 0; i < bit_model_total >> price_step_bits; ++i ) {
  1086. + unsigned val = ( i * price_step ) + ( price_step / 2 );
  1087. + int bits = 0; /* base 2 logarithm of val */
  1088. + for( j = 0; j < price_shift_bits; ++j ) {
  1089. + val = val * val;
  1090. + bits <<= 1;
  1091. + while( val >= 1 << 16 ) { val >>= 1; ++bits; }
  1092. + }
  1093. + bits += 15; /* remaining bits in val */
  1094. + prob_prices[i] = ( bit_model_total_bits << price_shift_bits ) - bits;
  1095. + }
  1096. +}
  1097. +
  1098. +static inline int get_price(const int probability)
  1099. +{
  1100. + return prob_prices[probability >> price_step_bits];
  1101. +}
  1102. +
  1103. +
  1104. +static inline int price0(const Bit_model probability)
  1105. +{
  1106. + return get_price(probability);
  1107. +}
  1108. +
  1109. +static inline int price1(const Bit_model probability)
  1110. +{
  1111. + return get_price(bit_model_total - probability);
  1112. +}
  1113. +
  1114. +static int price_bit(const Bit_model bm, const bool bit)
  1115. +{
  1116. + return (bit ? price1(bm) : price0(bm));
  1117. +}
  1118. +
  1119. +
  1120. +static int price_symbol(const Bit_model bm[], int symbol, const int num_bits)
  1121. +{
  1122. + int price = 0;
  1123. + symbol |= (1 << num_bits);
  1124. + while (symbol > 1) {
  1125. + const bool bit = symbol & 1;
  1126. + symbol >>= 1;
  1127. + price += price_bit(bm[symbol], bit);
  1128. + }
  1129. + return price;
  1130. +}
  1131. +
  1132. +
  1133. +static int price_symbol_reversed(const Bit_model bm[], int symbol,
  1134. + const int num_bits)
  1135. +{
  1136. + int price = 0;
  1137. + int model = 1;
  1138. + int i;
  1139. + for (i = num_bits; i > 0; --i) {
  1140. + const bool bit = symbol & 1;
  1141. + symbol >>= 1;
  1142. + price += price_bit(bm[model], bit);
  1143. + model = (model << 1) | bit;
  1144. + }
  1145. + return price;
  1146. +}
  1147. +
  1148. +
  1149. +static int price_matched(const Bit_model bm[], unsigned symbol,
  1150. + unsigned match_byte)
  1151. +{
  1152. + int price = 0;
  1153. + unsigned mask = 0x100;
  1154. + symbol |= mask;
  1155. +
  1156. + while (true) {
  1157. + const unsigned match_bit = (match_byte <<= 1) & mask;
  1158. + const bool bit = (symbol <<= 1) & 0x100;
  1159. + price += price_bit( bm[(symbol>>9)+match_bit+mask], bit );
  1160. + if (symbol >= 0x10000) return price;
  1161. + mask &= ~(match_bit ^ symbol); /* if( match_bit != bit ) mask = 0; */
  1162. + }
  1163. +}
  1164. +
  1165. +
  1166. +enum { /* bytes to keep in buffer before dictionary */
  1167. + before_size = max_num_trials,
  1168. + /* bytes to keep in buffer after pos */
  1169. + after_size = ( 2 * max_match_len ) + 1,
  1170. + num_prev_positions3 = 1 << 16,
  1171. + num_prev_positions2 = 1 << 10,
  1172. + num_prev_positions23 = num_prev_positions2 + num_prev_positions3
  1173. +};
  1174. +
  1175. +struct Matchfinder {
  1176. + unsigned long long partial_data_pos;
  1177. + uint8_t *buffer; /* input buffer */
  1178. + int32_t *prev_positions; /* 1 + last seen position of key. else 0 */
  1179. + int32_t *pos_array; /* tree of previous positions of key */
  1180. + int match_len_limit;
  1181. + int buffer_size;
  1182. + int dictionary_size; /* bytes to keep in buffer before pos */
  1183. + int pos; /* current pos in buffer */
  1184. + int cyclic_pos; /* current pos in dictionary */
  1185. + int stream_pos; /* first byte not yet read from file */
  1186. + int pos_limit; /* when reached, a new block must be read */
  1187. + int key4_mask;
  1188. + int num_prev_positions; /* size of prev_positions */
  1189. + int pos_array_size;
  1190. + int cycles;
  1191. + bool at_stream_end; /* stream_pos shows real end of file */
  1192. +};
  1193. +
  1194. +static bool Mf_read_block(struct Matchfinder * const mf)
  1195. +{
  1196. + if (!mf->at_stream_end && mf->stream_pos < mf->buffer_size) {
  1197. + const int size = mf->buffer_size - mf->stream_pos;
  1198. + const int rd = full_read(STDIN_FILENO,
  1199. + mf->buffer + mf->stream_pos, size);
  1200. + mf->stream_pos += rd;
  1201. + if (rd < size) {
  1202. + mf->at_stream_end = true;
  1203. + mf->pos_limit = mf->buffer_size;
  1204. + }
  1205. + }
  1206. + return mf->pos < mf->stream_pos;
  1207. +}
  1208. +
  1209. +static void Mf_normalize_pos(struct Matchfinder * const mf)
  1210. +{
  1211. + int i;
  1212. + const int offset = mf->pos - before_size - mf->dictionary_size;
  1213. + const int size = mf->stream_pos - offset;
  1214. + if (mf->at_stream_end) return;
  1215. + memmove(mf->buffer, mf->buffer + offset, size);
  1216. + mf->partial_data_pos += offset;
  1217. + mf->pos -= offset; /* pos = before_size + dictionary_size */
  1218. + mf->stream_pos -= offset;
  1219. + for (i = 0; i < mf->num_prev_positions; ++i)
  1220. + mf->prev_positions[i] -= MIN(mf->prev_positions[i], offset);
  1221. + for (i = 0; i < mf->pos_array_size; ++i)
  1222. + mf->pos_array[i] -= MIN(mf->pos_array[i], offset);
  1223. + Mf_read_block(mf);
  1224. +}
  1225. +
  1226. +static bool Mf_init(struct Matchfinder * const mf, const int dict_size,
  1227. + const int match_len_limit)
  1228. +{
  1229. + const int buffer_size_limit = (2 * dict_size) + before_size + after_size;
  1230. + unsigned size;
  1231. + int i;
  1232. +
  1233. + mf->partial_data_pos = 0;
  1234. + mf->match_len_limit = match_len_limit;
  1235. + mf->pos = 0;
  1236. + mf->cyclic_pos = 0;
  1237. + mf->stream_pos = 0;
  1238. + mf->cycles = (match_len_limit < max_match_len) ?
  1239. + 16 + (match_len_limit / 2) : 256;
  1240. + mf->at_stream_end = false;
  1241. +
  1242. + mf->buffer_size = MAX(65536, dict_size);
  1243. + mf->buffer = (uint8_t *) malloc(mf->buffer_size);
  1244. + if (!mf->buffer) return false;
  1245. + if (Mf_read_block(mf) && !mf->at_stream_end &&
  1246. + mf->buffer_size < buffer_size_limit) {
  1247. + uint8_t *tmp;
  1248. + mf->buffer_size = buffer_size_limit;
  1249. + tmp = (uint8_t *) realloc(mf->buffer, mf->buffer_size);
  1250. + if (!tmp) { free(mf->buffer); return false; }
  1251. + mf->buffer = tmp;
  1252. + Mf_read_block(mf);
  1253. + }
  1254. + if (mf->at_stream_end && mf->stream_pos < dict_size)
  1255. + mf->dictionary_size = MAX(min_dictionary_size, mf->stream_pos);
  1256. + else
  1257. + mf->dictionary_size = dict_size;
  1258. + mf->pos_limit = mf->buffer_size;
  1259. + if (!mf->at_stream_end) mf->pos_limit -= after_size;
  1260. + size = 1 << MAX(16, real_bits(mf->dictionary_size - 1) - 2);
  1261. + if(mf->dictionary_size > 1 << 26) /* 64 MiB */
  1262. + size >>= 1;
  1263. + mf->key4_mask = size - 1;
  1264. + size += num_prev_positions23;
  1265. + mf->num_prev_positions = size;
  1266. +
  1267. + mf->pos_array_size = 2 * (mf->dictionary_size + 1);
  1268. + size += mf->pos_array_size;
  1269. + if (size * sizeof mf->prev_positions[0] <= size) mf->prev_positions = 0;
  1270. + else mf->prev_positions =
  1271. + (int32_t *) malloc(size * sizeof mf->prev_positions[0]);
  1272. + if (!mf->prev_positions) { free(mf->buffer); return false; }
  1273. + mf->pos_array = mf->prev_positions + mf->num_prev_positions;
  1274. + for (i = 0; i < mf->num_prev_positions; ++i) mf->prev_positions[i] = 0;
  1275. + return true;
  1276. +}
  1277. +
  1278. +static void Mf_free(struct Matchfinder * const mf)
  1279. +{
  1280. + free(mf->prev_positions);
  1281. + free(mf->buffer);
  1282. +}
  1283. +
  1284. +static inline uint8_t Mf_peek(const struct Matchfinder * const mf,
  1285. + const int distance)
  1286. +{
  1287. + return mf->buffer[mf->pos-distance];
  1288. +}
  1289. +
  1290. +static inline int Mf_available_bytes(const struct Matchfinder * const mf)
  1291. +{
  1292. + return mf->stream_pos - mf->pos;
  1293. +}
  1294. +
  1295. +static inline unsigned long long
  1296. +Mf_data_position(const struct Matchfinder * const mf)
  1297. +{
  1298. + return mf->partial_data_pos + mf->pos;
  1299. +}
  1300. +
  1301. +static inline bool Mf_finished(const struct Matchfinder * const mf)
  1302. +{
  1303. + return mf->at_stream_end && mf->pos >= mf->stream_pos;
  1304. +}
  1305. +
  1306. +static inline const uint8_t *
  1307. +Mf_ptr_to_current_pos(const struct Matchfinder * const mf)
  1308. +{
  1309. + return mf->buffer + mf->pos;
  1310. +}
  1311. +
  1312. +static int Mf_true_match_len(const struct Matchfinder * const mf,
  1313. + const int index, const int distance)
  1314. +{
  1315. + const uint8_t * const data = mf->buffer + mf->pos;
  1316. + int i = index;
  1317. + const int len_limit = MIN(Mf_available_bytes(mf), max_match_len);
  1318. + while (i < len_limit && data[i - distance] == data[i]) ++i;
  1319. + return i;
  1320. +}
  1321. +
  1322. +static void Mf_move_pos(struct Matchfinder * const mf)
  1323. +{
  1324. + if (++mf->cyclic_pos > mf->dictionary_size) mf->cyclic_pos = 0;
  1325. + if (++mf->pos >= mf->pos_limit) Mf_normalize_pos(mf);
  1326. +}
  1327. +
  1328. +static int Mf_longest_match_len(struct Matchfinder * const mf,
  1329. + int * const distances)
  1330. +{
  1331. + int32_t *ptr0 = mf->pos_array + (mf->cyclic_pos << 1);
  1332. + int32_t *ptr1 = ptr0 + 1;
  1333. + int32_t *newptr;
  1334. + int len = 0, len0 = 0, len1 = 0;
  1335. + int maxlen = min_match_len - 1;
  1336. + const int pos1 = mf->pos + 1;
  1337. + const int min_pos = (mf->pos > mf->dictionary_size) ?
  1338. + mf->pos - mf->dictionary_size : 0;
  1339. + const uint8_t * const data = Mf_ptr_to_current_pos(mf);
  1340. + int count, key2, key3, key4, newpos1;
  1341. + unsigned tmp;
  1342. + int len_limit = mf->match_len_limit;
  1343. +
  1344. + if (len_limit > Mf_available_bytes(mf)) {
  1345. + len_limit = Mf_available_bytes(mf);
  1346. + if (len_limit < 4) return 0;
  1347. + }
  1348. +
  1349. + tmp = global_crc32_table[data[0]] ^ data[1];
  1350. + key2 = tmp & (num_prev_positions2 - 1);
  1351. + tmp ^= ((unsigned) data[2] << 8);
  1352. + key3 = num_prev_positions2 + (tmp & (num_prev_positions3 - 1));
  1353. + key4 = num_prev_positions2 + num_prev_positions3 +
  1354. + ((tmp ^ (global_crc32_table[data[3]] << 5)) & mf->key4_mask);
  1355. +
  1356. + if (distances) {
  1357. + int np2 = mf->prev_positions[key2];
  1358. + int np3 = mf->prev_positions[key3];
  1359. + if (np2 > min_pos && mf->buffer[np2-1] == data[0]) {
  1360. + distances[2] = mf->pos - np2;
  1361. + maxlen = 2;
  1362. + } else
  1363. + distances[2] = 0x7FFFFFFF;
  1364. + if (np2 != np3 && np3 > min_pos && mf->buffer[np3-1] == data[0]) {
  1365. + distances[3] = mf->pos - np3;
  1366. + maxlen = 3;
  1367. + } else
  1368. + distances[3] = 0x7FFFFFFF;
  1369. + distances[4] = 0x7FFFFFFF;
  1370. + }
  1371. +
  1372. + mf->prev_positions[key2] = pos1;
  1373. + mf->prev_positions[key3] = pos1;
  1374. + newpos1 = mf->prev_positions[key4];
  1375. + mf->prev_positions[key4] = pos1;
  1376. +
  1377. + for (count = mf->cycles;;) {
  1378. + int delta;
  1379. + if (newpos1 <= min_pos || --count < 0) {
  1380. + *ptr0 = *ptr1 = 0;
  1381. + break;
  1382. + }
  1383. + delta = pos1 - newpos1;
  1384. + newptr = mf->pos_array +
  1385. + ((mf->cyclic_pos - delta +
  1386. + ((mf->cyclic_pos >= delta) ? 0 : mf->dictionary_size + 1)) << 1);
  1387. +
  1388. + if (data[len-delta] == data[len]) {
  1389. + while (++len < len_limit && data[len-delta] == data[len]) {}
  1390. + if (distances && maxlen < len)
  1391. + while (maxlen < len)
  1392. + distances[++maxlen] = delta - 1;
  1393. +
  1394. + if (len >= len_limit) {
  1395. + *ptr0 = newptr[0];
  1396. + *ptr1 = newptr[1];
  1397. + break;
  1398. + }
  1399. + }
  1400. + if (data[len-delta] < data[len]) {
  1401. + *ptr0 = newpos1;
  1402. + ptr0 = newptr + 1;
  1403. + newpos1 = *ptr0;
  1404. + len0 = len;
  1405. + if (len1 < len) len = len1;
  1406. + } else {
  1407. + *ptr1 = newpos1;
  1408. + ptr1 = newptr;
  1409. + newpos1 = *ptr1;
  1410. + len1 = len;
  1411. + if (len0 < len) len = len0;
  1412. + }
  1413. + }
  1414. + if (distances) {
  1415. + if (distances[3] > distances[4])
  1416. + distances[3] = distances[4];
  1417. + if (distances[2] > distances[3])
  1418. + distances[2] = distances[3];
  1419. + }
  1420. + return maxlen;
  1421. +}
  1422. +
  1423. +
  1424. +enum { re_buffer_size = 65536 };
  1425. +
  1426. +struct Range_encoder {
  1427. + uint64_t low;
  1428. + unsigned long long partial_member_pos;
  1429. + uint8_t *buffer; /* output buffer */
  1430. + int pos; /* current pos in buffer */
  1431. + uint32_t range;
  1432. + unsigned ff_count;
  1433. + uint8_t cache;
  1434. + bool write_error;
  1435. +};
  1436. +
  1437. +static void Re_flush_data(struct Range_encoder * const renc)
  1438. +{
  1439. + if (renc->pos > 0) {
  1440. + if (full_write(STDOUT_FILENO, renc->buffer, renc->pos) != renc->pos)
  1441. + renc->write_error = true;
  1442. + renc->partial_member_pos += renc->pos;
  1443. + renc->pos = 0;
  1444. + }
  1445. +}
  1446. +
  1447. +static void Re_put_byte(struct Range_encoder * const renc, const uint8_t b)
  1448. +{
  1449. + renc->buffer[renc->pos] = b;
  1450. + if (++renc->pos >= re_buffer_size) Re_flush_data(renc);
  1451. +}
  1452. +
  1453. +static void Re_shift_low(struct Range_encoder * const renc)
  1454. +{
  1455. + if(renc->low >> 24 != 0xFF) {
  1456. + const bool carry = (renc->low > 0xFFFFFFFFU);
  1457. + Re_put_byte(renc, renc->cache + carry);
  1458. + for (; renc->ff_count > 0; --renc->ff_count)
  1459. + Re_put_byte(renc, 0xFF + carry);
  1460. + renc->cache = renc->low >> 24;
  1461. + } else
  1462. + ++renc->ff_count;
  1463. + renc->low = (renc->low & 0x00FFFFFFU) << 8;
  1464. +}
  1465. +
  1466. +static bool Re_init(struct Range_encoder * const renc)
  1467. +{
  1468. + renc->low = 0;
  1469. + renc->partial_member_pos = 0;
  1470. + renc->buffer = (uint8_t *) malloc(re_buffer_size);
  1471. + if (!renc->buffer) return false;
  1472. + renc->pos = 0;
  1473. + renc->range = 0xFFFFFFFFU;
  1474. + renc->ff_count = 0;
  1475. + renc->cache = 0;
  1476. + renc->write_error = false;
  1477. + return true;
  1478. +}
  1479. +
  1480. +static inline void Re_free(struct Range_encoder * const renc)
  1481. +{
  1482. + free(renc->buffer);
  1483. +}
  1484. +
  1485. +static inline unsigned long long
  1486. +Re_member_position(const struct Range_encoder * const renc)
  1487. +{
  1488. + return renc->partial_member_pos + renc->pos + renc->ff_count;
  1489. +}
  1490. +
  1491. +static void Re_flush(struct Range_encoder * const renc)
  1492. +{
  1493. + int i;
  1494. + for (i = 0; i < 5; ++i) Re_shift_low(renc);
  1495. +}
  1496. +
  1497. +static void Re_encode(struct Range_encoder * const renc,
  1498. + const int symbol, const int num_bits)
  1499. +{
  1500. + unsigned mask;
  1501. + for (mask = 1 << ( num_bits - 1 ); mask > 0; mask >>= 1) {
  1502. + renc->range >>= 1;
  1503. + if (symbol &mask) renc->low += renc->range;
  1504. + if (renc->range <= 0x00FFFFFFU) {
  1505. + renc->range <<= 8;
  1506. + Re_shift_low(renc);
  1507. + }
  1508. + }
  1509. +}
  1510. +
  1511. +static void Re_encode_bit(struct Range_encoder * const renc,
  1512. + Bit_model * const probability, const bool bit)
  1513. +{
  1514. + const uint32_t bound = (renc->range >> bit_model_total_bits) * *probability;
  1515. + if (!bit) {
  1516. + renc->range = bound;
  1517. + *probability += (bit_model_total - *probability) >> bit_model_move_bits;
  1518. + } else {
  1519. + renc->low += bound;
  1520. + renc->range -= bound;
  1521. + *probability -= *probability >> bit_model_move_bits;
  1522. + }
  1523. + if (renc->range <= 0x00FFFFFFU) {
  1524. + renc->range <<= 8;
  1525. + Re_shift_low(renc);
  1526. + }
  1527. +}
  1528. +
  1529. +static void Re_encode_tree(struct Range_encoder * const renc,
  1530. + Bit_model bm[], const int symbol,
  1531. + const int num_bits)
  1532. +{
  1533. + int model = 1;
  1534. + int i;
  1535. + for (i = num_bits - 1; i >= 0; --i) {
  1536. + const bool bit = (symbol >> i) & 1;
  1537. + Re_encode_bit(renc, &bm[model], bit);
  1538. + model = (model << 1) | bit;
  1539. + }
  1540. +}
  1541. +
  1542. +static void Re_encode_tree_reversed(struct Range_encoder * const renc,
  1543. + Bit_model bm[], int symbol, const int num_bits)
  1544. +{
  1545. + int model = 1;
  1546. + int i;
  1547. + for (i = num_bits; i > 0; --i) {
  1548. + const bool bit = symbol & 1;
  1549. + symbol >>= 1;
  1550. + Re_encode_bit(renc, &bm[model], bit);
  1551. + model = (model << 1) | bit;
  1552. + }
  1553. +}
  1554. +
  1555. +static void Re_encode_matched(struct Range_encoder * const renc,
  1556. + Bit_model bm[], unsigned symbol,
  1557. + unsigned match_byte)
  1558. +{
  1559. + unsigned mask = 0x100;
  1560. + symbol |= mask;
  1561. +
  1562. + while (true) {
  1563. + const unsigned match_bit = (match_byte <<= 1) & mask;
  1564. + const bool bit = (symbol <<= 1) & 0x100;
  1565. + Re_encode_bit( renc, &bm[(symbol>>9)+match_bit+mask], bit );
  1566. + if (symbol >= 0x10000) break;
  1567. + mask &= ~(match_bit ^ symbol); /* if( match_bit != bit ) mask = 0; */
  1568. + }
  1569. +}
  1570. +
  1571. +static void Re_encode_len( struct Range_encoder * const renc,
  1572. + struct Len_model * const lm,
  1573. + int symbol, const int pos_state )
  1574. +{
  1575. + bool bit = ( ( symbol -= min_match_len ) >= len_low_symbols );
  1576. + Re_encode_bit( renc, &lm->choice1, bit );
  1577. + if( !bit )
  1578. + Re_encode_tree( renc, lm->bm_low[pos_state], symbol, len_low_bits );
  1579. + else {
  1580. + bit = ((symbol -= len_low_symbols) >= len_mid_symbols );
  1581. + Re_encode_bit( renc, &lm->choice2, bit );
  1582. + if( !bit )
  1583. + Re_encode_tree( renc, lm->bm_mid[pos_state],
  1584. + symbol, len_mid_bits );
  1585. + else
  1586. + Re_encode_tree( renc, lm->bm_high,
  1587. + symbol - len_mid_symbols, len_high_bits );
  1588. + }
  1589. +}
  1590. +
  1591. +
  1592. +struct Len_encoder {
  1593. + struct Len_model lm;
  1594. + int len_symbols;
  1595. + int prices[pos_states][max_len_symbols];
  1596. + int counters[pos_states];
  1597. +};
  1598. +
  1599. +static void Lee_update_prices(struct Len_encoder * const le, const int pos_state)
  1600. +{
  1601. + int * const pps = le->prices[pos_state];
  1602. + int tmp = price0(le->lm.choice1);
  1603. + int len = 0;
  1604. +
  1605. + for (; len < len_low_symbols && len < le->len_symbols; ++len)
  1606. + pps[len] = tmp +
  1607. + price_symbol(le->lm.bm_low[pos_state], len, len_low_bits);
  1608. + tmp = price1(le->lm.choice1);
  1609. + for (; len < len_low_symbols + len_mid_symbols && len < le->len_symbols; ++len)
  1610. + pps[len] = tmp + price0(le->lm.choice2) +
  1611. + price_symbol(le->lm.bm_mid[pos_state],
  1612. + len - len_low_symbols, len_mid_bits);
  1613. + for (; len < le->len_symbols; ++len)
  1614. + /* using 4 slots per value makes "Lee_price" faster */
  1615. + le->prices[3][len] = le->prices[2][len] =
  1616. + le->prices[1][len] = le->prices[0][len] =
  1617. + tmp + price1(le->lm.choice2) +
  1618. + price_symbol(le->lm.bm_high,
  1619. + len - len_low_symbols - len_mid_symbols,
  1620. + len_high_bits);
  1621. + le->counters[pos_state] = le->len_symbols;
  1622. +}
  1623. +
  1624. +static void Lee_init(struct Len_encoder * const le, const int len_limit)
  1625. +{
  1626. + int i;
  1627. + Lm_init(&le->lm);
  1628. + le->len_symbols = len_limit + 1 - min_match_len;
  1629. + for (i = 0; i < pos_states; ++i) Lee_update_prices(le, i);
  1630. +}
  1631. +
  1632. +static void Lee_encode(struct Len_encoder * const le,
  1633. + struct Range_encoder * const renc,
  1634. + int symbol, const int pos_state)
  1635. +{
  1636. + Re_encode_len(renc, &le->lm, symbol, pos_state);
  1637. + if (--le->counters[pos_state] <= 0)
  1638. + Lee_update_prices(le, pos_state);
  1639. +}
  1640. +
  1641. +static int Lee_price(const struct Len_encoder * const le,
  1642. + const int symbol, const int pos_state)
  1643. +{
  1644. + return le->prices[pos_state][symbol - min_match_len];
  1645. +}
  1646. +
  1647. +
  1648. +enum { infinite_price = 0x0FFFFFFF,
  1649. + num_rep_distances = 4 /* must be 4 */
  1650. +};
  1651. +
  1652. +struct Trial {
  1653. + State state;
  1654. + int price; /* dual use var; cumulative price, match length */
  1655. + int dis; /* rep index or match distance. (-1 for literal) */
  1656. + int prev_index; /* index of prev trial in trials[] */
  1657. + int reps[num_rep_distances];
  1658. +};
  1659. +
  1660. +static void Tr_update(struct Trial * const trial, const int pr,
  1661. + const int distance, const int p_i)
  1662. +{
  1663. + if (pr < trial->price) {
  1664. + trial->price = pr;
  1665. + trial->dis = distance;
  1666. + trial->prev_index = p_i;
  1667. + }
  1668. +}
  1669. +
  1670. +
  1671. +struct LZ_encoder {
  1672. + int longest_match_found;
  1673. + uint32_t crc;
  1674. +
  1675. + Bit_model bm_literal[1 << literal_context_bits][0x300];
  1676. + Bit_model bm_match[states][pos_states];
  1677. + Bit_model bm_rep[states];
  1678. + Bit_model bm_rep0[states];
  1679. + Bit_model bm_rep1[states];
  1680. + Bit_model bm_rep2[states];
  1681. + Bit_model bm_len[states][pos_states];
  1682. + Bit_model bm_dis_slot[len_states][1 << dis_slot_bits];
  1683. + Bit_model bm_dis[modeled_distances-end_dis_model+1];
  1684. + Bit_model bm_align[dis_align_size];
  1685. +
  1686. + struct Matchfinder *matchfinder;
  1687. + struct Range_encoder renc;
  1688. + struct Len_encoder match_len_encoder;
  1689. + struct Len_encoder rep_len_encoder;
  1690. +
  1691. + int match_distances[max_match_len+1];
  1692. + struct Trial trials[max_num_trials];
  1693. +
  1694. + int dis_slot_prices[len_states][2*max_dictionary_bits];
  1695. + int dis_prices[len_states][modeled_distances];
  1696. + int align_prices[dis_align_size];
  1697. + int align_price_count;
  1698. + int num_dis_slots;
  1699. +};
  1700. +
  1701. +static void LZe_fill_align_prices(struct LZ_encoder * const e)
  1702. +{
  1703. + int i;
  1704. + for (i = 0; i < dis_align_size; ++i)
  1705. + e->align_prices[i] =
  1706. + price_symbol_reversed(e->bm_align, i, dis_align_bits);
  1707. + e->align_price_count = dis_align_size;
  1708. +}
  1709. +
  1710. +static bool LZe_init(struct LZ_encoder * const e,
  1711. + struct Matchfinder * const mf, const Lzip_header header)
  1712. +{
  1713. + int i;
  1714. + e->longest_match_found = 0;
  1715. + e->crc = 0xFFFFFFFFU;
  1716. + Bm_array_init(&e->bm_literal[0][0], lz_num_models);
  1717. + e->matchfinder = mf;
  1718. + if (!Re_init(&e->renc)) return false;
  1719. + Lee_init(&e->match_len_encoder, e->matchfinder->match_len_limit);
  1720. + Lee_init(&e->rep_len_encoder, e->matchfinder->match_len_limit);
  1721. + LZe_fill_align_prices(e);
  1722. + e->num_dis_slots = 2 * real_bits(e->matchfinder->dictionary_size - 1);
  1723. + e->trials[1].prev_index = 0;
  1724. + for (i = 0; i < Lh_size; ++i)
  1725. + Re_put_byte(&e->renc, header[i]);
  1726. + return true;
  1727. +}
  1728. +
  1729. +static inline void LZe_free(struct LZ_encoder * const e)
  1730. +{
  1731. + Re_free(&e->renc);
  1732. +}
  1733. +
  1734. +static inline unsigned LZe_crc(const struct LZ_encoder * const e)
  1735. +{
  1736. + return e->crc ^ 0xFFFFFFFFU;
  1737. +}
  1738. +
  1739. + /* move-to-front dis in/into reps; do nothing if( dis4 <= 0 ) */
  1740. +static void mtf_reps(const int dis4, int reps[num_rep_distances])
  1741. +{
  1742. + if (dis4 >= num_rep_distances) { /* match */
  1743. + reps[3] = reps[2]; reps[2] = reps[1]; reps[1] = reps[0];
  1744. + reps[0] = dis4 - num_rep_distances;
  1745. + } else if (dis4 > 0) { /* repeated match */
  1746. + const int distance = reps[dis4];
  1747. + int i; for (i = dis4; i > 0; --i)
  1748. + reps[i] = reps[i - 1];
  1749. + reps[0] = distance;
  1750. + }
  1751. +}
  1752. +
  1753. +static int LZe_price_shortrep(const struct LZ_encoder * const e,
  1754. + const State state, const int pos_state)
  1755. +{
  1756. + return price0(e->bm_rep0[state]) + price0(e->bm_len[state][pos_state]);
  1757. +}
  1758. +
  1759. +static int LZe_price_rep(const struct LZ_encoder * const e, const int rep,
  1760. + const State state, const int pos_state)
  1761. +{
  1762. + int price;
  1763. + if (rep == 0)
  1764. + return price0(e->bm_rep0[state]) +
  1765. + price1(e->bm_len[state][pos_state]);
  1766. + price = price1(e->bm_rep0[state]);
  1767. + if (rep == 1)
  1768. + price += price0(e->bm_rep1[state]);
  1769. + else {
  1770. + price += price1(e->bm_rep1[state]);
  1771. + price += price_bit(e->bm_rep2[state], rep - 2);
  1772. + }
  1773. + return price;
  1774. +}
  1775. +
  1776. +static int LZe_price_dis(const struct LZ_encoder * const e,
  1777. + const int dis, const int len_state)
  1778. +{
  1779. + if (dis < modeled_distances)
  1780. + return e->dis_prices[len_state][dis];
  1781. + else
  1782. + return e->dis_slot_prices[len_state][get_slot(dis)] +
  1783. + e->align_prices[dis & (dis_align_size - 1)];
  1784. +}
  1785. +
  1786. +static int LZe_price_pair(const struct LZ_encoder * const e,
  1787. + const int dis, const int len,
  1788. + const int pos_state)
  1789. +{
  1790. + if (len <= min_match_len && dis >= modeled_distances)
  1791. + return infinite_price;
  1792. + return Lee_price(&e->match_len_encoder, len, pos_state) +
  1793. + LZe_price_dis(e, dis, get_len_state(len));
  1794. +}
  1795. +
  1796. +static int LZe_price_literal(const struct LZ_encoder * const e,
  1797. + uint8_t prev_byte, uint8_t symbol)
  1798. +{
  1799. + return price_symbol(e->bm_literal[get_lit_state(prev_byte)], symbol, 8);
  1800. +}
  1801. +
  1802. +static int LZe_price_matched(const struct LZ_encoder * const e,
  1803. + uint8_t prev_byte, uint8_t symbol,
  1804. + uint8_t match_byte)
  1805. +{
  1806. + return price_matched(e->bm_literal[get_lit_state(prev_byte)], symbol,
  1807. + match_byte);
  1808. +}
  1809. +
  1810. +static void LZe_encode_literal(struct LZ_encoder * const e,
  1811. + uint8_t prev_byte, uint8_t symbol)
  1812. +{
  1813. + Re_encode_tree(&e->renc,
  1814. + e->bm_literal[get_lit_state(prev_byte)], symbol, 8);
  1815. +}
  1816. +
  1817. +static void LZe_encode_matched(struct LZ_encoder * const e,
  1818. + uint8_t prev_byte, uint8_t symbol,
  1819. + uint8_t match_byte)
  1820. +{
  1821. + Re_encode_matched(&e->renc, e->bm_literal[get_lit_state(prev_byte)],
  1822. + symbol, match_byte);
  1823. +}
  1824. +
  1825. +static void LZe_encode_pair(struct LZ_encoder * const e,
  1826. + const unsigned dis, const int len,
  1827. + const int pos_state)
  1828. +{
  1829. + const int dis_slot = get_slot(dis);
  1830. + Lee_encode(&e->match_len_encoder, &e->renc, len, pos_state);
  1831. + Re_encode_tree(&e->renc, e->bm_dis_slot[get_len_state(len)], dis_slot,
  1832. + dis_slot_bits);
  1833. +
  1834. + if (dis_slot >= start_dis_model) {
  1835. + const int direct_bits = (dis_slot >> 1) - 1;
  1836. + const unsigned base = (2 | (dis_slot & 1)) << direct_bits;
  1837. + const unsigned direct_dis = dis - base;
  1838. +
  1839. + if (dis_slot < end_dis_model)
  1840. + Re_encode_tree_reversed(&e->renc,
  1841. + e->bm_dis + (base - dis_slot),
  1842. + direct_dis, direct_bits);
  1843. + else {
  1844. + Re_encode(&e->renc, direct_dis >> dis_align_bits,
  1845. + direct_bits - dis_align_bits);
  1846. + Re_encode_tree_reversed(&e->renc, e->bm_align,
  1847. + direct_dis, dis_align_bits);
  1848. + if (--e->align_price_count <= 0)
  1849. + LZe_fill_align_prices(e);
  1850. + }
  1851. + }
  1852. +}
  1853. +
  1854. +static int LZe_read_match_distances(struct LZ_encoder * const e)
  1855. +{
  1856. + int len = Mf_longest_match_len(e->matchfinder, e->match_distances);
  1857. + if (len == e->matchfinder->match_len_limit && len < max_match_len)
  1858. + len = Mf_true_match_len(e->matchfinder, len,
  1859. + e->match_distances[len] + 1);
  1860. + return len;
  1861. +}
  1862. +
  1863. +static void LZe_move_pos(struct LZ_encoder * const e, int n)
  1864. +{
  1865. + while (true) {
  1866. + Mf_move_pos(e->matchfinder);
  1867. + if( --n <= 0 ) break;
  1868. + Mf_longest_match_len(e->matchfinder, 0);
  1869. + }
  1870. +}
  1871. +
  1872. +static void LZe_backward(struct LZ_encoder * const e, int cur)
  1873. +{
  1874. + int * const dis = &e->trials[cur].dis;
  1875. + while (cur > 0) {
  1876. + const int prev_index = e->trials[cur].prev_index;
  1877. + struct Trial * const prev_trial = &e->trials[prev_index];
  1878. + prev_trial->price = cur - prev_index; /* len */
  1879. + cur = *dis;
  1880. + *dis = prev_trial->dis;
  1881. + prev_trial->dis = cur;
  1882. + cur = prev_index;
  1883. + }
  1884. +}
  1885. +
  1886. + /* End Of Stream mark => (dis == 0xFFFFFFFFU, len == min_match_len) */
  1887. +static void LZe_full_flush(struct LZ_encoder * const e, const State state)
  1888. +{
  1889. + int i;
  1890. + const int pos_state = Mf_data_position(e->matchfinder) & pos_state_mask;
  1891. + Lzip_trailer trailer;
  1892. + Re_encode_bit(&e->renc, &e->bm_match[state][pos_state], 1);
  1893. + Re_encode_bit(&e->renc, &e->bm_rep[state], 0);
  1894. + LZe_encode_pair(e, 0xFFFFFFFFU, min_match_len, pos_state);
  1895. + Re_flush(&e->renc);
  1896. + Lt_set_data_crc(trailer, LZe_crc(e));
  1897. + Lt_set_data_size(trailer, Mf_data_position(e->matchfinder));
  1898. + Lt_set_member_size(trailer, Re_member_position(&e->renc) + Lt_size);
  1899. + for (i = 0; i < Lt_size; ++i)
  1900. + Re_put_byte(&e->renc, trailer[i]);
  1901. + Re_flush_data(&e->renc);
  1902. +}
  1903. +
  1904. +
  1905. +static void LZe_update_distance_prices(struct LZ_encoder * const e)
  1906. +{
  1907. + int dis, len_state;
  1908. + for (dis = start_dis_model; dis < modeled_distances; ++dis) {
  1909. + const int dis_slot = dis_slots[dis];
  1910. + const int direct_bits = (dis_slot >> 1) - 1;
  1911. + const int base = (2 | (dis_slot & 1)) << direct_bits;
  1912. + const int price =
  1913. + price_symbol_reversed(e->bm_dis + (base - dis_slot),
  1914. + dis - base, direct_bits);
  1915. + for (len_state = 0; len_state < len_states; ++len_state)
  1916. + e->dis_prices[len_state][dis] = price;
  1917. + }
  1918. +
  1919. + for (len_state = 0; len_state < len_states; ++len_state) {
  1920. + int * const dsp = e->dis_slot_prices[len_state];
  1921. + int * const dp = e->dis_prices[len_state];
  1922. + const Bit_model * const bmds = e->bm_dis_slot[len_state];
  1923. + int slot = 0;
  1924. + for (; slot < end_dis_model; ++slot)
  1925. + dsp[slot] = price_symbol(bmds, slot, dis_slot_bits);
  1926. + for (; slot < e->num_dis_slots; ++slot)
  1927. + dsp[slot] = price_symbol(bmds, slot, dis_slot_bits) +
  1928. + ((((slot >> 1) - 1) - dis_align_bits) << price_shift_bits);
  1929. +
  1930. + for (dis = 0; dis < start_dis_model; ++dis)
  1931. + dp[dis] = dsp[dis];
  1932. + for (; dis < modeled_distances; ++dis)
  1933. + dp[dis] += dsp[dis_slots[dis]];
  1934. + }
  1935. +}
  1936. +
  1937. +
  1938. +/* Returns the number of bytes advanced (ahead).
  1939. + trials[0]..trials[ahead-1] contain the steps to encode.
  1940. + ( trials[0].dis == -1 && trials[0].price == 1 ) means literal.
  1941. + A match/rep longer or equal than match_len_limit finishes the sequence.
  1942. +*/
  1943. +static int LZe_sequence_optimizer(struct LZ_encoder * const e,
  1944. + const int reps[num_rep_distances],
  1945. + const State state)
  1946. +{
  1947. + int main_len, i, rep, cur = 0, num_trials;
  1948. + int replens[num_rep_distances];
  1949. + int rep_index = 0;
  1950. +
  1951. + if (e->longest_match_found > 0) { /* from previous call */
  1952. + main_len = e->longest_match_found;
  1953. + e->longest_match_found = 0;
  1954. + } else
  1955. + main_len = LZe_read_match_distances(e);
  1956. +
  1957. + for (i = 0; i < num_rep_distances; ++i) {
  1958. + replens[i] = Mf_true_match_len(e->matchfinder, 0, reps[i] + 1);
  1959. + if (replens[i] > replens[rep_index]) rep_index = i;
  1960. + }
  1961. + if (replens[rep_index] >= e->matchfinder->match_len_limit) {
  1962. + e->trials[0].dis = rep_index;
  1963. + e->trials[0].price = replens[rep_index];
  1964. + LZe_move_pos(e, replens[rep_index]);
  1965. + return replens[rep_index];
  1966. + }
  1967. +
  1968. + if (main_len >= e->matchfinder->match_len_limit) {
  1969. + e->trials[0].dis =
  1970. + e->match_distances[e->matchfinder->match_len_limit] +
  1971. + num_rep_distances;
  1972. + e->trials[0].price = main_len;
  1973. + LZe_move_pos(e, main_len);
  1974. + return main_len;
  1975. + }
  1976. +
  1977. + {
  1978. + const int pos_state = Mf_data_position(e->matchfinder) & pos_state_mask;
  1979. + const int match_price = price1(e->bm_match[state][pos_state]);
  1980. + const int rep_match_price = match_price + price1(e->bm_rep[state]);
  1981. + const uint8_t prev_byte = Mf_peek(e->matchfinder, 1);
  1982. + const uint8_t cur_byte = Mf_peek(e->matchfinder, 0);
  1983. + const uint8_t match_byte = Mf_peek(e->matchfinder, reps[0] + 1);
  1984. +
  1985. + e->trials[1].price = price0(e->bm_match[state][pos_state]);
  1986. + if (St_is_char(state))
  1987. + e->trials[1].price +=
  1988. + LZe_price_literal(e, prev_byte, cur_byte);
  1989. + else
  1990. + e->trials[1].price +=
  1991. + LZe_price_matched(e, prev_byte, cur_byte, match_byte);
  1992. + e->trials[1].dis = -1; /* literal */
  1993. +
  1994. + if (match_byte == cur_byte)
  1995. + Tr_update(&e->trials[1], rep_match_price +
  1996. + LZe_price_shortrep(e, state, pos_state), 0, 0);
  1997. +
  1998. + if (main_len < min_match_len) {
  1999. + e->trials[0].dis = e->trials[1].dis;
  2000. + e->trials[0].price = 1;
  2001. + Mf_move_pos(e->matchfinder);
  2002. + return 1;
  2003. + }
  2004. +
  2005. + e->trials[0].state = state;
  2006. + for (i = 0; i < num_rep_distances; ++i)
  2007. + e->trials[0].reps[i] = reps[i];
  2008. +
  2009. + if (main_len <= replens[rep_index]) {
  2010. + int len;
  2011. +
  2012. + main_len = replens[rep_index];
  2013. + for (len = min_match_len; len <= main_len; ++len)
  2014. + e->trials[len].price = infinite_price;
  2015. + } else {
  2016. + int len;
  2017. + const int normal_match_price =
  2018. + match_price + price0(e->bm_rep[state]);
  2019. + for (len = min_match_len; len <= main_len; ++len) {
  2020. + e->trials[len].dis =
  2021. + e->match_distances[len] + num_rep_distances;
  2022. + e->trials[len].prev_index = 0;
  2023. + e->trials[len].price = normal_match_price +
  2024. + LZe_price_pair(e, e->match_distances[len],
  2025. + len, pos_state);
  2026. + }
  2027. + }
  2028. +
  2029. + for (rep = 0; rep < num_rep_distances; ++rep) {
  2030. + const int price = rep_match_price +
  2031. + LZe_price_rep(e, rep, state, pos_state);
  2032. + int len;
  2033. + for (len = min_match_len; len <= replens[rep]; ++len)
  2034. + Tr_update(&e->trials[len], price +
  2035. + Lee_price(&e->rep_len_encoder, len, pos_state),
  2036. + rep, 0);
  2037. + }
  2038. + }
  2039. +
  2040. + num_trials = main_len;
  2041. +
  2042. + while (true) { /* price optimization loop */
  2043. + struct Trial *cur_trial, *next_trial;
  2044. + int newlen, pos_state, prev_index, len_limit;
  2045. + int next_price, match_price, rep_match_price;
  2046. + uint8_t prev_byte, cur_byte, match_byte;
  2047. +
  2048. + Mf_move_pos(e->matchfinder);
  2049. + if (++cur >= num_trials) { /* no more initialized trials */
  2050. + LZe_backward(e, cur);
  2051. + return cur;
  2052. + }
  2053. + newlen = LZe_read_match_distances(e);
  2054. + if (newlen >= e->matchfinder->match_len_limit) {
  2055. + e->longest_match_found = newlen;
  2056. + LZe_backward(e, cur);
  2057. + return cur;
  2058. + }
  2059. +
  2060. + /* give final values to current trial */
  2061. + cur_trial = &e->trials[cur];
  2062. + prev_index = cur_trial->prev_index;
  2063. + cur_trial->state = e->trials[prev_index].state;
  2064. +
  2065. + for (i = 0; i < num_rep_distances; ++i)
  2066. + cur_trial->reps[i] = e->trials[prev_index].reps[i];
  2067. +
  2068. + if (prev_index == cur - 1) {
  2069. + if (cur_trial->dis == 0)
  2070. + cur_trial->state = St_set_short_rep(cur_trial->state);
  2071. + else
  2072. + cur_trial->state = St_set_char(cur_trial->state);
  2073. + } else {
  2074. + if (cur_trial->dis < num_rep_distances)
  2075. + cur_trial->state = St_set_rep(cur_trial->state);
  2076. + else
  2077. + cur_trial->state = St_set_match(cur_trial->state);
  2078. + mtf_reps(cur_trial->dis, cur_trial->reps);
  2079. + }
  2080. +
  2081. + pos_state = Mf_data_position(e->matchfinder) & pos_state_mask;
  2082. + prev_byte = Mf_peek(e->matchfinder, 1);
  2083. + cur_byte = Mf_peek(e->matchfinder, 0);
  2084. + match_byte = Mf_peek(e->matchfinder, cur_trial->reps[0] + 1);
  2085. +
  2086. + next_price = cur_trial->price +
  2087. + price0(e->bm_match[cur_trial->state][pos_state]);
  2088. + if (St_is_char(cur_trial->state))
  2089. + next_price += LZe_price_literal(e, prev_byte, cur_byte);
  2090. + else
  2091. + next_price += LZe_price_matched(e, prev_byte, cur_byte,
  2092. + match_byte);
  2093. + /* try last updates to next trial */
  2094. + next_trial = &e->trials[cur + 1];
  2095. +
  2096. + Tr_update(next_trial, next_price, -1, cur); /* literal */
  2097. +
  2098. + match_price = cur_trial->price +
  2099. + price1(e->bm_match[cur_trial->state][pos_state]);
  2100. + rep_match_price = match_price + price1(e->bm_rep[cur_trial->state]);
  2101. +
  2102. + if (match_byte == cur_byte && next_trial->dis != 0)
  2103. + Tr_update(next_trial, rep_match_price +
  2104. + LZe_price_shortrep(e, cur_trial->state,
  2105. + pos_state), 0, cur);
  2106. +
  2107. + len_limit = MIN(MIN(max_num_trials - 1 - cur,
  2108. + Mf_available_bytes(e->matchfinder)),
  2109. + e->matchfinder->match_len_limit);
  2110. + if (len_limit < min_match_len) continue;
  2111. +
  2112. + for (rep = 0; rep < num_rep_distances; ++rep) {
  2113. + const int dis = cur_trial->reps[rep] + 1;
  2114. + int len = 0;
  2115. + const uint8_t * const data =
  2116. + Mf_ptr_to_current_pos(e->matchfinder);
  2117. + while (len < len_limit && data[len] == data[len - dis])
  2118. + ++len;
  2119. + if (len >= min_match_len) {
  2120. + const int price = rep_match_price +
  2121. + LZe_price_rep(e, rep, cur_trial->state, pos_state);
  2122. + while (num_trials < cur + len)
  2123. + e->trials[++num_trials].price = infinite_price;
  2124. + for (; len >= min_match_len; --len)
  2125. + Tr_update(&e->trials[cur + len], price +
  2126. + Lee_price(&e->rep_len_encoder, len,
  2127. + pos_state), rep, cur);
  2128. + }
  2129. + }
  2130. +
  2131. + if (newlen <= len_limit &&
  2132. + (newlen > min_match_len ||
  2133. + (newlen == min_match_len &&
  2134. + e->match_distances[min_match_len] < modeled_distances))) {
  2135. + const int normal_match_price = match_price +
  2136. + price0(e->bm_rep[cur_trial->state]);
  2137. + int len;
  2138. + int dis = e->match_distances[min_match_len];
  2139. + int len_state = get_len_state(min_match_len);
  2140. + int dis_price = infinite_price;
  2141. +
  2142. + while (num_trials < cur + newlen)
  2143. + e->trials[++num_trials].price = infinite_price;
  2144. +
  2145. + if (dis < modeled_distances)
  2146. + Tr_update(&e->trials[cur + min_match_len],
  2147. + normal_match_price +
  2148. + e->dis_prices[len_state][dis] +
  2149. + Lee_price(&e->match_len_encoder,
  2150. + min_match_len, pos_state),
  2151. + dis + num_rep_distances, cur);
  2152. +
  2153. + for (len = min_match_len + 1; len <= newlen; ++len) {
  2154. + if (dis != e->match_distances[len] ||
  2155. + len_state < len_states - 1) {
  2156. + dis = e->match_distances[len];
  2157. + len_state = get_len_state(len);
  2158. + dis_price = LZe_price_dis(e, dis, len_state);
  2159. + }
  2160. + Tr_update(&e->trials[cur + len],
  2161. + normal_match_price + dis_price +
  2162. + Lee_price(&e->match_len_encoder, len, pos_state),
  2163. + dis + num_rep_distances, cur);
  2164. + }
  2165. + }
  2166. + }
  2167. +}
  2168. +
  2169. +
  2170. +static bool LZe_encode_member(struct LZ_encoder * const e)
  2171. +{
  2172. + const int dis_price_count =
  2173. + (e->matchfinder->match_len_limit > 12) ? 512 : 2048;
  2174. + int dis_price_counter = 0;
  2175. + int ahead, i;
  2176. + int reps[num_rep_distances];
  2177. + State state = 0;
  2178. + for (i = 0; i < num_rep_distances; ++i) reps[i] = 0;
  2179. +
  2180. + if (!Mf_finished(e->matchfinder)) { /* encode first byte */
  2181. + const uint8_t prev_byte = 0;
  2182. + const uint8_t cur_byte = Mf_peek(e->matchfinder, 0);
  2183. + Re_encode_bit(&e->renc, &e->bm_match[state][0], 0);
  2184. + LZe_encode_literal(e, prev_byte, cur_byte);
  2185. + CRC32_update_byte(&e->crc, cur_byte);
  2186. + Mf_longest_match_len(e->matchfinder, 0);
  2187. + Mf_move_pos(e->matchfinder);
  2188. + }
  2189. +
  2190. + while (!Mf_finished(e->matchfinder)) {
  2191. + if (dis_price_counter <= 0) {
  2192. + LZe_update_distance_prices(e);
  2193. + dis_price_counter = dis_price_count;
  2194. + }
  2195. +
  2196. + ahead = LZe_sequence_optimizer(e, reps, state);
  2197. + dis_price_counter -= ahead;
  2198. +
  2199. + for (i = 0; ahead > 0;) {
  2200. + const int pos_state =
  2201. + (Mf_data_position(e->matchfinder) - ahead) & pos_state_mask;
  2202. + const int dis = e->trials[i].dis;
  2203. + const int len = e->trials[i].price;
  2204. +
  2205. + bool bit = (dis < 0);
  2206. + Re_encode_bit(&e->renc, &e->bm_match[state][pos_state], !bit);
  2207. + if (bit) { /* literal byte */
  2208. + const uint8_t prev_byte = Mf_peek(e->matchfinder, ahead + 1);
  2209. + const uint8_t cur_byte = Mf_peek(e->matchfinder, ahead);
  2210. + CRC32_update_byte(&e->crc, cur_byte);
  2211. + if (St_is_char(state))
  2212. + LZe_encode_literal(e, prev_byte, cur_byte);
  2213. + else {
  2214. + const uint8_t match_byte =
  2215. + Mf_peek(e->matchfinder, ahead + reps[0] + 1);
  2216. + LZe_encode_matched(e, prev_byte, cur_byte, match_byte);
  2217. + }
  2218. + state = St_set_char(state);
  2219. + } else { /* match or repeated match */
  2220. +
  2221. + e->crc = crc32_block_endian0(e->crc,
  2222. + Mf_ptr_to_current_pos(e->matchfinder) - ahead,
  2223. + len, global_crc32_table);
  2224. + mtf_reps(dis, reps);
  2225. + bit = (dis < num_rep_distances);
  2226. + Re_encode_bit(&e->renc, &e->bm_rep[state], bit);
  2227. + if (bit) { /* repeated match */
  2228. + bit = (dis == 0);
  2229. + Re_encode_bit(&e->renc, &e->bm_rep0[state], !bit);
  2230. + if (bit)
  2231. + Re_encode_bit(&e->renc, &e->bm_len[state][pos_state], len > 1);
  2232. + else {
  2233. + Re_encode_bit(&e->renc, &e->bm_rep1[state], dis > 1);
  2234. + if (dis > 1)
  2235. + Re_encode_bit(&e->renc, &e->bm_rep2[state], dis > 2);
  2236. + }
  2237. + if (len == 1)
  2238. + state = St_set_short_rep(state);
  2239. + else {
  2240. + Lee_encode(&e->rep_len_encoder,
  2241. + &e->renc, len, pos_state);
  2242. + state = St_set_rep(state);
  2243. + }
  2244. + } else { /* match */
  2245. + LZe_encode_pair(e, dis - num_rep_distances, len, pos_state);
  2246. + state = St_set_match(state);
  2247. + }
  2248. + }
  2249. + ahead -= len;
  2250. + i += len;
  2251. + }
  2252. + }
  2253. + LZe_full_flush(e, state);
  2254. + return !e->renc.write_error;
  2255. +}
  2256. +
  2257. +
  2258. +struct Lzma_options {
  2259. + int dictionary_size; /* 4KiB..512MiB */
  2260. + int match_len_limit; /* 5..273 */
  2261. +} encoder_options;
  2262. +
  2263. +
  2264. +static int getnum(const char * const ptr, const int llimit, const int ulimit)
  2265. +{
  2266. + long result;
  2267. + char *tail;
  2268. + errno = 0;
  2269. + result = strtol(ptr, &tail, 0);
  2270. + if (tail == ptr || errno)
  2271. + goto error;
  2272. + if (tail[0]) {
  2273. + int factor = (tail[1] == 'i') ? 1024 : 1000;
  2274. + int exponent = 0, i;
  2275. +
  2276. + switch (tail[0]) {
  2277. + case 'M':
  2278. + exponent = 2;
  2279. + break;
  2280. + case 'K':
  2281. + if (factor == 1024) {
  2282. + exponent = 1;
  2283. + break;
  2284. + }
  2285. + goto error;
  2286. + case 'k':
  2287. + if (factor == 1000) {
  2288. + exponent = 1;
  2289. + break;
  2290. + }
  2291. + default:
  2292. + goto error;
  2293. + }
  2294. + for (i = 0; i < exponent; ++i) {
  2295. + if (LONG_MAX / factor >= labs(result))
  2296. + result *= factor;
  2297. + else
  2298. + goto error;
  2299. + }
  2300. + }
  2301. + if (result >= llimit && result <= ulimit)
  2302. + return result;
  2303. + error:
  2304. + bb_error_msg_and_die("invalid number");
  2305. +}
  2306. +
  2307. +
  2308. +static int get_dict_size(const char * const arg)
  2309. +{
  2310. + char *tail;
  2311. + long bits = strtol(arg, &tail, 0);
  2312. + if (bits >= min_dictionary_bits &&
  2313. + bits <= max_dictionary_bits && *tail == 0)
  2314. + return (1 << bits);
  2315. + return getnum(arg, min_dictionary_size, max_dictionary_size);
  2316. +}
  2317. +
  2318. +
  2319. +static IF_DESKTOP(long long) int FAST_FUNC pack_lzip(transformer_state_t *xstate UNUSED_PARAM)
  2320. +{
  2321. + int retval = 0;
  2322. + Lzip_header header;
  2323. + struct Matchfinder matchfinder;
  2324. + struct LZ_encoder * encoder;
  2325. +
  2326. + Lh_set_magic(header);
  2327. + if (!Lh_set_dictionary_size(header, encoder_options.dictionary_size) ||
  2328. + encoder_options.match_len_limit < min_match_len_limit ||
  2329. + encoder_options.match_len_limit > max_match_len)
  2330. + bb_error_msg_and_die("internal error");
  2331. +
  2332. + if (!Mf_init(&matchfinder, Lh_get_dictionary_size(header),
  2333. + encoder_options.match_len_limit)) {
  2334. + bb_error_msg(bb_msg_memory_exhausted);
  2335. + return -1;
  2336. + }
  2337. + Lh_set_dictionary_size(header, matchfinder.dictionary_size);
  2338. +
  2339. + encoder = malloc(sizeof(struct LZ_encoder));
  2340. + if (!encoder || !LZe_init(encoder, &matchfinder, header)) {
  2341. + bb_error_msg(bb_msg_memory_exhausted);
  2342. + retval = -1;
  2343. + } else {
  2344. + if (!LZe_encode_member(encoder)) {
  2345. + bb_perror_msg(bb_msg_write_error);
  2346. + retval = -1;
  2347. + }
  2348. + LZe_free(encoder);
  2349. + }
  2350. + free(encoder);
  2351. + Mf_free(&matchfinder);
  2352. + return retval;
  2353. +}
  2354. +
  2355. +
  2356. +int lzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  2357. +#if ENABLE_FEATURE_LZIP_DECOMPRESS
  2358. +int lzip_main(int argc, char **argv)
  2359. +#else
  2360. +int lzip_main(int argc UNUSED_PARAM, char **argv)
  2361. +#endif
  2362. +{
  2363. + /* Mapping from gzip/bzip2 style 1..9 compression modes
  2364. + to the corresponding LZMA compression modes. */
  2365. + const struct Lzma_options option_mapping[] = {
  2366. + {1 << 20, 5}, /* -0 */
  2367. + {1 << 20, 5}, /* -1 */
  2368. + {3 << 19, 6}, /* -2 */
  2369. + {1 << 21, 8}, /* -3 */
  2370. + {3 << 20, 12}, /* -4 */
  2371. + {1 << 22, 20}, /* -5 */
  2372. + {1 << 23, 36}, /* -6 */
  2373. + {1 << 24, 68}, /* -7 */
  2374. + {3 << 23, 132}, /* -8 */
  2375. + {1 << 25, 273} /* -9 */
  2376. + };
  2377. + int i;
  2378. + char *m_arg;
  2379. + char *s_arg;
  2380. + /* Must match BBUNPK_foo constants! */
  2381. + unsigned opt = getopt32(argv, BBUNPK_OPTSTR IF_FEATURE_LZIP_DECOMPRESS("dt") "0123456789Fm:s:", &m_arg, &s_arg);
  2382. +
  2383. +#if ENABLE_FEATURE_LZIP_DECOMPRESS /* lunzip_main may not be visible... */
  2384. + if (opt & (BBUNPK_OPT_DECOMPRESS|BBUNPK_OPT_TEST)) /* -d and/or -t */
  2385. + return lunzip_main(argc, argv);
  2386. +#endif
  2387. + /* drop BBUNPK_OPTSTR "dt" bits */
  2388. + opt >>= (BBUNPK_OPTSTRLEN IF_FEATURE_LZIP_DECOMPRESS(+ 2));
  2389. +
  2390. + encoder_options = option_mapping[6]; /* default = "-6" */
  2391. +
  2392. + for (i = 9; i >= 7; --i)
  2393. + if (opt & (1 << i))
  2394. + encoder_options = option_mapping[i];
  2395. + for (i = 0; i <= 6; ++i)
  2396. + if (opt & (1 << i))
  2397. + encoder_options = option_mapping[i];
  2398. + if (opt & (1 << 11)) /* -m */
  2399. + encoder_options.match_len_limit =
  2400. + getnum(m_arg, min_match_len_limit, max_match_len);
  2401. + if (opt & (1 << 12)) /* -s */
  2402. + encoder_options.dictionary_size = get_dict_size(s_arg);
  2403. + /* end process options */
  2404. + option_mask32 &= BBUNPK_OPTSTRMASK; /* retain only -cfkvq */
  2405. +
  2406. + /* Initialize the CRC32 table */
  2407. + global_crc32_new_table_le();
  2408. + if (!dis_slots) {
  2409. + Dis_slots_init();
  2410. + Prob_prices_init();
  2411. + }
  2412. +
  2413. + argv += optind;
  2414. + return bbunpack(argv, pack_lzip, append_ext, "lz");
  2415. +}
  2416. diff -urdN busybox-1.29.1.old/archival/tar.c busybox-1.29.1.new/archival/tar.c
  2417. --- busybox-1.29.1.old/archival/tar.c 2018-07-02 13:23:06.000000000 +0200
  2418. +++ busybox-1.29.1.new/archival/tar.c 2018-07-17 00:03:25.000000000 +0200
  2419. @@ -43,7 +43,7 @@
  2420. //config:config FEATURE_TAR_AUTODETECT
  2421. //config: bool "Autodetect compressed tarballs"
  2422. //config: default y
  2423. -//config: depends on TAR && (FEATURE_SEAMLESS_Z || FEATURE_SEAMLESS_GZ || FEATURE_SEAMLESS_BZ2 || FEATURE_SEAMLESS_LZMA || FEATURE_SEAMLESS_XZ)
  2424. +//config: depends on TAR && (FEATURE_SEAMLESS_Z || FEATURE_SEAMLESS_GZ || FEATURE_SEAMLESS_BZ2 || FEATURE_SEAMLESS_LZ || FEATURE_SEAMLESS_LZMA || FEATURE_SEAMLESS_XZ)
  2425. //config: help
  2426. //config: With this option tar can automatically detect compressed
  2427. //config: tarballs. Currently it works only on files (not pipes etc).
  2428. @@ -756,6 +756,7 @@
  2429. //usage: IF_FEATURE_SEAMLESS_GZ("z")
  2430. //usage: IF_FEATURE_SEAMLESS_XZ("J")
  2431. //usage: IF_FEATURE_SEAMLESS_BZ2("j")
  2432. +//usage: IF_FEATURE_SEAMLESS_LZ("y")
  2433. //usage: IF_FEATURE_SEAMLESS_LZMA("a")
  2434. //usage: IF_FEATURE_TAR_CREATE("h")
  2435. //usage: IF_FEATURE_TAR_NOPRESERVE_TIME("m")
  2436. @@ -795,6 +796,9 @@
  2437. //usage: IF_FEATURE_SEAMLESS_BZ2(
  2438. //usage: "\n -j (De)compress using bzip2"
  2439. //usage: )
  2440. +//usage: IF_FEATURE_SEAMLESS_LZ(
  2441. +//usage: "\n -y (De)compress using lzip"
  2442. +//usage: )
  2443. //usage: IF_FEATURE_SEAMLESS_LZMA(
  2444. //usage: "\n -a (De)compress using lzma"
  2445. //usage: )
  2446. @@ -832,6 +836,7 @@
  2447. IF_FEATURE_TAR_FROM( OPTBIT_EXCLUDE_FROM,)
  2448. IF_FEATURE_SEAMLESS_GZ( OPTBIT_GZIP ,)
  2449. IF_FEATURE_SEAMLESS_XZ( OPTBIT_XZ ,) // 16th bit
  2450. + IF_FEATURE_SEAMLESS_LZ( OPTBIT_LZIP ,)
  2451. IF_FEATURE_SEAMLESS_Z( OPTBIT_COMPRESS ,)
  2452. IF_FEATURE_TAR_NOPRESERVE_TIME(OPTBIT_NOPRESERVE_TIME,)
  2453. #if ENABLE_FEATURE_TAR_LONG_OPTIONS
  2454. @@ -859,6 +864,7 @@
  2455. OPT_EXCLUDE_FROM = IF_FEATURE_TAR_FROM( (1 << OPTBIT_EXCLUDE_FROM)) + 0, // X
  2456. OPT_GZIP = IF_FEATURE_SEAMLESS_GZ( (1 << OPTBIT_GZIP )) + 0, // z
  2457. OPT_XZ = IF_FEATURE_SEAMLESS_XZ( (1 << OPTBIT_XZ )) + 0, // J
  2458. + OPT_LZIP = IF_FEATURE_SEAMLESS_LZ( (1 << OPTBIT_LZIP )) + 0, // y
  2459. OPT_COMPRESS = IF_FEATURE_SEAMLESS_Z( (1 << OPTBIT_COMPRESS )) + 0, // Z
  2460. OPT_NOPRESERVE_TIME = IF_FEATURE_TAR_NOPRESERVE_TIME((1 << OPTBIT_NOPRESERVE_TIME)) + 0, // m
  2461. OPT_STRIP_COMPONENTS = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_STRIP_COMPONENTS)) + 0, // strip-components
  2462. @@ -868,7 +874,7 @@
  2463. OPT_NOPRESERVE_PERM = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_NOPRESERVE_PERM)) + 0, // no-same-permissions
  2464. OPT_OVERWRITE = IF_FEATURE_TAR_LONG_OPTIONS((1 << OPTBIT_OVERWRITE )) + 0, // overwrite
  2465. - OPT_ANY_COMPRESS = (OPT_BZIP2 | OPT_LZMA | OPT_GZIP | OPT_XZ | OPT_COMPRESS),
  2466. + OPT_ANY_COMPRESS = (OPT_BZIP2 | OPT_LZMA | OPT_GZIP | OPT_XZ | OPT_LZIP | OPT_COMPRESS),
  2467. };
  2468. #if ENABLE_FEATURE_TAR_LONG_OPTIONS
  2469. static const char tar_longopts[] ALIGN1 =
  2470. @@ -901,6 +907,9 @@
  2471. # if ENABLE_FEATURE_SEAMLESS_GZ
  2472. "gzip\0" No_argument "z"
  2473. # endif
  2474. +# if ENABLE_FEATURE_SEAMLESS_LZ
  2475. + "lzip\0" No_argument "y"
  2476. +# endif
  2477. # if ENABLE_FEATURE_SEAMLESS_XZ
  2478. "xz\0" No_argument "J"
  2479. # endif
  2480. @@ -1003,6 +1012,7 @@
  2481. IF_FEATURE_TAR_FROM( "T:*X:*")
  2482. IF_FEATURE_SEAMLESS_GZ( "z" )
  2483. IF_FEATURE_SEAMLESS_XZ( "J" )
  2484. + IF_FEATURE_SEAMLESS_LZ( "y" )
  2485. IF_FEATURE_SEAMLESS_Z( "Z" )
  2486. IF_FEATURE_TAR_NOPRESERVE_TIME("m")
  2487. IF_FEATURE_TAR_LONG_OPTIONS("\xf9:") // --strip-components
  2488. @@ -1052,6 +1062,7 @@
  2489. showopt(OPT_EXCLUDE_FROM );
  2490. showopt(OPT_GZIP );
  2491. showopt(OPT_XZ );
  2492. + showopt(OPT_LZIP );
  2493. showopt(OPT_COMPRESS );
  2494. showopt(OPT_NOPRESERVE_TIME );
  2495. showopt(OPT_STRIP_COMPONENTS);
  2496. @@ -1184,6 +1195,8 @@
  2497. zipMode = "gzip";
  2498. if (opt & OPT_BZIP2)
  2499. zipMode = "bzip2";
  2500. + if (opt & OPT_LZIP)
  2501. + zipMode = "lzip";
  2502. if (opt & OPT_LZMA)
  2503. zipMode = "lzma";
  2504. if (opt & OPT_XZ)
  2505. @@ -1220,6 +1233,10 @@
  2506. USE_FOR_MMU(IF_FEATURE_SEAMLESS_BZ2(xformer = unpack_bz2_stream;))
  2507. USE_FOR_NOMMU(xformer_prog = "bunzip2";)
  2508. }
  2509. + if (opt & OPT_LZIP) {
  2510. + USE_FOR_MMU(IF_FEATURE_SEAMLESS_LZ(xformer = unpack_lz_stream;))
  2511. + USE_FOR_NOMMU(xformer_prog = "lunzip";)
  2512. + }
  2513. if (opt & OPT_LZMA) {
  2514. USE_FOR_MMU(IF_FEATURE_SEAMLESS_LZMA(xformer = unpack_lzma_stream;))
  2515. USE_FOR_NOMMU(xformer_prog = "unlzma";)
  2516. diff -urdN busybox-1.29.1.old/configs/TEST_nommu_defconfig busybox-1.29.1.new/configs/TEST_nommu_defconfig
  2517. --- busybox-1.29.1.old/configs/TEST_nommu_defconfig 2018-07-02 13:23:06.000000000 +0200
  2518. +++ busybox-1.29.1.new/configs/TEST_nommu_defconfig 2018-07-17 00:03:25.000000000 +0200
  2519. @@ -107,6 +107,7 @@
  2520. CONFIG_FEATURE_SEAMLESS_LZMA=y
  2521. CONFIG_FEATURE_SEAMLESS_BZ2=y
  2522. CONFIG_FEATURE_SEAMLESS_GZ=y
  2523. +CONFIG_FEATURE_SEAMLESS_LZ=y
  2524. CONFIG_FEATURE_SEAMLESS_Z=y
  2525. CONFIG_AR=y
  2526. CONFIG_FEATURE_AR_LONG_FILENAMES=y
  2527. @@ -120,6 +121,8 @@
  2528. CONFIG_GUNZIP=y
  2529. CONFIG_GZIP=y
  2530. CONFIG_FEATURE_GZIP_LONG_OPTIONS=y
  2531. +CONFIG_LUNZIP=y
  2532. +CONFIG_LZIP=y
  2533. CONFIG_LZOP=y
  2534. CONFIG_LZOP_COMPR_HIGH=y
  2535. CONFIG_RPM2CPIO=y
  2536. diff -urdN busybox-1.29.1.old/configs/TEST_noprintf_defconfig busybox-1.29.1.new/configs/TEST_noprintf_defconfig
  2537. --- busybox-1.29.1.old/configs/TEST_noprintf_defconfig 2018-07-02 13:23:06.000000000 +0200
  2538. +++ busybox-1.29.1.new/configs/TEST_noprintf_defconfig 2018-07-17 00:03:25.000000000 +0200
  2539. @@ -118,6 +118,7 @@
  2540. CONFIG_FEATURE_SEAMLESS_LZMA=y
  2541. CONFIG_FEATURE_SEAMLESS_BZ2=y
  2542. CONFIG_FEATURE_SEAMLESS_GZ=y
  2543. +CONFIG_FEATURE_SEAMLESS_LZ=y
  2544. CONFIG_FEATURE_SEAMLESS_Z=y
  2545. # CONFIG_AR is not set
  2546. # CONFIG_FEATURE_AR_LONG_FILENAMES is not set
  2547. @@ -132,6 +133,8 @@
  2548. # CONFIG_GUNZIP is not set
  2549. # CONFIG_GZIP is not set
  2550. # CONFIG_FEATURE_GZIP_LONG_OPTIONS is not set
  2551. +# CONFIG_LUNZIP is not set
  2552. +# CONFIG_LZIP is not set
  2553. # CONFIG_LZOP is not set
  2554. # CONFIG_LZOP_COMPR_HIGH is not set
  2555. # CONFIG_RPM2CPIO is not set
  2556. diff -urdN busybox-1.29.1.old/configs/TEST_rh9_defconfig busybox-1.29.1.new/configs/TEST_rh9_defconfig
  2557. --- busybox-1.29.1.old/configs/TEST_rh9_defconfig 2018-07-02 13:23:06.000000000 +0200
  2558. +++ busybox-1.29.1.new/configs/TEST_rh9_defconfig 2018-07-17 00:03:25.000000000 +0200
  2559. @@ -116,6 +116,7 @@
  2560. CONFIG_FEATURE_SEAMLESS_LZMA=y
  2561. CONFIG_FEATURE_SEAMLESS_BZ2=y
  2562. CONFIG_FEATURE_SEAMLESS_GZ=y
  2563. +CONFIG_FEATURE_SEAMLESS_LZ=y
  2564. CONFIG_FEATURE_SEAMLESS_Z=y
  2565. CONFIG_AR=y
  2566. CONFIG_FEATURE_AR_LONG_FILENAMES=y
  2567. @@ -130,6 +131,8 @@
  2568. CONFIG_GUNZIP=y
  2569. CONFIG_GZIP=y
  2570. CONFIG_FEATURE_GZIP_LONG_OPTIONS=y
  2571. +CONFIG_LUNZIP=y
  2572. +CONFIG_LZIP=y
  2573. CONFIG_LZOP=y
  2574. # CONFIG_LZOP_COMPR_HIGH is not set
  2575. CONFIG_RPM2CPIO=y
  2576. diff -urdN busybox-1.29.1.old/configs/android2_defconfig busybox-1.29.1.new/configs/android2_defconfig
  2577. --- busybox-1.29.1.old/configs/android2_defconfig 2018-07-02 13:23:06.000000000 +0200
  2578. +++ busybox-1.29.1.new/configs/android2_defconfig 2018-07-17 00:03:25.000000000 +0200
  2579. @@ -121,6 +121,7 @@
  2580. CONFIG_FEATURE_SEAMLESS_LZMA=y
  2581. CONFIG_FEATURE_SEAMLESS_BZ2=y
  2582. CONFIG_FEATURE_SEAMLESS_GZ=y
  2583. +CONFIG_FEATURE_SEAMLESS_LZ=y
  2584. CONFIG_FEATURE_SEAMLESS_Z=y
  2585. CONFIG_AR=y
  2586. CONFIG_FEATURE_AR_LONG_FILENAMES=y
  2587. @@ -135,6 +136,8 @@
  2588. CONFIG_GUNZIP=y
  2589. CONFIG_GZIP=y
  2590. # CONFIG_FEATURE_GZIP_LONG_OPTIONS is not set
  2591. +CONFIG_LUNZIP=y
  2592. +CONFIG_LZIP=y
  2593. CONFIG_LZOP=y
  2594. CONFIG_LZOP_COMPR_HIGH=y
  2595. CONFIG_RPM2CPIO=y
  2596. diff -urdN busybox-1.29.1.old/configs/android_defconfig busybox-1.29.1.new/configs/android_defconfig
  2597. --- busybox-1.29.1.old/configs/android_defconfig 2018-07-02 13:23:06.000000000 +0200
  2598. +++ busybox-1.29.1.new/configs/android_defconfig 2018-07-17 00:03:25.000000000 +0200
  2599. @@ -141,6 +141,7 @@
  2600. CONFIG_FEATURE_SEAMLESS_LZMA=y
  2601. CONFIG_FEATURE_SEAMLESS_BZ2=y
  2602. CONFIG_FEATURE_SEAMLESS_GZ=y
  2603. +CONFIG_FEATURE_SEAMLESS_LZ=y
  2604. CONFIG_FEATURE_SEAMLESS_Z=y
  2605. CONFIG_AR=y
  2606. CONFIG_FEATURE_AR_LONG_FILENAMES=y
  2607. @@ -156,6 +157,8 @@
  2608. CONFIG_GZIP=y
  2609. # CONFIG_FEATURE_GZIP_LONG_OPTIONS is not set
  2610. CONFIG_GZIP_FAST=0
  2611. +CONFIG_LUNZIP=y
  2612. +CONFIG_LZIP=y
  2613. CONFIG_LZOP=y
  2614. CONFIG_LZOP_COMPR_HIGH=y
  2615. CONFIG_RPM2CPIO=y
  2616. diff -urdN busybox-1.29.1.old/configs/android_ndk_defconfig busybox-1.29.1.new/configs/android_ndk_defconfig
  2617. --- busybox-1.29.1.old/configs/android_ndk_defconfig 2018-07-02 13:23:06.000000000 +0200
  2618. +++ busybox-1.29.1.new/configs/android_ndk_defconfig 2018-07-17 00:03:25.000000000 +0200
  2619. @@ -131,6 +131,7 @@
  2620. CONFIG_FEATURE_SEAMLESS_LZMA=y
  2621. CONFIG_FEATURE_SEAMLESS_BZ2=y
  2622. CONFIG_FEATURE_SEAMLESS_GZ=y
  2623. +CONFIG_FEATURE_SEAMLESS_LZ=y
  2624. CONFIG_FEATURE_SEAMLESS_Z=y
  2625. CONFIG_AR=y
  2626. CONFIG_FEATURE_AR_LONG_FILENAMES=y
  2627. @@ -153,6 +154,8 @@
  2628. # CONFIG_FEATURE_GZIP_LONG_OPTIONS is not set
  2629. CONFIG_GZIP_FAST=0
  2630. # CONFIG_FEATURE_GZIP_LEVELS is not set
  2631. +CONFIG_LUNZIP=y
  2632. +CONFIG_LZIP=y
  2633. CONFIG_LZOP=y
  2634. CONFIG_LZOP_COMPR_HIGH=y
  2635. CONFIG_RPM=y
  2636. diff -urdN busybox-1.29.1.old/configs/cygwin_defconfig busybox-1.29.1.new/configs/cygwin_defconfig
  2637. --- busybox-1.29.1.old/configs/cygwin_defconfig 2018-07-02 13:23:06.000000000 +0200
  2638. +++ busybox-1.29.1.new/configs/cygwin_defconfig 2018-07-17 00:03:25.000000000 +0200
  2639. @@ -121,6 +121,7 @@
  2640. CONFIG_FEATURE_SEAMLESS_LZMA=y
  2641. CONFIG_FEATURE_SEAMLESS_BZ2=y
  2642. CONFIG_FEATURE_SEAMLESS_GZ=y
  2643. +CONFIG_FEATURE_SEAMLESS_LZ=y
  2644. # CONFIG_FEATURE_SEAMLESS_Z is not set
  2645. # CONFIG_AR is not set
  2646. # CONFIG_FEATURE_AR_LONG_FILENAMES is not set
  2647. @@ -135,6 +136,8 @@
  2648. CONFIG_GUNZIP=y
  2649. CONFIG_GZIP=y
  2650. CONFIG_FEATURE_GZIP_LONG_OPTIONS=y
  2651. +CONFIG_LUNZIP=y
  2652. +CONFIG_LZIP=y
  2653. CONFIG_LZOP=y
  2654. # CONFIG_LZOP_COMPR_HIGH is not set
  2655. CONFIG_RPM2CPIO=y
  2656. diff -urdN busybox-1.29.1.old/configs/freebsd_defconfig busybox-1.29.1.new/configs/freebsd_defconfig
  2657. --- busybox-1.29.1.old/configs/freebsd_defconfig 2018-07-02 13:23:06.000000000 +0200
  2658. +++ busybox-1.29.1.new/configs/freebsd_defconfig 2018-07-17 00:03:25.000000000 +0200
  2659. @@ -119,6 +119,7 @@
  2660. CONFIG_FEATURE_SEAMLESS_LZMA=y
  2661. CONFIG_FEATURE_SEAMLESS_BZ2=y
  2662. CONFIG_FEATURE_SEAMLESS_GZ=y
  2663. +CONFIG_FEATURE_SEAMLESS_LZ=y
  2664. CONFIG_FEATURE_SEAMLESS_Z=y
  2665. CONFIG_AR=y
  2666. CONFIG_FEATURE_AR_LONG_FILENAMES=y
  2667. @@ -133,6 +134,8 @@
  2668. CONFIG_GUNZIP=y
  2669. CONFIG_GZIP=y
  2670. CONFIG_FEATURE_GZIP_LONG_OPTIONS=y
  2671. +CONFIG_LUNZIP=y
  2672. +CONFIG_LZIP=y
  2673. CONFIG_LZOP=y
  2674. # CONFIG_LZOP_COMPR_HIGH is not set
  2675. CONFIG_RPM2CPIO=y
  2676. diff -urdN busybox-1.29.1.old/include/bb_archive.h busybox-1.29.1.new/include/bb_archive.h
  2677. --- busybox-1.29.1.old/include/bb_archive.h 2018-07-02 13:23:06.000000000 +0200
  2678. +++ busybox-1.29.1.new/include/bb_archive.h 2018-07-17 00:03:25.000000000 +0200
  2679. @@ -9,6 +9,8 @@
  2680. COMPRESS_MAGIC = 0x1f9d,
  2681. GZIP_MAGIC = 0x1f8b,
  2682. BZIP2_MAGIC = 256 * 'B' + 'Z',
  2683. + LZIP_MAGIC1 = 0x4C5A,
  2684. + LZIP_MAGIC2 = 0x4950,
  2685. /* .xz signature: 0xfd, '7', 'z', 'X', 'Z', 0x00 */
  2686. /* More info at: http://tukaani.org/xz/xz-file-format.txt */
  2687. XZ_MAGIC1 = 256 * 0xfd + '7',
  2688. @@ -21,6 +23,8 @@
  2689. COMPRESS_MAGIC = 0x9d1f,
  2690. GZIP_MAGIC = 0x8b1f,
  2691. BZIP2_MAGIC = 'B' + 'Z' * 256,
  2692. + LZIP_MAGIC1 = 0x5A4C,
  2693. + LZIP_MAGIC2 = 0x5049,
  2694. XZ_MAGIC1 = 0xfd + '7' * 256,
  2695. XZ_MAGIC2 = 'z' + ('X' + ('Z' + 0 * 256) * 256) * 256,
  2696. XZ_MAGIC1a = 0xfd + ('7' + ('z' + 'X' * 256) * 256) * 256,
  2697. @@ -196,6 +200,7 @@
  2698. char get_header_tar_gz(archive_handle_t *archive_handle) FAST_FUNC;
  2699. char get_header_tar_xz(archive_handle_t *archive_handle) FAST_FUNC;
  2700. char get_header_tar_bz2(archive_handle_t *archive_handle) FAST_FUNC;
  2701. +char get_header_tar_lz(archive_handle_t *archive_handle) FAST_FUNC;
  2702. char get_header_tar_lzma(archive_handle_t *archive_handle) FAST_FUNC;
  2703. char get_header_tar_xz(archive_handle_t *archive_handle) FAST_FUNC;
  2704. @@ -251,6 +256,7 @@
  2705. IF_DESKTOP(long long) int unpack_Z_stream(transformer_state_t *xstate) FAST_FUNC;
  2706. IF_DESKTOP(long long) int unpack_gz_stream(transformer_state_t *xstate) FAST_FUNC;
  2707. IF_DESKTOP(long long) int unpack_bz2_stream(transformer_state_t *xstate) FAST_FUNC;
  2708. +IF_DESKTOP(long long) int unpack_lz_stream(transformer_state_t *xstate) FAST_FUNC;
  2709. IF_DESKTOP(long long) int unpack_lzma_stream(transformer_state_t *xstate) FAST_FUNC;
  2710. IF_DESKTOP(long long) int unpack_xz_stream(transformer_state_t *xstate) FAST_FUNC;
  2711. diff -urdN busybox-1.29.1.old/include/libbb.h busybox-1.29.1.new/include/libbb.h
  2712. --- busybox-1.29.1.old/include/libbb.h 2018-07-02 13:23:06.000000000 +0200
  2713. +++ busybox-1.29.1.new/include/libbb.h 2018-07-17 00:03:25.000000000 +0200
  2714. @@ -879,6 +879,7 @@
  2715. #define SEAMLESS_COMPRESSION (0 \
  2716. || ENABLE_FEATURE_SEAMLESS_XZ \
  2717. || ENABLE_FEATURE_SEAMLESS_LZMA \
  2718. + || ENABLE_FEATURE_SEAMLESS_LZ \
  2719. || ENABLE_FEATURE_SEAMLESS_BZ2 \
  2720. || ENABLE_FEATURE_SEAMLESS_GZ \
  2721. || ENABLE_FEATURE_SEAMLESS_Z)
  2722. @@ -1332,6 +1333,7 @@
  2723. /* Don't need IF_xxx() guard for these */
  2724. int gunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  2725. int bunzip2_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  2726. +int lunzip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  2727. #if ENABLE_ROUTE
  2728. void bb_displayroutes(int noresolve, int netstatfmt) FAST_FUNC;
  2729. diff -urdN busybox-1.29.1.old/miscutils/man.c busybox-1.29.1.new/miscutils/man.c
  2730. --- busybox-1.29.1.old/miscutils/man.c 2018-07-02 13:23:06.000000000 +0200
  2731. +++ busybox-1.29.1.new/miscutils/man.c 2018-07-17 00:03:25.000000000 +0200
  2732. @@ -180,6 +180,11 @@
  2733. if (run_pipe(filename_with_zext, man, level))
  2734. return 1;
  2735. #endif
  2736. +#if ENABLE_FEATURE_SEAMLESS_LZ
  2737. + strcpy(ext, "lz");
  2738. + if (run_pipe(filename_with_zext, man, level))
  2739. + return 1;
  2740. +#endif
  2741. #if ENABLE_FEATURE_SEAMLESS_BZ2
  2742. strcpy(ext, "bz2");
  2743. if (run_pipe(filename_with_zext, man, level))
  2744. diff -urdN busybox-1.29.1.old/scripts/fix_ws.sh busybox-1.29.1.new/scripts/fix_ws.sh
  2745. --- busybox-1.29.1.old/scripts/fix_ws.sh 2018-07-02 13:23:06.000000000 +0200
  2746. +++ busybox-1.29.1.new/scripts/fix_ws.sh 2018-07-17 00:03:25.000000000 +0200
  2747. @@ -19,6 +19,7 @@
  2748. | while read name; do
  2749. test "YES" = "${name/*.bz2/YES}" && continue
  2750. test "YES" = "${name/*.gz/YES}" && continue
  2751. + test "YES" = "${name/*.lz/YES}" && continue
  2752. test "YES" = "${name/*.png/YES}" && continue
  2753. test "YES" = "${name/*.gif/YES}" && continue
  2754. test "YES" = "${name/*.jpg/YES}" && continue
  2755. diff -urdN busybox-1.29.1.old/testsuite/bunzip2.tests busybox-1.29.1.new/testsuite/bunzip2.tests
  2756. --- busybox-1.29.1.old/testsuite/bunzip2.tests 2018-07-02 13:23:06.000000000 +0200
  2757. +++ busybox-1.29.1.new/testsuite/bunzip2.tests 2018-07-17 00:03:25.000000000 +0200
  2758. @@ -9,6 +9,9 @@
  2759. elif test "${0##*/}" = "bunzip2.tests"; then
  2760. unpack=bunzip2
  2761. ext=bz2
  2762. +elif test "${0##*/}" = "lunzip.tests"; then
  2763. + unpack=lunzip
  2764. + ext=lz
  2765. else
  2766. echo "WTF? argv0='$0'"
  2767. exit 1
  2768. @@ -35,6 +38,13 @@
  2769. $ECHO -ne "\x17\x72\x45\x38\x50\x90\x5b\xb8\xe8\xa3"
  2770. }
  2771. +hello_lz() {
  2772. +# Lzipped "HELLO\n"
  2773. +$ECHO -ne "\x4c\x5a\x49\x50\x01\x0c\x00\x24\x11\x45\xcf\x72\xcd\x3d\x3a\xdf"
  2774. +$ECHO -ne "\xff\xff\xdd\x12\x00\x00\x6e\xd7\xac\xfd\x06\x00\x00\x00\x00\x00"
  2775. +$ECHO -ne "\x00\x00\x2a\x00\x00\x00\x00\x00\x00\x00"
  2776. +}
  2777. +
  2778. # We had bunzip2 error on this .bz2 file (fixed in rev 22521)
  2779. test1_bz2()
  2780. {
  2781. @@ -530,6 +540,12 @@
  2782. expected="ok\n"
  2783. prep; check "$unpack: delete src" "${bb}$unpack t2.$ext; test ! -f t2.$ext && echo ok"
  2784. +expected="ok\n"
  2785. +rm -f t1.*
  2786. +hello_$ext > t1.t$ext
  2787. +check "$unpack: replace .t$ext --> .tar" \
  2788. +"${bb}$unpack t1.t$ext && test -f t1.tar && test ! -f t1.t$ext && echo ok"
  2789. +
  2790. )
  2791. rm -rf testdir
  2792. diff -urdN busybox-1.29.1.old/testsuite/bzcat.tests busybox-1.29.1.new/testsuite/bzcat.tests
  2793. --- busybox-1.29.1.old/testsuite/bzcat.tests 2018-07-02 13:23:06.000000000 +0200
  2794. +++ busybox-1.29.1.new/testsuite/bzcat.tests 2018-07-19 02:04:10.000000000 +0200
  2795. @@ -30,10 +30,18 @@
  2796. $ECHO -ne "\x17\x72\x45\x38\x50\x90\x5b\xb8\xe8\xa3"
  2797. }
  2798. +hello_lz() {
  2799. +# Lzipped "HELLO\n"
  2800. +$ECHO -ne "\x4c\x5a\x49\x50\x01\x0c\x00\x24\x11\x45\xcf\x72\xcd\x3d\x3a\xdf"
  2801. +$ECHO -ne "\xff\xff\xdd\x12\x00\x00\x6e\xd7\xac\xfd\x06\x00\x00\x00\x00\x00"
  2802. +$ECHO -ne "\x00\x00\x2a\x00\x00\x00\x00\x00\x00\x00"
  2803. +}
  2804. +
  2805. test x"$CONFIG_ZCAT" = x"y" && \
  2806. for ext in \
  2807. `test x"$CONFIG_FEATURE_SEAMLESS_GZ" = x"y" && echo gz` \
  2808. `test x"$CONFIG_FEATURE_SEAMLESS_BZ2" = x"y" && echo bz2` \
  2809. + `test x"$CONFIG_FEATURE_SEAMLESS_LZ" = x"y" && echo lz` \
  2810. `test x"$CONFIG_FEATURE_SEAMLESS_Z" = x"y" && echo Z`
  2811. do
  2812. prep() {
  2813. diff -urdN busybox-1.29.1.old/testsuite/lunzip.tests busybox-1.29.1.new/testsuite/lunzip.tests
  2814. --- busybox-1.29.1.old/testsuite/lunzip.tests 1970-01-01 01:00:00.000000000 +0100
  2815. +++ busybox-1.29.1.new/testsuite/lunzip.tests 2018-07-17 00:03:25.000000000 +0200
  2816. @@ -0,0 +1,3 @@
  2817. +#!/bin/sh
  2818. +
  2819. +. ./bunzip2.tests
  2820. diff -urdN busybox-1.29.1.old/testsuite/lzip.tests busybox-1.29.1.new/testsuite/lzip.tests
  2821. --- busybox-1.29.1.old/testsuite/lzip.tests 1970-01-01 01:00:00.000000000 +0100
  2822. +++ busybox-1.29.1.new/testsuite/lzip.tests 2018-07-17 14:06:36.000000000 +0200
  2823. @@ -0,0 +1,58 @@
  2824. +#!/bin/sh
  2825. +# Copyright (C) 2012-2018 Antonio Diaz Diaz.
  2826. +# Licensed under GPLv2 or later, see file LICENSE in this source tree.
  2827. +
  2828. +. ./testing.sh
  2829. +
  2830. +rm -rf lzip.testdir 2>/dev/null
  2831. +mkdir lzip.testdir
  2832. +
  2833. +# Lzipped "a"
  2834. +$ECHO -ne "\x4c\x5a\x49\x50\x01\x0c\x00\x30\xc1\xfb\xff\xff\xff\xe0\x00\x00\
  2835. +\x00\x43\xbe\xb7\xe8\x01\x00\x00\x00\x00\x00\x00\x00\x25\x00\x00\
  2836. +\x00\x00\x00\x00\x00" > lzip.testdir/a.lz
  2837. +
  2838. +# Lzipped zero-length file
  2839. +$ECHO -ne "\x4c\x5a\x49\x50\x01\x0c\x00\x83\xff\xfb\xff\xff\xc0\x00\x00\x00\
  2840. +\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x24\x00\x00\x00\
  2841. +\x00\x00\x00\x00" > lzip.testdir/zero.lz
  2842. +
  2843. +
  2844. +# testing "test name" "commands" "expected result" "file input" "stdin"
  2845. +
  2846. +testing "lzip reads from standard input" \
  2847. +"busybox lzip | cmp lzip.testdir/a.lz -" "" "" "a"
  2848. +
  2849. +testing "lzip accepts single minus" \
  2850. +"busybox lzip - | cmp lzip.testdir/a.lz -" "" "" "a"
  2851. +
  2852. +testing "lzip compresses a zero-length file" \
  2853. +"> zero ; busybox lzip -c zero | cmp lzip.testdir/zero.lz -" "" "" ""
  2854. +
  2855. +testing "lzip replaces original file" \
  2856. +"$ECHO foo > lzip.testdir/foo
  2857. +rm -f lzip.testdir/foo.lz 2>/dev/null
  2858. +busybox lzip lzip.testdir/foo
  2859. +test -f lzip.testdir/foo.lz && test ! -f lzip.testdir/foo && echo ok" \
  2860. +"ok\n" "" ""
  2861. +
  2862. +testing "lzip replaces multiple files" \
  2863. +"$ECHO foo > lzip.testdir/foo
  2864. +$ECHO bar > lzip.testdir/bar
  2865. +rm -f lzip.testdir/foo.lz 2>/dev/null
  2866. +rm -f lzip.testdir/bar.lz 2>/dev/null
  2867. +busybox lzip lzip.testdir/foo lzip.testdir/bar
  2868. +test -f lzip.testdir/foo.lz && test ! -f lzip.testdir/foo && echo ok1
  2869. +test -f lzip.testdir/bar.lz && test ! -f lzip.testdir/bar && echo ok2" \
  2870. +"ok1\nok2\n" "" ""
  2871. +
  2872. +testing "lzip -c does not remove original file" \
  2873. +"$ECHO foo > lzip.testdir/foo
  2874. +busybox lzip -c lzip.testdir/foo >/dev/null
  2875. +test -f lzip.testdir/foo && echo ok" "ok\n" "" ""
  2876. +
  2877. +
  2878. +# Clean up
  2879. +rm -rf lzip.testdir 2>/dev/null
  2880. +
  2881. +exit $FAILCOUNT
  2882. diff -urdN busybox-1.29.1.old/testsuite/tar.tests.~1~ busybox-1.29.1.new/testsuite/tar.tests.~1~
  2883. --- busybox-1.29.1.old/testsuite/tar.tests.~1~ 1970-01-01 01:00:00.000000000 +0100
  2884. +++ busybox-1.29.1.new/testsuite/tar.tests.~1~ 2018-07-17 00:03:25.000000000 +0200
  2885. @@ -0,0 +1,368 @@
  2886. +#!/bin/sh
  2887. +# Copyright 2009 by Denys Vlasenko
  2888. +# Licensed under GPLv2, see file LICENSE in this source tree.
  2889. +
  2890. +. ./testing.sh
  2891. +
  2892. +unset LANG
  2893. +unset LANGUAGE
  2894. +unset LC_COLLATE
  2895. +unset LC_ALL
  2896. +umask 022
  2897. +
  2898. +# testing "test name" "script" "expected result" "file input" "stdin"
  2899. +
  2900. +testing "Empty file is not a tarball" '\
  2901. +tar xvf - 2>&1; echo $?
  2902. +' "\
  2903. +tar: short read
  2904. +1
  2905. +" \
  2906. +"" ""
  2907. +SKIP=
  2908. +
  2909. +optional FEATURE_SEAMLESS_GZ GUNZIP
  2910. +# In NOMMU case, "invalid magic" message comes from gunzip child process.
  2911. +# Otherwise, it comes from tar.
  2912. +# Need to fix output up to avoid false positive.
  2913. +testing "Empty file is not a tarball.tar.gz" '\
  2914. +{ tar xvzf - 2>&1; echo $?; } | grep -Fv "invalid magic"
  2915. +' "\
  2916. +tar: short read
  2917. +1
  2918. +" \
  2919. +"" ""
  2920. +SKIP=
  2921. +
  2922. +testing "Two zeroed blocks is a ('truncated') empty tarball" '\
  2923. +dd if=/dev/zero bs=512 count=2 2>/dev/null | tar xvf - 2>&1; echo $?
  2924. +' "\
  2925. +0
  2926. +" \
  2927. +"" ""
  2928. +SKIP=
  2929. +
  2930. +testing "Twenty zeroed blocks is an empty tarball" '\
  2931. +dd if=/dev/zero bs=512 count=20 2>/dev/null | tar xvf - 2>&1; echo $?
  2932. +' "\
  2933. +0
  2934. +" \
  2935. +"" ""
  2936. +SKIP=
  2937. +
  2938. +mkdir tar.tempdir && cd tar.tempdir || exit 1
  2939. +# "tar cf test.tar input input_dir/ input_hard1 input_hard2 input_hard1 input_dir/ input":
  2940. +# GNU tar 1.26 records as hardlinks:
  2941. +# input_hard2 -> input_hard1
  2942. +# input_hard1 -> input_hard1 (!!!)
  2943. +# input_dir/file -> input_dir/file
  2944. +# input -> input
  2945. +# As of 1.24.0, we don't record last two: for them, nlink==1
  2946. +# and we check for "hardlink"ness only files with nlink!=1
  2947. +# We also don't use "hrw-r--r--" notation for hardlinks in "tar tv" listing.
  2948. +optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
  2949. +testing "tar hardlinks and repeated files" '\
  2950. +>input_hard1
  2951. +ln input_hard1 input_hard2
  2952. +mkdir input_dir
  2953. +>input_dir/file
  2954. +chmod -R 644 *
  2955. +chmod 755 input_dir
  2956. +tar cf test.tar input input_dir/ input_hard1 input_hard2 input_hard1 input_dir/ input
  2957. +tar tvf test.tar | sed "s/.*[0-9] input/input/"
  2958. +rm -rf input_dir
  2959. +tar xf test.tar 2>&1
  2960. +echo Ok: $?
  2961. +ls -l . input_dir/* | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
  2962. +' "\
  2963. +input
  2964. +input_dir/
  2965. +input_dir/file
  2966. +input_hard1
  2967. +input_hard2 -> input_hard1
  2968. +input_hard1 -> input_hard1
  2969. +input_dir/
  2970. +input_dir/file
  2971. +input
  2972. +Ok: 0
  2973. +-rw-r--r-- input_dir/file
  2974. +drwxr-xr-x input_dir
  2975. +-rw-r--r-- input_hard1
  2976. +-rw-r--r-- input_hard2
  2977. +" \
  2978. +"" ""
  2979. +SKIP=
  2980. +cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null
  2981. +
  2982. +mkdir tar.tempdir && cd tar.tempdir || exit 1
  2983. +optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
  2984. +testing "tar hardlinks mode" '\
  2985. +>input_hard1
  2986. +chmod 741 input_hard1
  2987. +ln input_hard1 input_hard2
  2988. +mkdir input_dir
  2989. +ln input_hard1 input_dir
  2990. +ln input_hard2 input_dir
  2991. +chmod 550 input_dir
  2992. +# On some filesystems, input_dir/input_hard2 is returned by readdir
  2993. +# BEFORE input_dir/input_hard1! Thats why we cant just "tar cf ... input_*":
  2994. +tar cf test.tar input_dir/input_hard* input_hard*
  2995. +tar tvf test.tar | sed "s/.*[0-9] input/input/"
  2996. +chmod 770 input_dir
  2997. +rm -rf input_*
  2998. +tar xf test.tar 2>&1
  2999. +echo Ok: $?
  3000. +ls -l . input_dir/* | grep "input.*hard" | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
  3001. +' "\
  3002. +input_dir/input_hard1
  3003. +input_dir/input_hard2 -> input_dir/input_hard1
  3004. +input_hard1 -> input_dir/input_hard1
  3005. +input_hard2 -> input_dir/input_hard1
  3006. +Ok: 0
  3007. +-rwxr----x input_dir/input_hard1
  3008. +-rwxr----x input_dir/input_hard2
  3009. +-rwxr----x input_hard1
  3010. +-rwxr----x input_hard2
  3011. +" \
  3012. +"" ""
  3013. +SKIP=
  3014. +cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null
  3015. +
  3016. +mkdir tar.tempdir && cd tar.tempdir || exit 1
  3017. +optional FEATURE_TAR_CREATE FEATURE_LS_SORTFILES
  3018. +testing "tar symlinks mode" '\
  3019. +>input_file
  3020. +chmod 741 input_file
  3021. +ln -s input_file input_soft
  3022. +mkdir input_dir
  3023. +ln input_file input_dir
  3024. +ln input_soft input_dir
  3025. +chmod 550 input_dir
  3026. +tar cf test.tar input_dir/* input_[fs]*
  3027. +tar tvf test.tar | sed "s/.*[0-9] input/input/" | sort
  3028. +chmod 770 input_dir
  3029. +rm -rf input_*
  3030. +tar xf test.tar 2>&1
  3031. +echo Ok: $?
  3032. +ls -l . input_dir/* | grep "input_[fs]" | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
  3033. +' "\
  3034. +input_dir/input_file
  3035. +input_dir/input_soft -> input_file
  3036. +input_file -> input_dir/input_file
  3037. +input_soft -> input_dir/input_soft
  3038. +Ok: 0
  3039. +-rwxr----x input_dir/input_file
  3040. +lrwxrwxrwx input_file
  3041. +-rwxr----x input_file
  3042. +lrwxrwxrwx input_file
  3043. +" \
  3044. +"" ""
  3045. +SKIP=
  3046. +cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null
  3047. +
  3048. +mkdir tar.tempdir && cd tar.tempdir || exit 1
  3049. +optional FEATURE_TAR_CREATE FEATURE_TAR_LONG_OPTIONS
  3050. +testing "tar --overwrite" "\
  3051. +ln input input_hard
  3052. +tar cf test.tar input_hard
  3053. +echo WRONG >input
  3054. +# --overwrite opens 'input_hard' without unlinking,
  3055. +# thus 'input_hard' still linked to 'input' and we write 'Ok' into it
  3056. +tar xf test.tar --overwrite 2>&1 && cat input
  3057. +" "\
  3058. +Ok
  3059. +" \
  3060. +"Ok\n" ""
  3061. +SKIP=
  3062. +cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null
  3063. +
  3064. +mkdir tar.tempdir && cd tar.tempdir || exit 1
  3065. +test x"$SKIP_KNOWN_BUGS" = x"" && {
  3066. +# Needs to be run under non-root for meaningful test
  3067. +optional FEATURE_TAR_CREATE
  3068. +testing "tar writing into read-only dir" '\
  3069. +mkdir input_dir
  3070. +>input_dir/input_file
  3071. +chmod 550 input_dir
  3072. +tar cf test.tar input_dir
  3073. +tar tvf test.tar | sed "s/.*[0-9] input/input/"
  3074. +chmod 770 input_dir
  3075. +rm -rf input_*
  3076. +tar xf test.tar 2>&1
  3077. +echo Ok: $?
  3078. +ls -l input_dir/* . | grep input_ | sed "s/\\(^[^ ]*\\) .* input/\\1 input/"
  3079. +chmod 770 input_dir
  3080. +' "\
  3081. +input_dir/
  3082. +input_dir/input_file
  3083. +Ok: 0
  3084. +-rw-r--r-- input_dir/input_file
  3085. +dr-xr-x--- input_dir
  3086. +" \
  3087. +"" ""
  3088. +SKIP=
  3089. +}
  3090. +cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null
  3091. +
  3092. +mkdir tar.tempdir && cd tar.tempdir || exit 1
  3093. +# Had a bug where on extract autodetect first "switched off" -z
  3094. +# and then failed to recognize .tgz extension
  3095. +optional FEATURE_TAR_CREATE FEATURE_SEAMLESS_GZ GUNZIP
  3096. +testing "tar extract tgz" "\
  3097. +dd count=1 bs=1M if=/dev/zero of=F0 2>/dev/null
  3098. +tar -czf F0.tgz F0
  3099. +rm F0
  3100. +tar -xzvf F0.tgz && echo Ok
  3101. +rm F0 || echo BAD
  3102. +" "\
  3103. +F0
  3104. +Ok
  3105. +" \
  3106. +"" ""
  3107. +SKIP=
  3108. +cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null
  3109. +
  3110. +mkdir tar.tempdir && cd tar.tempdir || exit 1
  3111. +# Do we detect XZ-compressed data (even w/o .tar.xz or txz extension)?
  3112. +# (the uuencoded hello_world.txz contains one empty file named "hello_world")
  3113. +optional UUDECODE FEATURE_TAR_AUTODETECT FEATURE_SEAMLESS_XZ
  3114. +testing "tar extract txz" "\
  3115. +uudecode -o input && tar tf input && echo Ok
  3116. +" "\
  3117. +hello_world
  3118. +Ok
  3119. +" \
  3120. +"" "\
  3121. +begin-base64 644 hello_world.txz
  3122. +/Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4AX/AEldADQZSe6ODIZQ3rSQ8kAJ
  3123. +SnMPTX+XWGKW3Yu/Rwqg4Ik5wqgQKgVH97J8yA8IvZ4ahaCQogUNHRkXibr2
  3124. +Q615wcb2G7fJU49AhWAAAAAAUA8gu9DyXfAAAWWADAAAAB5FXGCxxGf7AgAA
  3125. +AAAEWVo=
  3126. +====
  3127. +"
  3128. +SKIP=
  3129. +cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null
  3130. +
  3131. +mkdir tar.tempdir && cd tar.tempdir || exit 1
  3132. +# On extract, everything up to and including last ".." component is stripped
  3133. +optional FEATURE_TAR_CREATE
  3134. +testing "tar strips /../ on extract" "\
  3135. +rm -rf input_* test.tar 2>/dev/null
  3136. +mkdir input_dir
  3137. +echo Ok >input_dir/file
  3138. +tar cf test.tar ./../tar.tempdir/input_dir/../input_dir 2>&1
  3139. +rm -rf input_* 2>/dev/null
  3140. +tar -vxf test.tar 2>&1
  3141. +cat input_dir/file 2>&1
  3142. +" "\
  3143. +tar: removing leading './../tar.tempdir/input_dir/../' from member names
  3144. +input_dir/
  3145. +input_dir/file
  3146. +Ok
  3147. +" \
  3148. +"" ""
  3149. +SKIP=
  3150. +cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null
  3151. +
  3152. +mkdir tar.tempdir && cd tar.tempdir || exit 1
  3153. +# attack.tar.bz2 has symlink pointing to a system file
  3154. +# followed by a regular file with the same name
  3155. +# containing "root::0:0::/root:/bin/sh":
  3156. +# lrwxrwxrwx root/root passwd -> /tmp/passwd
  3157. +# -rw-r--r-- root/root passwd
  3158. +# naive tar implementation may end up creating the symlink
  3159. +# and then writing into it.
  3160. +# The correct implementation unlinks target before
  3161. +# creating the second file.
  3162. +# We test that /tmp/passwd remains empty:
  3163. +optional UUDECODE FEATURE_TAR_AUTODETECT FEATURE_SEAMLESS_BZ2
  3164. +testing "tar does not extract into symlinks" "\
  3165. +>>/tmp/passwd && uudecode -o input && tar xf input 2>&1 && rm passwd; cat /tmp/passwd; echo \$?
  3166. +" "\
  3167. +tar: skipping unsafe symlink to '/tmp/passwd' in archive, set EXTRACT_UNSAFE_SYMLINKS=1 to extract
  3168. +0
  3169. +" \
  3170. +"" "\
  3171. +begin-base64 644 attack.tar.bz2
  3172. +QlpoOTFBWSZTWRVn/bIAAKt7hMqwAEBAAP2QAhB0Y96AAACACCAAlISgpqe0
  3173. +po0DIaDynqAkpDRP1ANAhiYNSPR8VchKhAz0AK59+DA6FcMKBggOARIJdVHL
  3174. +DGllrjs20ATUgR1HmccBX3EhoMnpMJaNyggmxgLDMz54lBnBTJO/1L1lbMS4
  3175. +l4/V8LDoe90yiWJhOJvIypgEfxdyRThQkBVn/bI=
  3176. +====
  3177. +"
  3178. +SKIP=
  3179. +cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null
  3180. +
  3181. +mkdir tar.tempdir && cd tar.tempdir || exit 1
  3182. +# And same with -k
  3183. +optional UUDECODE FEATURE_TAR_AUTODETECT FEATURE_SEAMLESS_BZ2
  3184. +testing "tar -k does not extract into symlinks" "\
  3185. +>>/tmp/passwd && uudecode -o input && tar xf input -k 2>&1 && rm passwd; cat /tmp/passwd; echo \$?
  3186. +" "\
  3187. +tar: skipping unsafe symlink to '/tmp/passwd' in archive, set EXTRACT_UNSAFE_SYMLINKS=1 to extract
  3188. +0
  3189. +" \
  3190. +"" "\
  3191. +begin-base64 644 attack.tar.bz2
  3192. +QlpoOTFBWSZTWRVn/bIAAKt7hMqwAEBAAP2QAhB0Y96AAACACCAAlISgpqe0
  3193. +po0DIaDynqAkpDRP1ANAhiYNSPR8VchKhAz0AK59+DA6FcMKBggOARIJdVHL
  3194. +DGllrjs20ATUgR1HmccBX3EhoMnpMJaNyggmxgLDMz54lBnBTJO/1L1lbMS4
  3195. +l4/V8LDoe90yiWJhOJvIypgEfxdyRThQkBVn/bI=
  3196. +====
  3197. +"
  3198. +SKIP=
  3199. +cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null
  3200. +
  3201. +mkdir tar.tempdir && cd tar.tempdir || exit 1
  3202. +optional UNICODE_SUPPORT FEATURE_TAR_GNU_EXTENSIONS FEATURE_SEAMLESS_BZ2 FEATURE_TAR_AUTODETECT
  3203. +testing "Pax-encoded UTF8 names and symlinks" '\
  3204. +tar xvf ../tar.utf8.tar.bz2 2>&1; echo $?
  3205. +export LANG=en_US.UTF-8
  3206. +ls -l etc/ssl/certs/* | sed "s:.*etc/:etc/:" | sort
  3207. +unset LANG
  3208. +rm -rf etc usr
  3209. +' "\
  3210. +etc/ssl/certs/3b2716e5.0
  3211. +etc/ssl/certs/EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.pem
  3212. +tar: skipping unsafe symlink to '/usr/share/ca-certificates/mozilla/EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.crt' in archive, set EXTRACT_UNSAFE_SYMLINKS=1 to extract
  3213. +etc/ssl/certs/f80cc7f6.0
  3214. +usr/share/ca-certificates/mozilla/EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.crt
  3215. +0
  3216. +etc/ssl/certs/3b2716e5.0 -> EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.pem
  3217. +etc/ssl/certs/f80cc7f6.0 -> EBG_Elektronik_Sertifika_Hizmet_Sağlayıcısı.pem
  3218. +" \
  3219. +"" ""
  3220. +SKIP=
  3221. +cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null
  3222. +
  3223. +mkdir tar.tempdir && cd tar.tempdir || exit 1
  3224. +optional FEATURE_SEAMLESS_BZ2 FEATURE_TAR_AUTODETECT
  3225. +testing "Symlink attack: create symlink and then write through it" '\
  3226. +exec 2>&1
  3227. +uudecode -o input && tar xvf input; echo $?
  3228. +ls /tmp/bb_test_evilfile
  3229. +ls bb_test_evilfile
  3230. +ls symlink/bb_test_evilfile
  3231. +' "\
  3232. +anything.txt
  3233. +symlink
  3234. +tar: skipping unsafe symlink to '/tmp' in archive, set EXTRACT_UNSAFE_SYMLINKS=1 to extract
  3235. +symlink/bb_test_evilfile
  3236. +0
  3237. +ls: /tmp/bb_test_evilfile: No such file or directory
  3238. +ls: bb_test_evilfile: No such file or directory
  3239. +symlink/bb_test_evilfile
  3240. +" \
  3241. +"" "\
  3242. +begin-base64 644 tar_symlink_attack.tar.bz2
  3243. +QlpoOTFBWSZTWZgs7bQAALT/hMmQAFBAAf+AEMAGJPPv32AAAIAIMAC5thlR
  3244. +omAjAmCMADQT1BqNE0AEwAAjAEwElTKeo9NTR6h6gaeoA0DQNLVdwZZ5iNTk
  3245. +AQwCAV6S00QFJYhrlfFkVCEDEGtgNVqYrI0uK3ggnt30gqk4e1TTQm5QIAKa
  3246. +SJqzRGSFLMmOloHSAcvLiFxxRiQtQZF+qPxbo173ZDISOAoNoPN4PQPhBhKS
  3247. +n8fYaKlioCTzL2oXYczyUUIP4u5IpwoSEwWdtoA=
  3248. +====
  3249. +"
  3250. +SKIP=
  3251. +cd .. || exit 1; rm -rf tar.tempdir 2>/dev/null
  3252. +
  3253. +exit $FAILCOUNT