libarchive-static 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (157) hide show
  1. data/ext/Makefile +6 -0
  2. data/ext/extconf.rb +61 -0
  3. data/ext/libarchive-0.1.1/COPYING.libarchive +60 -0
  4. data/ext/libarchive-0.1.1/LICENSE.libbzip2 +42 -0
  5. data/ext/libarchive-0.1.1/README.txt +143 -0
  6. data/ext/libarchive-0.1.1/ext/Makefile.in +0 -0
  7. data/ext/libarchive-0.1.1/ext/archive_read_support_compression.c +31 -0
  8. data/ext/libarchive-0.1.1/ext/archive_read_support_compression.h +6 -0
  9. data/ext/libarchive-0.1.1/ext/archive_read_support_format.c +32 -0
  10. data/ext/libarchive-0.1.1/ext/archive_read_support_format.h +6 -0
  11. data/ext/libarchive-0.1.1/ext/archive_write_open_rb_str.c +29 -0
  12. data/ext/libarchive-0.1.1/ext/archive_write_open_rb_str.h +6 -0
  13. data/ext/libarchive-0.1.1/ext/archive_write_set_compression.c +32 -0
  14. data/ext/libarchive-0.1.1/ext/archive_write_set_compression.h +6 -0
  15. data/ext/libarchive-0.1.1/ext/config.h.in +22 -0
  16. data/ext/libarchive-0.1.1/ext/configure +3904 -0
  17. data/ext/libarchive-0.1.1/ext/configure.in +11 -0
  18. data/ext/libarchive-0.1.1/ext/depend +19 -0
  19. data/ext/libarchive-0.1.1/ext/extconf.rb +6 -0
  20. data/ext/libarchive-0.1.1/ext/install-sh +250 -0
  21. data/ext/libarchive-0.1.1/ext/libarchive.c +89 -0
  22. data/ext/libarchive-0.1.1/ext/libarchive_archive.c +84 -0
  23. data/ext/libarchive-0.1.1/ext/libarchive_entry.c +1015 -0
  24. data/ext/libarchive-0.1.1/ext/libarchive_internal.h +155 -0
  25. data/ext/libarchive-0.1.1/ext/libarchive_reader.c +328 -0
  26. data/ext/libarchive-0.1.1/ext/libarchive_win32.h +52 -0
  27. data/ext/libarchive-0.1.1/ext/libarchive_writer.c +246 -0
  28. data/ext/libarchive-0.1.1/libarchive.c +1762 -0
  29. data/ext/libarchive-2.8.4/Makefile.in +7076 -0
  30. data/ext/libarchive-2.8.4/build/autoconf/check_stdcall_func.m4 +51 -0
  31. data/ext/libarchive-2.8.4/build/autoconf/compile +143 -0
  32. data/ext/libarchive-2.8.4/build/autoconf/config.guess +1502 -0
  33. data/ext/libarchive-2.8.4/build/autoconf/config.sub +1708 -0
  34. data/ext/libarchive-2.8.4/build/autoconf/depcomp +630 -0
  35. data/ext/libarchive-2.8.4/build/autoconf/install-sh +291 -0
  36. data/ext/libarchive-2.8.4/build/autoconf/la_uid_t.m4 +20 -0
  37. data/ext/libarchive-2.8.4/build/autoconf/ltmain.sh +8406 -0
  38. data/ext/libarchive-2.8.4/build/autoconf/missing +376 -0
  39. data/ext/libarchive-2.8.4/build/pkgconfig/libarchive.pc.in +10 -0
  40. data/ext/libarchive-2.8.4/config.h.in +772 -0
  41. data/ext/libarchive-2.8.4/configure +17916 -0
  42. data/ext/libarchive-2.8.4/libarchive/archive.h +741 -0
  43. data/ext/libarchive-2.8.4/libarchive/archive_check_magic.c +134 -0
  44. data/ext/libarchive-2.8.4/libarchive/archive_crc32.h +66 -0
  45. data/ext/libarchive-2.8.4/libarchive/archive_endian.h +162 -0
  46. data/ext/libarchive-2.8.4/libarchive/archive_entry.c +2202 -0
  47. data/ext/libarchive-2.8.4/libarchive/archive_entry.h +524 -0
  48. data/ext/libarchive-2.8.4/libarchive/archive_entry_copy_bhfi.c +74 -0
  49. data/ext/libarchive-2.8.4/libarchive/archive_entry_copy_stat.c +77 -0
  50. data/ext/libarchive-2.8.4/libarchive/archive_entry_link_resolver.c +405 -0
  51. data/ext/libarchive-2.8.4/libarchive/archive_entry_private.h +184 -0
  52. data/ext/libarchive-2.8.4/libarchive/archive_entry_stat.c +118 -0
  53. data/ext/libarchive-2.8.4/libarchive/archive_entry_strmode.c +87 -0
  54. data/ext/libarchive-2.8.4/libarchive/archive_entry_xattr.c +158 -0
  55. data/ext/libarchive-2.8.4/libarchive/archive_hash.h +281 -0
  56. data/ext/libarchive-2.8.4/libarchive/archive_platform.h +165 -0
  57. data/ext/libarchive-2.8.4/libarchive/archive_private.h +124 -0
  58. data/ext/libarchive-2.8.4/libarchive/archive_read.c +1249 -0
  59. data/ext/libarchive-2.8.4/libarchive/archive_read_data_into_fd.c +93 -0
  60. data/ext/libarchive-2.8.4/libarchive/archive_read_disk.c +198 -0
  61. data/ext/libarchive-2.8.4/libarchive/archive_read_disk_entry_from_file.c +570 -0
  62. data/ext/libarchive-2.8.4/libarchive/archive_read_disk_private.h +62 -0
  63. data/ext/libarchive-2.8.4/libarchive/archive_read_disk_set_standard_lookup.c +303 -0
  64. data/ext/libarchive-2.8.4/libarchive/archive_read_extract.c +182 -0
  65. data/ext/libarchive-2.8.4/libarchive/archive_read_open_fd.c +190 -0
  66. data/ext/libarchive-2.8.4/libarchive/archive_read_open_file.c +165 -0
  67. data/ext/libarchive-2.8.4/libarchive/archive_read_open_filename.c +272 -0
  68. data/ext/libarchive-2.8.4/libarchive/archive_read_open_memory.c +156 -0
  69. data/ext/libarchive-2.8.4/libarchive/archive_read_private.h +199 -0
  70. data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_all.c +60 -0
  71. data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_bzip2.c +353 -0
  72. data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_compress.c +444 -0
  73. data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_gzip.c +465 -0
  74. data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_none.c +40 -0
  75. data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_program.c +459 -0
  76. data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_rpm.c +287 -0
  77. data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_uu.c +627 -0
  78. data/ext/libarchive-2.8.4/libarchive/archive_read_support_compression_xz.c +708 -0
  79. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_all.c +43 -0
  80. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_ar.c +584 -0
  81. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_cpio.c +777 -0
  82. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_empty.c +93 -0
  83. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_iso9660.c +2830 -0
  84. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_mtree.c +1304 -0
  85. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_raw.c +185 -0
  86. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_tar.c +2418 -0
  87. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_xar.c +3151 -0
  88. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_zip.c +903 -0
  89. data/ext/libarchive-2.8.4/libarchive/archive_string.c +453 -0
  90. data/ext/libarchive-2.8.4/libarchive/archive_string.h +148 -0
  91. data/ext/libarchive-2.8.4/libarchive/archive_string_sprintf.c +164 -0
  92. data/ext/libarchive-2.8.4/libarchive/archive_util.c +391 -0
  93. data/ext/libarchive-2.8.4/libarchive/archive_virtual.c +94 -0
  94. data/ext/libarchive-2.8.4/libarchive/archive_windows.c +1236 -0
  95. data/ext/libarchive-2.8.4/libarchive/archive_windows.h +347 -0
  96. data/ext/libarchive-2.8.4/libarchive/archive_write.c +466 -0
  97. data/ext/libarchive-2.8.4/libarchive/archive_write_disk.c +2628 -0
  98. data/ext/libarchive-2.8.4/libarchive/archive_write_disk_private.h +38 -0
  99. data/ext/libarchive-2.8.4/libarchive/archive_write_disk_set_standard_lookup.c +262 -0
  100. data/ext/libarchive-2.8.4/libarchive/archive_write_open_fd.c +141 -0
  101. data/ext/libarchive-2.8.4/libarchive/archive_write_open_file.c +105 -0
  102. data/ext/libarchive-2.8.4/libarchive/archive_write_open_filename.c +162 -0
  103. data/ext/libarchive-2.8.4/libarchive/archive_write_open_memory.c +126 -0
  104. data/ext/libarchive-2.8.4/libarchive/archive_write_private.h +122 -0
  105. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_bzip2.c +408 -0
  106. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_compress.c +492 -0
  107. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_gzip.c +477 -0
  108. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_none.c +257 -0
  109. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_program.c +347 -0
  110. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_xz.c +438 -0
  111. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format.c +72 -0
  112. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_ar.c +550 -0
  113. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_by_name.c +76 -0
  114. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_cpio.c +344 -0
  115. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_cpio_newc.c +295 -0
  116. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_mtree.c +1050 -0
  117. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_pax.c +1386 -0
  118. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_shar.c +626 -0
  119. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_ustar.c +587 -0
  120. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_zip.c +667 -0
  121. data/ext/libarchive-2.8.4/libarchive/config_freebsd.h +154 -0
  122. data/ext/libarchive-2.8.4/libarchive/filter_fork.c +161 -0
  123. data/ext/libarchive-2.8.4/libarchive/filter_fork.h +41 -0
  124. data/ext/libarchive-2.8.4/libarchive/filter_fork_windows.c +113 -0
  125. data/ext/libarchive-static-makefile +80 -0
  126. data/ext/libarchive-static-wrapper-makefile +22 -0
  127. data/ext/zlib-1.2.5/Makefile.in +257 -0
  128. data/ext/zlib-1.2.5/adler32.c +169 -0
  129. data/ext/zlib-1.2.5/compress.c +80 -0
  130. data/ext/zlib-1.2.5/configure +596 -0
  131. data/ext/zlib-1.2.5/crc32.c +442 -0
  132. data/ext/zlib-1.2.5/crc32.h +441 -0
  133. data/ext/zlib-1.2.5/deflate.c +1834 -0
  134. data/ext/zlib-1.2.5/deflate.h +342 -0
  135. data/ext/zlib-1.2.5/example.c +565 -0
  136. data/ext/zlib-1.2.5/gzclose.c +25 -0
  137. data/ext/zlib-1.2.5/gzguts.h +132 -0
  138. data/ext/zlib-1.2.5/gzlib.c +537 -0
  139. data/ext/zlib-1.2.5/gzread.c +653 -0
  140. data/ext/zlib-1.2.5/gzwrite.c +531 -0
  141. data/ext/zlib-1.2.5/infback.c +632 -0
  142. data/ext/zlib-1.2.5/inffast.c +340 -0
  143. data/ext/zlib-1.2.5/inffast.h +11 -0
  144. data/ext/zlib-1.2.5/inffixed.h +94 -0
  145. data/ext/zlib-1.2.5/inflate.c +1480 -0
  146. data/ext/zlib-1.2.5/inflate.h +122 -0
  147. data/ext/zlib-1.2.5/inftrees.c +330 -0
  148. data/ext/zlib-1.2.5/inftrees.h +62 -0
  149. data/ext/zlib-1.2.5/minigzip.c +440 -0
  150. data/ext/zlib-1.2.5/trees.c +1244 -0
  151. data/ext/zlib-1.2.5/trees.h +128 -0
  152. data/ext/zlib-1.2.5/uncompr.c +59 -0
  153. data/ext/zlib-1.2.5/zconf.h +428 -0
  154. data/ext/zlib-1.2.5/zlib.h +1613 -0
  155. data/ext/zlib-1.2.5/zutil.c +318 -0
  156. data/ext/zlib-1.2.5/zutil.h +274 -0
  157. metadata +211 -0
@@ -0,0 +1,708 @@
1
+ /*-
2
+ * Copyright (c) 2009 Michihiro NAKAJIMA
3
+ * Copyright (c) 2003-2008 Tim Kientzle and Miklos Vajna
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions
8
+ * are met:
9
+ * 1. Redistributions of source code must retain the above copyright
10
+ * notice, this list of conditions and the following disclaimer.
11
+ * 2. Redistributions in binary form must reproduce the above copyright
12
+ * notice, this list of conditions and the following disclaimer in the
13
+ * documentation and/or other materials provided with the distribution.
14
+ *
15
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18
+ * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
+ */
26
+
27
+ #include "archive_platform.h"
28
+
29
+ __FBSDID("$FreeBSD: head/lib/libarchive/archive_read_support_compression_xz.c 201167 2009-12-29 06:06:20Z kientzle $");
30
+
31
+ #ifdef HAVE_ERRNO_H
32
+ #include <errno.h>
33
+ #endif
34
+ #include <stdio.h>
35
+ #ifdef HAVE_STDLIB_H
36
+ #include <stdlib.h>
37
+ #endif
38
+ #ifdef HAVE_STRING_H
39
+ #include <string.h>
40
+ #endif
41
+ #ifdef HAVE_UNISTD_H
42
+ #include <unistd.h>
43
+ #endif
44
+ #if HAVE_LZMA_H
45
+ #include <lzma.h>
46
+ #elif HAVE_LZMADEC_H
47
+ #include <lzmadec.h>
48
+ #endif
49
+
50
+ #include "archive.h"
51
+ #include "archive_endian.h"
52
+ #include "archive_private.h"
53
+ #include "archive_read_private.h"
54
+
55
+ #if HAVE_LZMA_H && HAVE_LIBLZMA
56
+
57
+ struct private_data {
58
+ lzma_stream stream;
59
+ unsigned char *out_block;
60
+ size_t out_block_size;
61
+ int64_t total_out;
62
+ char eof; /* True = found end of compressed data. */
63
+ };
64
+
65
+ /* Combined lzma/xz filter */
66
+ static ssize_t xz_filter_read(struct archive_read_filter *, const void **);
67
+ static int xz_filter_close(struct archive_read_filter *);
68
+ static int xz_lzma_bidder_init(struct archive_read_filter *);
69
+
70
+ #elif HAVE_LZMADEC_H && HAVE_LIBLZMADEC
71
+
72
+ struct private_data {
73
+ lzmadec_stream stream;
74
+ unsigned char *out_block;
75
+ size_t out_block_size;
76
+ int64_t total_out;
77
+ char eof; /* True = found end of compressed data. */
78
+ };
79
+
80
+ /* Lzma-only filter */
81
+ static ssize_t lzma_filter_read(struct archive_read_filter *, const void **);
82
+ static int lzma_filter_close(struct archive_read_filter *);
83
+ #endif
84
+
85
+ /*
86
+ * Note that we can detect xz and lzma compressed files even if we
87
+ * can't decompress them. (In fact, we like detecting them because we
88
+ * can give better error messages.) So the bid framework here gets
89
+ * compiled even if no lzma library is available.
90
+ */
91
+ static int xz_bidder_bid(struct archive_read_filter_bidder *,
92
+ struct archive_read_filter *);
93
+ static int xz_bidder_init(struct archive_read_filter *);
94
+ static int lzma_bidder_bid(struct archive_read_filter_bidder *,
95
+ struct archive_read_filter *);
96
+ static int lzma_bidder_init(struct archive_read_filter *);
97
+
98
+ int
99
+ archive_read_support_compression_xz(struct archive *_a)
100
+ {
101
+ struct archive_read *a = (struct archive_read *)_a;
102
+ struct archive_read_filter_bidder *bidder = __archive_read_get_bidder(a);
103
+
104
+ archive_clear_error(_a);
105
+ if (bidder == NULL)
106
+ return (ARCHIVE_FATAL);
107
+
108
+ bidder->data = NULL;
109
+ bidder->bid = xz_bidder_bid;
110
+ bidder->init = xz_bidder_init;
111
+ bidder->options = NULL;
112
+ bidder->free = NULL;
113
+ #if HAVE_LZMA_H && HAVE_LIBLZMA
114
+ return (ARCHIVE_OK);
115
+ #else
116
+ archive_set_error(_a, ARCHIVE_ERRNO_MISC,
117
+ "Using external unxz program for xz decompression");
118
+ return (ARCHIVE_WARN);
119
+ #endif
120
+ }
121
+
122
+ int
123
+ archive_read_support_compression_lzma(struct archive *_a)
124
+ {
125
+ struct archive_read *a = (struct archive_read *)_a;
126
+ struct archive_read_filter_bidder *bidder = __archive_read_get_bidder(a);
127
+
128
+ archive_clear_error(_a);
129
+ if (bidder == NULL)
130
+ return (ARCHIVE_FATAL);
131
+
132
+ bidder->data = NULL;
133
+ bidder->bid = lzma_bidder_bid;
134
+ bidder->init = lzma_bidder_init;
135
+ bidder->options = NULL;
136
+ bidder->free = NULL;
137
+ #if HAVE_LZMA_H && HAVE_LIBLZMA
138
+ return (ARCHIVE_OK);
139
+ #elif HAVE_LZMADEC_H && HAVE_LIBLZMADEC
140
+ return (ARCHIVE_OK);
141
+ #else
142
+ archive_set_error(_a, ARCHIVE_ERRNO_MISC,
143
+ "Using external unlzma program for lzma decompression");
144
+ return (ARCHIVE_WARN);
145
+ #endif
146
+ }
147
+
148
+ /*
149
+ * Test whether we can handle this data.
150
+ */
151
+ static int
152
+ xz_bidder_bid(struct archive_read_filter_bidder *self,
153
+ struct archive_read_filter *filter)
154
+ {
155
+ const unsigned char *buffer;
156
+ ssize_t avail;
157
+ int bits_checked;
158
+
159
+ (void)self; /* UNUSED */
160
+
161
+ buffer = __archive_read_filter_ahead(filter, 6, &avail);
162
+ if (buffer == NULL)
163
+ return (0);
164
+
165
+ /*
166
+ * Verify Header Magic Bytes : FD 37 7A 58 5A 00
167
+ */
168
+ bits_checked = 0;
169
+ if (buffer[0] != 0xFD)
170
+ return (0);
171
+ bits_checked += 8;
172
+ if (buffer[1] != 0x37)
173
+ return (0);
174
+ bits_checked += 8;
175
+ if (buffer[2] != 0x7A)
176
+ return (0);
177
+ bits_checked += 8;
178
+ if (buffer[3] != 0x58)
179
+ return (0);
180
+ bits_checked += 8;
181
+ if (buffer[4] != 0x5A)
182
+ return (0);
183
+ bits_checked += 8;
184
+ if (buffer[5] != 0x00)
185
+ return (0);
186
+ bits_checked += 8;
187
+
188
+ return (bits_checked);
189
+ }
190
+
191
+ /*
192
+ * Test whether we can handle this data.
193
+ *
194
+ * <sigh> LZMA has a rather poor file signature. Zeros do not
195
+ * make good signature bytes as a rule, and the only non-zero byte
196
+ * here is an ASCII character. For example, an uncompressed tar
197
+ * archive whose first file is ']' would satisfy this check. It may
198
+ * be necessary to exclude LZMA from compression_all() because of
199
+ * this. Clients of libarchive would then have to explicitly enable
200
+ * LZMA checking instead of (or in addition to) compression_all() when
201
+ * they have other evidence (file name, command-line option) to go on.
202
+ */
203
+ static int
204
+ lzma_bidder_bid(struct archive_read_filter_bidder *self,
205
+ struct archive_read_filter *filter)
206
+ {
207
+ const unsigned char *buffer;
208
+ ssize_t avail;
209
+ uint32_t dicsize;
210
+ uint64_t uncompressed_size;
211
+ int bits_checked;
212
+
213
+ (void)self; /* UNUSED */
214
+
215
+ buffer = __archive_read_filter_ahead(filter, 14, &avail);
216
+ if (buffer == NULL)
217
+ return (0);
218
+
219
+ /* First byte of raw LZMA stream is commonly 0x5d.
220
+ * The first byte is a special number, which consists of
221
+ * three parameters of LZMA compression, a number of literal
222
+ * context bits(which is from 0 to 8, default is 3), a number
223
+ * of literal pos bits(which is from 0 to 4, default is 0),
224
+ * a number of pos bits(which is from 0 to 4, default is 2).
225
+ * The first byte is made by
226
+ * (pos bits * 5 + literal pos bit) * 9 + * literal contest bit,
227
+ * and so the default value in this field is
228
+ * (2 * 5 + 0) * 9 + 3 = 0x5d.
229
+ * lzma of LZMA SDK has options to change those parameters.
230
+ * It means a range of this field is from 0 to 224. And lzma of
231
+ * XZ Utils with option -e records 0x5e in this field. */
232
+ /* NOTE: If this checking of the first byte increases false
233
+ * recognition, we should allow only 0x5d and 0x5e for the first
234
+ * byte of LZMA stream. */
235
+ bits_checked = 0;
236
+ if (buffer[0] > (4 * 5 + 4) * 9 + 8)
237
+ return (0);
238
+ /* Most likely value in the first byte of LZMA stream. */
239
+ if (buffer[0] == 0x5d || buffer[0] == 0x5e)
240
+ bits_checked += 8;
241
+
242
+ /* Sixth through fourteenth bytes are uncompressed size,
243
+ * stored in little-endian order. `-1' means uncompressed
244
+ * size is unknown and lzma of XZ Utils always records `-1'
245
+ * in this field. */
246
+ uncompressed_size = archive_le64dec(buffer+5);
247
+ if (uncompressed_size == (uint64_t)ARCHIVE_LITERAL_LL(-1))
248
+ bits_checked += 64;
249
+
250
+ /* Second through fifth bytes are dictionary size, stored in
251
+ * little-endian order. The minimum dictionary size is
252
+ * 1 << 12(4KiB) which the lzma of LZMA SDK uses with option
253
+ * -d12 and the maxinam dictionary size is 1 << 27(128MiB)
254
+ * which the one uses with option -d27.
255
+ * NOTE: A comment of LZMA SDK source code says this dictionary
256
+ * range is from 1 << 12 to 1 << 30. */
257
+ dicsize = archive_le32dec(buffer+1);
258
+ switch (dicsize) {
259
+ case 0x00001000:/* lzma of LZMA SDK option -d12. */
260
+ case 0x00002000:/* lzma of LZMA SDK option -d13. */
261
+ case 0x00004000:/* lzma of LZMA SDK option -d14. */
262
+ case 0x00008000:/* lzma of LZMA SDK option -d15. */
263
+ case 0x00010000:/* lzma of XZ Utils option -0 and -1.
264
+ * lzma of LZMA SDK option -d16. */
265
+ case 0x00020000:/* lzma of LZMA SDK option -d17. */
266
+ case 0x00040000:/* lzma of LZMA SDK option -d18. */
267
+ case 0x00080000:/* lzma of XZ Utils option -2.
268
+ * lzma of LZMA SDK option -d19. */
269
+ case 0x00100000:/* lzma of XZ Utils option -3.
270
+ * lzma of LZMA SDK option -d20. */
271
+ case 0x00200000:/* lzma of XZ Utils option -4.
272
+ * lzma of LZMA SDK option -d21. */
273
+ case 0x00400000:/* lzma of XZ Utils option -5.
274
+ * lzma of LZMA SDK option -d22. */
275
+ case 0x00800000:/* lzma of XZ Utils option -6.
276
+ * lzma of LZMA SDK option -d23. */
277
+ case 0x01000000:/* lzma of XZ Utils option -7.
278
+ * lzma of LZMA SDK option -d24. */
279
+ case 0x02000000:/* lzma of XZ Utils option -8.
280
+ * lzma of LZMA SDK option -d25. */
281
+ case 0x04000000:/* lzma of XZ Utils option -9.
282
+ * lzma of LZMA SDK option -d26. */
283
+ case 0x08000000:/* lzma of LZMA SDK option -d27. */
284
+ bits_checked += 32;
285
+ break;
286
+ default:
287
+ /* If a memory usage for encoding was not enough on
288
+ * the platform where LZMA stream was made, lzma of
289
+ * XZ Utils automatically decreased the dictionary
290
+ * size to enough memory for encoding by 1Mi bytes
291
+ * (1 << 20).*/
292
+ if (dicsize <= 0x03F00000 && dicsize >= 0x00300000 &&
293
+ (dicsize & ((1 << 20)-1)) == 0 &&
294
+ bits_checked == 8 + 64) {
295
+ bits_checked += 32;
296
+ break;
297
+ }
298
+ /* Otherwise dictionary size is unlikely. But it is
299
+ * possible that someone makes lzma stream with
300
+ * liblzma/LZMA SDK in one's dictionary size. */
301
+ return (0);
302
+ }
303
+
304
+ /* TODO: The above test is still very weak. It would be
305
+ * good to do better. */
306
+
307
+ return (bits_checked);
308
+ }
309
+
310
+ #if HAVE_LZMA_H && HAVE_LIBLZMA
311
+
312
+ /*
313
+ * liblzma 4.999.7 and later support both lzma and xz streams.
314
+ */
315
+ static int
316
+ xz_bidder_init(struct archive_read_filter *self)
317
+ {
318
+ self->code = ARCHIVE_COMPRESSION_XZ;
319
+ self->name = "xz";
320
+ return (xz_lzma_bidder_init(self));
321
+ }
322
+
323
+ static int
324
+ lzma_bidder_init(struct archive_read_filter *self)
325
+ {
326
+ self->code = ARCHIVE_COMPRESSION_LZMA;
327
+ self->name = "lzma";
328
+ return (xz_lzma_bidder_init(self));
329
+ }
330
+
331
+ /*
332
+ * Setup the callbacks.
333
+ */
334
+ static int
335
+ xz_lzma_bidder_init(struct archive_read_filter *self)
336
+ {
337
+ static const size_t out_block_size = 64 * 1024;
338
+ void *out_block;
339
+ struct private_data *state;
340
+ int ret;
341
+
342
+ state = (struct private_data *)calloc(sizeof(*state), 1);
343
+ out_block = (unsigned char *)malloc(out_block_size);
344
+ if (state == NULL || out_block == NULL) {
345
+ archive_set_error(&self->archive->archive, ENOMEM,
346
+ "Can't allocate data for xz decompression");
347
+ free(out_block);
348
+ free(state);
349
+ return (ARCHIVE_FATAL);
350
+ }
351
+
352
+ self->data = state;
353
+ state->out_block_size = out_block_size;
354
+ state->out_block = out_block;
355
+ self->read = xz_filter_read;
356
+ self->skip = NULL; /* not supported */
357
+ self->close = xz_filter_close;
358
+
359
+ state->stream.avail_in = 0;
360
+
361
+ state->stream.next_out = state->out_block;
362
+ state->stream.avail_out = state->out_block_size;
363
+
364
+ /* Initialize compression library.
365
+ * TODO: I don't know what value is best for memlimit.
366
+ * maybe, it needs to check memory size which
367
+ * running system has.
368
+ */
369
+ if (self->code == ARCHIVE_COMPRESSION_XZ)
370
+ ret = lzma_stream_decoder(&(state->stream),
371
+ (1U << 30),/* memlimit */
372
+ LZMA_CONCATENATED);
373
+ else
374
+ ret = lzma_alone_decoder(&(state->stream),
375
+ (1U << 30));/* memlimit */
376
+
377
+ if (ret == LZMA_OK)
378
+ return (ARCHIVE_OK);
379
+
380
+ /* Library setup failed: Choose an error message and clean up. */
381
+ switch (ret) {
382
+ case LZMA_MEM_ERROR:
383
+ archive_set_error(&self->archive->archive, ENOMEM,
384
+ "Internal error initializing compression library: "
385
+ "Cannot allocate memory");
386
+ break;
387
+ case LZMA_OPTIONS_ERROR:
388
+ archive_set_error(&self->archive->archive,
389
+ ARCHIVE_ERRNO_MISC,
390
+ "Internal error initializing compression library: "
391
+ "Invalid or unsupported options");
392
+ break;
393
+ default:
394
+ archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
395
+ "Internal error initializing lzma library");
396
+ break;
397
+ }
398
+
399
+ free(state->out_block);
400
+ free(state);
401
+ self->data = NULL;
402
+ return (ARCHIVE_FATAL);
403
+ }
404
+
405
+ /*
406
+ * Return the next block of decompressed data.
407
+ */
408
+ static ssize_t
409
+ xz_filter_read(struct archive_read_filter *self, const void **p)
410
+ {
411
+ struct private_data *state;
412
+ size_t decompressed;
413
+ ssize_t avail_in;
414
+ int ret;
415
+
416
+ state = (struct private_data *)self->data;
417
+
418
+ /* Empty our output buffer. */
419
+ state->stream.next_out = state->out_block;
420
+ state->stream.avail_out = state->out_block_size;
421
+
422
+ /* Try to fill the output buffer. */
423
+ while (state->stream.avail_out > 0 && !state->eof) {
424
+ state->stream.next_in =
425
+ __archive_read_filter_ahead(self->upstream, 1, &avail_in);
426
+ if (state->stream.next_in == NULL && avail_in < 0)
427
+ return (ARCHIVE_FATAL);
428
+ state->stream.avail_in = avail_in;
429
+
430
+ /* Decompress as much as we can in one pass. */
431
+ ret = lzma_code(&(state->stream),
432
+ (state->stream.avail_in == 0)? LZMA_FINISH: LZMA_RUN);
433
+ switch (ret) {
434
+ case LZMA_STREAM_END: /* Found end of stream. */
435
+ state->eof = 1;
436
+ /* FALL THROUGH */
437
+ case LZMA_OK: /* Decompressor made some progress. */
438
+ __archive_read_filter_consume(self->upstream,
439
+ avail_in - state->stream.avail_in);
440
+ break;
441
+ case LZMA_MEM_ERROR:
442
+ archive_set_error(&self->archive->archive, ENOMEM,
443
+ "Lzma library error: Cannot allocate memory");
444
+ return (ARCHIVE_FATAL);
445
+ case LZMA_MEMLIMIT_ERROR:
446
+ archive_set_error(&self->archive->archive, ENOMEM,
447
+ "Lzma library error: Out of memory");
448
+ return (ARCHIVE_FATAL);
449
+ case LZMA_FORMAT_ERROR:
450
+ archive_set_error(&self->archive->archive,
451
+ ARCHIVE_ERRNO_MISC,
452
+ "Lzma library error: format not recognized");
453
+ return (ARCHIVE_FATAL);
454
+ case LZMA_OPTIONS_ERROR:
455
+ archive_set_error(&self->archive->archive,
456
+ ARCHIVE_ERRNO_MISC,
457
+ "Lzma library error: Invalid options");
458
+ return (ARCHIVE_FATAL);
459
+ case LZMA_DATA_ERROR:
460
+ archive_set_error(&self->archive->archive,
461
+ ARCHIVE_ERRNO_MISC,
462
+ "Lzma library error: Corrupted input data");
463
+ return (ARCHIVE_FATAL);
464
+ case LZMA_BUF_ERROR:
465
+ archive_set_error(&self->archive->archive,
466
+ ARCHIVE_ERRNO_MISC,
467
+ "Lzma library error: No progress is possible");
468
+ return (ARCHIVE_FATAL);
469
+ default:
470
+ /* Return an error. */
471
+ archive_set_error(&self->archive->archive,
472
+ ARCHIVE_ERRNO_MISC,
473
+ "Lzma decompression failed: Unknown error");
474
+ return (ARCHIVE_FATAL);
475
+ }
476
+ }
477
+
478
+ decompressed = state->stream.next_out - state->out_block;
479
+ state->total_out += decompressed;
480
+ if (decompressed == 0)
481
+ *p = NULL;
482
+ else
483
+ *p = state->out_block;
484
+ return (decompressed);
485
+ }
486
+
487
+ /*
488
+ * Clean up the decompressor.
489
+ */
490
+ static int
491
+ xz_filter_close(struct archive_read_filter *self)
492
+ {
493
+ struct private_data *state;
494
+
495
+ state = (struct private_data *)self->data;
496
+ lzma_end(&(state->stream));
497
+ free(state->out_block);
498
+ free(state);
499
+ return (ARCHIVE_OK);
500
+ }
501
+
502
+ #else
503
+
504
+ #if HAVE_LZMADEC_H && HAVE_LIBLZMADEC
505
+
506
+ /*
507
+ * If we have the older liblzmadec library, then we can handle
508
+ * LZMA streams but not XZ streams.
509
+ */
510
+
511
+ /*
512
+ * Setup the callbacks.
513
+ */
514
+ static int
515
+ lzma_bidder_init(struct archive_read_filter *self)
516
+ {
517
+ static const size_t out_block_size = 64 * 1024;
518
+ void *out_block;
519
+ struct private_data *state;
520
+ ssize_t ret, avail_in;
521
+
522
+ self->code = ARCHIVE_COMPRESSION_LZMA;
523
+ self->name = "lzma";
524
+
525
+ state = (struct private_data *)calloc(sizeof(*state), 1);
526
+ out_block = (unsigned char *)malloc(out_block_size);
527
+ if (state == NULL || out_block == NULL) {
528
+ archive_set_error(&self->archive->archive, ENOMEM,
529
+ "Can't allocate data for lzma decompression");
530
+ free(out_block);
531
+ free(state);
532
+ return (ARCHIVE_FATAL);
533
+ }
534
+
535
+ self->data = state;
536
+ state->out_block_size = out_block_size;
537
+ state->out_block = out_block;
538
+ self->read = lzma_filter_read;
539
+ self->skip = NULL; /* not supported */
540
+ self->close = lzma_filter_close;
541
+
542
+ /* Prime the lzma library with 18 bytes of input. */
543
+ state->stream.next_in = (unsigned char *)(uintptr_t)
544
+ __archive_read_filter_ahead(self->upstream, 18, &avail_in);
545
+ if (state->stream.next_in == NULL)
546
+ return (ARCHIVE_FATAL);
547
+ state->stream.avail_in = avail_in;
548
+ state->stream.next_out = state->out_block;
549
+ state->stream.avail_out = state->out_block_size;
550
+
551
+ /* Initialize compression library. */
552
+ ret = lzmadec_init(&(state->stream));
553
+ __archive_read_filter_consume(self->upstream,
554
+ avail_in - state->stream.avail_in);
555
+ if (ret == LZMADEC_OK)
556
+ return (ARCHIVE_OK);
557
+
558
+ /* Library setup failed: Clean up. */
559
+ archive_set_error(&self->archive->archive, ARCHIVE_ERRNO_MISC,
560
+ "Internal error initializing lzma library");
561
+
562
+ /* Override the error message if we know what really went wrong. */
563
+ switch (ret) {
564
+ case LZMADEC_HEADER_ERROR:
565
+ archive_set_error(&self->archive->archive,
566
+ ARCHIVE_ERRNO_MISC,
567
+ "Internal error initializing compression library: "
568
+ "invalid header");
569
+ break;
570
+ case LZMADEC_MEM_ERROR:
571
+ archive_set_error(&self->archive->archive, ENOMEM,
572
+ "Internal error initializing compression library: "
573
+ "out of memory");
574
+ break;
575
+ }
576
+
577
+ free(state->out_block);
578
+ free(state);
579
+ self->data = NULL;
580
+ return (ARCHIVE_FATAL);
581
+ }
582
+
583
+ /*
584
+ * Return the next block of decompressed data.
585
+ */
586
+ static ssize_t
587
+ lzma_filter_read(struct archive_read_filter *self, const void **p)
588
+ {
589
+ struct private_data *state;
590
+ size_t decompressed;
591
+ ssize_t avail_in, ret;
592
+
593
+ state = (struct private_data *)self->data;
594
+
595
+ /* Empty our output buffer. */
596
+ state->stream.next_out = state->out_block;
597
+ state->stream.avail_out = state->out_block_size;
598
+
599
+ /* Try to fill the output buffer. */
600
+ while (state->stream.avail_out > 0 && !state->eof) {
601
+ state->stream.next_in = (unsigned char *)(uintptr_t)
602
+ __archive_read_filter_ahead(self->upstream, 1, &avail_in);
603
+ if (state->stream.next_in == NULL && avail_in < 0)
604
+ return (ARCHIVE_FATAL);
605
+ state->stream.avail_in = avail_in;
606
+
607
+ /* Decompress as much as we can in one pass. */
608
+ ret = lzmadec_decode(&(state->stream), avail_in == 0);
609
+ switch (ret) {
610
+ case LZMADEC_STREAM_END: /* Found end of stream. */
611
+ state->eof = 1;
612
+ /* FALL THROUGH */
613
+ case LZMADEC_OK: /* Decompressor made some progress. */
614
+ __archive_read_filter_consume(self->upstream,
615
+ avail_in - state->stream.avail_in);
616
+ break;
617
+ case LZMADEC_BUF_ERROR: /* Insufficient input data? */
618
+ archive_set_error(&self->archive->archive,
619
+ ARCHIVE_ERRNO_MISC,
620
+ "Insufficient compressed data");
621
+ return (ARCHIVE_FATAL);
622
+ default:
623
+ /* Return an error. */
624
+ archive_set_error(&self->archive->archive,
625
+ ARCHIVE_ERRNO_MISC,
626
+ "Lzma decompression failed");
627
+ return (ARCHIVE_FATAL);
628
+ }
629
+ }
630
+
631
+ decompressed = state->stream.next_out - state->out_block;
632
+ state->total_out += decompressed;
633
+ if (decompressed == 0)
634
+ *p = NULL;
635
+ else
636
+ *p = state->out_block;
637
+ return (decompressed);
638
+ }
639
+
640
+ /*
641
+ * Clean up the decompressor.
642
+ */
643
+ static int
644
+ lzma_filter_close(struct archive_read_filter *self)
645
+ {
646
+ struct private_data *state;
647
+ int ret;
648
+
649
+ state = (struct private_data *)self->data;
650
+ ret = ARCHIVE_OK;
651
+ switch (lzmadec_end(&(state->stream))) {
652
+ case LZMADEC_OK:
653
+ break;
654
+ default:
655
+ archive_set_error(&(self->archive->archive),
656
+ ARCHIVE_ERRNO_MISC,
657
+ "Failed to clean up %s compressor",
658
+ self->archive->archive.compression_name);
659
+ ret = ARCHIVE_FATAL;
660
+ }
661
+
662
+ free(state->out_block);
663
+ free(state);
664
+ return (ret);
665
+ }
666
+
667
+ #else
668
+
669
+ /*
670
+ *
671
+ * If we have no suitable library on this system, we can't actually do
672
+ * the decompression. We can, however, still detect compressed
673
+ * archives and emit a useful message.
674
+ *
675
+ */
676
+ static int
677
+ lzma_bidder_init(struct archive_read_filter *self)
678
+ {
679
+ int r;
680
+
681
+ r = __archive_read_program(self, "unlzma");
682
+ /* Note: We set the format here even if __archive_read_program()
683
+ * above fails. We do, after all, know what the format is
684
+ * even if we weren't able to read it. */
685
+ self->code = ARCHIVE_COMPRESSION_LZMA;
686
+ self->name = "lzma";
687
+ return (r);
688
+ }
689
+
690
+ #endif /* HAVE_LZMADEC_H */
691
+
692
+
693
+ static int
694
+ xz_bidder_init(struct archive_read_filter *self)
695
+ {
696
+ int r;
697
+
698
+ r = __archive_read_program(self, "unxz");
699
+ /* Note: We set the format here even if __archive_read_program()
700
+ * above fails. We do, after all, know what the format is
701
+ * even if we weren't able to read it. */
702
+ self->code = ARCHIVE_COMPRESSION_XZ;
703
+ self->name = "xz";
704
+ return (r);
705
+ }
706
+
707
+
708
+ #endif /* HAVE_LZMA_H */