libarchive-static 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (296) hide show
  1. checksums.yaml +5 -5
  2. data/ext/extconf.rb +2 -9
  3. data/ext/libarchive-0.1.1/ext/archive_read_support_compression.c +6 -6
  4. data/ext/libarchive-0.1.1/ext/archive_read_support_compression.o +0 -0
  5. data/ext/libarchive-0.1.1/ext/archive_read_support_format.o +0 -0
  6. data/ext/libarchive-0.1.1/ext/archive_write_open_rb_str.c +1 -1
  7. data/ext/libarchive-0.1.1/ext/archive_write_open_rb_str.o +0 -0
  8. data/ext/libarchive-0.1.1/ext/archive_write_set_compression.c +5 -5
  9. data/ext/libarchive-0.1.1/ext/archive_write_set_compression.o +0 -0
  10. data/ext/libarchive-0.1.1/ext/config.h +23 -0
  11. data/ext/libarchive-0.1.1/ext/config.log +230 -0
  12. data/ext/libarchive-0.1.1/ext/config.status +671 -0
  13. data/ext/libarchive-0.1.1/ext/libarchive.c +1 -1
  14. data/ext/libarchive-0.1.1/ext/libarchive.o +0 -0
  15. data/ext/libarchive-0.1.1/ext/libarchive_archive.c +7 -7
  16. data/ext/libarchive-0.1.1/ext/libarchive_archive.o +0 -0
  17. data/ext/libarchive-0.1.1/ext/libarchive_entry.c +6 -0
  18. data/ext/libarchive-0.1.1/ext/libarchive_entry.o +0 -0
  19. data/ext/libarchive-0.1.1/ext/libarchive_internal.h +0 -1
  20. data/ext/libarchive-0.1.1/ext/libarchive_reader.c +6 -4
  21. data/ext/libarchive-0.1.1/ext/libarchive_reader.o +0 -0
  22. data/ext/libarchive-0.1.1/ext/libarchive_ruby.so +0 -0
  23. data/ext/libarchive-0.1.1/ext/libarchive_win32.h +1 -1
  24. data/ext/libarchive-0.1.1/ext/libarchive_writer.c +2 -2
  25. data/ext/libarchive-0.1.1/ext/libarchive_writer.o +0 -0
  26. data/ext/libarchive-3.6.2/Makefile.in +16892 -0
  27. data/ext/libarchive-3.6.2/build/autoconf/ax_append_compile_flags.m4 +67 -0
  28. data/ext/libarchive-3.6.2/build/autoconf/ax_append_flag.m4 +71 -0
  29. data/ext/libarchive-3.6.2/build/autoconf/ax_check_compile_flag.m4 +74 -0
  30. data/ext/libarchive-3.6.2/build/autoconf/ax_require_defined.m4 +37 -0
  31. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/build/autoconf/check_stdcall_func.m4 +0 -0
  32. data/ext/libarchive-3.6.2/build/autoconf/compile +348 -0
  33. data/ext/libarchive-3.6.2/build/autoconf/config.guess +1754 -0
  34. data/ext/libarchive-3.6.2/build/autoconf/config.rpath +696 -0
  35. data/ext/libarchive-3.6.2/build/autoconf/config.sub +1890 -0
  36. data/ext/libarchive-3.6.2/build/autoconf/depcomp +791 -0
  37. data/ext/libarchive-3.6.2/build/autoconf/iconv.m4 +271 -0
  38. data/ext/libarchive-3.6.2/build/autoconf/install-sh +541 -0
  39. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/build/autoconf/la_uid_t.m4 +0 -0
  40. data/ext/libarchive-3.6.2/build/autoconf/lib-ld.m4 +109 -0
  41. data/ext/libarchive-3.6.2/build/autoconf/lib-link.m4 +777 -0
  42. data/ext/libarchive-3.6.2/build/autoconf/lib-prefix.m4 +224 -0
  43. data/ext/libarchive-3.6.2/build/autoconf/ltmain.sh +11251 -0
  44. data/ext/libarchive-3.6.2/build/autoconf/m4_ax_compile_check_sizeof.m4 +115 -0
  45. data/ext/libarchive-3.6.2/build/autoconf/missing +215 -0
  46. data/ext/libarchive-3.6.2/build/autoconf/test-driver +153 -0
  47. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/build/pkgconfig/libarchive.pc.in +4 -1
  48. data/ext/libarchive-3.6.2/config.h.in +1504 -0
  49. data/ext/libarchive-3.6.2/configure +25558 -0
  50. data/ext/libarchive-3.6.2/libarchive/archive.h +1212 -0
  51. data/ext/libarchive-3.6.2/libarchive/archive_acl.c +2097 -0
  52. data/ext/libarchive-3.6.2/libarchive/archive_acl_private.h +83 -0
  53. data/ext/libarchive-3.6.2/libarchive/archive_blake2.h +197 -0
  54. data/ext/libarchive-3.6.2/libarchive/archive_blake2_impl.h +161 -0
  55. data/ext/libarchive-3.6.2/libarchive/archive_blake2s_ref.c +369 -0
  56. data/ext/libarchive-3.6.2/libarchive/archive_blake2sp_ref.c +361 -0
  57. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_check_magic.c +63 -22
  58. data/ext/libarchive-3.6.2/libarchive/archive_cmdline.c +227 -0
  59. data/ext/libarchive-3.6.2/libarchive/archive_cmdline_private.h +47 -0
  60. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_crc32.h +17 -0
  61. data/ext/libarchive-3.6.2/libarchive/archive_cryptor.c +534 -0
  62. data/ext/libarchive-3.6.2/libarchive/archive_cryptor_private.h +188 -0
  63. data/ext/libarchive-3.6.2/libarchive/archive_digest.c +1505 -0
  64. data/ext/libarchive-3.6.2/libarchive/archive_digest_private.h +416 -0
  65. data/ext/libarchive-3.6.2/libarchive/archive_disk_acl_darwin.c +559 -0
  66. data/ext/libarchive-3.6.2/libarchive/archive_disk_acl_freebsd.c +712 -0
  67. data/ext/libarchive-3.6.2/libarchive/archive_disk_acl_linux.c +760 -0
  68. data/ext/libarchive-3.6.2/libarchive/archive_disk_acl_sunos.c +824 -0
  69. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_endian.h +48 -15
  70. data/ext/libarchive-3.6.2/libarchive/archive_entry.c +2149 -0
  71. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_entry.h +305 -106
  72. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_entry_copy_bhfi.c +5 -4
  73. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_entry_copy_stat.c +9 -3
  74. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_entry_link_resolver.c +104 -62
  75. data/ext/libarchive-3.6.2/libarchive/archive_entry_locale.h +92 -0
  76. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_entry_private.h +65 -49
  77. data/ext/libarchive-3.6.2/libarchive/archive_entry_sparse.c +156 -0
  78. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_entry_stat.c +6 -6
  79. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_entry_strmode.c +1 -1
  80. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_entry_xattr.c +4 -6
  81. data/ext/libarchive-3.6.2/libarchive/archive_getdate.c +1165 -0
  82. data/ext/libarchive-3.6.2/libarchive/archive_getdate.h +39 -0
  83. data/ext/libarchive-3.6.2/libarchive/archive_hmac.c +334 -0
  84. data/ext/libarchive-3.6.2/libarchive/archive_hmac_private.h +117 -0
  85. data/ext/libarchive-3.6.2/libarchive/archive_match.c +1875 -0
  86. data/ext/libarchive-3.6.2/libarchive/archive_openssl_evp_private.h +53 -0
  87. data/ext/libarchive-3.6.2/libarchive/archive_openssl_hmac_private.h +54 -0
  88. data/ext/libarchive-3.6.2/libarchive/archive_options.c +218 -0
  89. data/ext/libarchive-3.6.2/libarchive/archive_options_private.h +51 -0
  90. data/ext/libarchive-3.6.2/libarchive/archive_pack_dev.c +337 -0
  91. data/ext/libarchive-3.6.2/libarchive/archive_pack_dev.h +49 -0
  92. data/ext/libarchive-3.6.2/libarchive/archive_pathmatch.c +463 -0
  93. data/ext/libarchive-3.6.2/libarchive/archive_pathmatch.h +52 -0
  94. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_platform.h +77 -9
  95. data/ext/libarchive-3.6.2/libarchive/archive_platform_acl.h +55 -0
  96. data/ext/libarchive-3.6.2/libarchive/archive_platform_xattr.h +47 -0
  97. data/ext/libarchive-3.6.2/libarchive/archive_ppmd7.c +1168 -0
  98. data/ext/libarchive-3.6.2/libarchive/archive_ppmd7_private.h +119 -0
  99. data/ext/libarchive-3.6.2/libarchive/archive_ppmd8.c +1287 -0
  100. data/ext/libarchive-3.6.2/libarchive/archive_ppmd8_private.h +148 -0
  101. data/ext/libarchive-3.6.2/libarchive/archive_ppmd_private.h +151 -0
  102. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_private.h +74 -18
  103. data/ext/libarchive-3.6.2/libarchive/archive_random.c +272 -0
  104. data/ext/libarchive-3.6.2/libarchive/archive_random_private.h +36 -0
  105. data/ext/libarchive-3.6.2/libarchive/archive_rb.c +709 -0
  106. data/ext/libarchive-3.6.2/libarchive/archive_rb.h +113 -0
  107. data/ext/libarchive-3.6.2/libarchive/archive_read.c +1756 -0
  108. data/ext/libarchive-3.6.2/libarchive/archive_read_add_passphrase.c +190 -0
  109. data/ext/libarchive-3.6.2/libarchive/archive_read_append_filter.c +204 -0
  110. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_data_into_fd.c +64 -18
  111. data/ext/libarchive-3.6.2/libarchive/archive_read_disk_entry_from_file.c +1086 -0
  112. data/ext/libarchive-3.6.2/libarchive/archive_read_disk_posix.c +2732 -0
  113. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_disk_private.h +40 -4
  114. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_disk_set_standard_lookup.c +21 -11
  115. data/ext/libarchive-3.6.2/libarchive/archive_read_disk_windows.c +2479 -0
  116. data/ext/libarchive-3.6.2/libarchive/archive_read_extract.c +60 -0
  117. data/ext/{libarchive-2.8.4/libarchive/archive_read_extract.c → libarchive-3.6.2/libarchive/archive_read_extract2.c} +34 -61
  118. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_open_fd.c +70 -49
  119. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_open_file.c +38 -23
  120. data/ext/libarchive-3.6.2/libarchive/archive_read_open_filename.c +586 -0
  121. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_open_memory.c +58 -28
  122. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_private.h +127 -59
  123. data/ext/libarchive-3.6.2/libarchive/archive_read_set_format.c +117 -0
  124. data/ext/libarchive-3.6.2/libarchive/archive_read_set_options.c +133 -0
  125. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_compression_all.c → libarchive-3.6.2/libarchive/archive_read_support_filter_all.c} +35 -10
  126. data/ext/libarchive-3.6.2/libarchive/archive_read_support_filter_by_code.c +83 -0
  127. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_compression_bzip2.c → libarchive-3.6.2/libarchive/archive_read_support_filter_bzip2.c} +38 -26
  128. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_compression_compress.c → libarchive-3.6.2/libarchive/archive_read_support_filter_compress.c} +52 -44
  129. data/ext/libarchive-3.6.2/libarchive/archive_read_support_filter_grzip.c +112 -0
  130. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_compression_gzip.c → libarchive-3.6.2/libarchive/archive_read_support_filter_gzip.c} +108 -37
  131. data/ext/libarchive-3.6.2/libarchive/archive_read_support_filter_lrzip.c +122 -0
  132. data/ext/libarchive-3.6.2/libarchive/archive_read_support_filter_lz4.c +742 -0
  133. data/ext/libarchive-3.6.2/libarchive/archive_read_support_filter_lzop.c +499 -0
  134. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_compression_none.c → libarchive-3.6.2/libarchive/archive_read_support_filter_none.c} +15 -3
  135. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_compression_program.c → libarchive-3.6.2/libarchive/archive_read_support_filter_program.c} +114 -77
  136. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_compression_rpm.c → libarchive-3.6.2/libarchive/archive_read_support_filter_rpm.c} +31 -31
  137. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_compression_uu.c → libarchive-3.6.2/libarchive/archive_read_support_filter_uu.c} +141 -85
  138. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_compression_xz.c → libarchive-3.6.2/libarchive/archive_read_support_filter_xz.c} +369 -284
  139. data/ext/libarchive-3.6.2/libarchive/archive_read_support_filter_zstd.c +297 -0
  140. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_7zip.c +3900 -0
  141. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_all.c +89 -0
  142. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_support_format_ar.c +126 -72
  143. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_by_code.c +92 -0
  144. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_cab.c +3228 -0
  145. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_cpio.c +1104 -0
  146. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_support_format_empty.c +14 -11
  147. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_support_format_iso9660.c +990 -541
  148. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_lha.c +2916 -0
  149. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_mtree.c +2150 -0
  150. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_rar.c +3797 -0
  151. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_rar5.c +4251 -0
  152. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_support_format_raw.c +38 -31
  153. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_support_format_tar.c +1157 -629
  154. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_warc.c +848 -0
  155. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_read_support_format_xar.c +439 -258
  156. data/ext/libarchive-3.6.2/libarchive/archive_read_support_format_zip.c +4270 -0
  157. data/ext/libarchive-3.6.2/libarchive/archive_string.c +4240 -0
  158. data/ext/libarchive-3.6.2/libarchive/archive_string.h +243 -0
  159. data/ext/libarchive-3.6.2/libarchive/archive_string_composition.h +2292 -0
  160. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_string_sprintf.c +44 -16
  161. data/ext/libarchive-3.6.2/libarchive/archive_util.c +655 -0
  162. data/ext/libarchive-3.6.2/libarchive/archive_version_details.c +151 -0
  163. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_virtual.c +85 -16
  164. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_windows.c +214 -541
  165. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_windows.h +74 -106
  166. data/ext/libarchive-3.6.2/libarchive/archive_write.c +828 -0
  167. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter.c +72 -0
  168. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_b64encode.c +304 -0
  169. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_by_name.c +77 -0
  170. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_bzip2.c +401 -0
  171. data/ext/{libarchive-2.8.4/libarchive/archive_write_set_compression_compress.c → libarchive-3.6.2/libarchive/archive_write_add_filter_compress.c} +86 -131
  172. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_grzip.c +135 -0
  173. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_gzip.c +442 -0
  174. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_lrzip.c +197 -0
  175. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_lz4.c +700 -0
  176. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_lzop.c +478 -0
  177. data/ext/{libarchive-2.8.4/libarchive/archive_read_support_format_all.c → libarchive-3.6.2/libarchive/archive_write_add_filter_none.c} +11 -11
  178. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_program.c +391 -0
  179. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_uuencode.c +295 -0
  180. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_xz.c +545 -0
  181. data/ext/libarchive-3.6.2/libarchive/archive_write_add_filter_zstd.c +418 -0
  182. data/ext/libarchive-3.6.2/libarchive/archive_write_disk_posix.c +4711 -0
  183. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_disk_private.h +9 -2
  184. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_disk_set_standard_lookup.c +30 -29
  185. data/ext/libarchive-3.6.2/libarchive/archive_write_disk_windows.c +2842 -0
  186. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_open_fd.c +15 -10
  187. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_open_file.c +15 -9
  188. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_open_filename.c +128 -20
  189. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_open_memory.c +7 -18
  190. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_private.h +72 -29
  191. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_set_format.c +56 -3
  192. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_7zip.c +2322 -0
  193. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_set_format_ar.c +54 -34
  194. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_set_format_by_name.c +20 -2
  195. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_cpio.c +11 -0
  196. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_cpio_binary.c +610 -0
  197. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_cpio_newc.c +457 -0
  198. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_cpio_odc.c +500 -0
  199. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_filter_by_ext.c +142 -0
  200. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_gnutar.c +755 -0
  201. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_iso9660.c +8165 -0
  202. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_mtree.c +2217 -0
  203. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_set_format_pax.c +1049 -387
  204. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_private.h +42 -0
  205. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_raw.c +125 -0
  206. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_set_format_shar.c +62 -47
  207. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/archive_write_set_format_ustar.c +279 -108
  208. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_v7tar.c +638 -0
  209. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_warc.c +453 -0
  210. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_xar.c +3259 -0
  211. data/ext/libarchive-3.6.2/libarchive/archive_write_set_format_zip.c +1704 -0
  212. data/ext/libarchive-3.6.2/libarchive/archive_write_set_options.c +130 -0
  213. data/ext/libarchive-3.6.2/libarchive/archive_write_set_passphrase.c +95 -0
  214. data/ext/libarchive-3.6.2/libarchive/archive_xxhash.h +48 -0
  215. data/ext/libarchive-3.6.2/libarchive/config_freebsd.h +271 -0
  216. data/ext/{libarchive-2.8.4 → libarchive-3.6.2}/libarchive/filter_fork.h +10 -5
  217. data/ext/{libarchive-2.8.4/libarchive/filter_fork.c → libarchive-3.6.2/libarchive/filter_fork_posix.c} +98 -19
  218. data/ext/libarchive-3.6.2/libarchive/filter_fork_windows.c +236 -0
  219. data/ext/libarchive-3.6.2/libarchive/xxhash.c +525 -0
  220. data/ext/libarchive-static-makefile +144 -80
  221. data/ext/libarchive-static-wrapper-makefile +1 -1
  222. data/ext/zlib-1.2.13/Makefile.in +404 -0
  223. data/ext/{zlib-1.2.5 → zlib-1.2.13}/adler32.c +51 -34
  224. data/ext/{zlib-1.2.5 → zlib-1.2.13}/compress.c +27 -21
  225. data/ext/zlib-1.2.13/configure +922 -0
  226. data/ext/zlib-1.2.13/crc32.c +1125 -0
  227. data/ext/zlib-1.2.13/crc32.h +9446 -0
  228. data/ext/{zlib-1.2.5 → zlib-1.2.13}/deflate.c +842 -459
  229. data/ext/{zlib-1.2.5 → zlib-1.2.13}/deflate.h +37 -33
  230. data/ext/{zlib-1.2.5 → zlib-1.2.13}/gzclose.c +0 -0
  231. data/ext/{zlib-1.2.5 → zlib-1.2.13}/gzguts.h +103 -16
  232. data/ext/{zlib-1.2.5 → zlib-1.2.13}/gzlib.c +155 -53
  233. data/ext/zlib-1.2.13/gzread.c +650 -0
  234. data/ext/zlib-1.2.13/gzwrite.c +677 -0
  235. data/ext/{zlib-1.2.5 → zlib-1.2.13}/infback.c +24 -12
  236. data/ext/{zlib-1.2.5 → zlib-1.2.13}/inffast.c +49 -66
  237. data/ext/{zlib-1.2.5 → zlib-1.2.13}/inffast.h +0 -0
  238. data/ext/{zlib-1.2.5 → zlib-1.2.13}/inffixed.h +3 -3
  239. data/ext/{zlib-1.2.5 → zlib-1.2.13}/inflate.c +209 -94
  240. data/ext/{zlib-1.2.5 → zlib-1.2.13}/inflate.h +9 -5
  241. data/ext/{zlib-1.2.5 → zlib-1.2.13}/inftrees.c +24 -50
  242. data/ext/{zlib-1.2.5 → zlib-1.2.13}/inftrees.h +1 -1
  243. data/ext/{zlib-1.2.5 → zlib-1.2.13}/trees.c +135 -198
  244. data/ext/{zlib-1.2.5 → zlib-1.2.13}/trees.h +0 -0
  245. data/ext/zlib-1.2.13/uncompr.c +93 -0
  246. data/ext/{zlib-1.2.5 → zlib-1.2.13}/zconf.h +182 -63
  247. data/ext/{zlib-1.2.5 → zlib-1.2.13}/zlib.h +617 -295
  248. data/ext/{zlib-1.2.5 → zlib-1.2.13}/zutil.c +50 -41
  249. data/ext/{zlib-1.2.5 → zlib-1.2.13}/zutil.h +83 -82
  250. metadata +244 -137
  251. data/ext/libarchive-0.1.1/libarchive.c +0 -1762
  252. data/ext/libarchive-2.8.4/Makefile.in +0 -7076
  253. data/ext/libarchive-2.8.4/build/autoconf/compile +0 -143
  254. data/ext/libarchive-2.8.4/build/autoconf/config.guess +0 -1502
  255. data/ext/libarchive-2.8.4/build/autoconf/config.sub +0 -1708
  256. data/ext/libarchive-2.8.4/build/autoconf/depcomp +0 -630
  257. data/ext/libarchive-2.8.4/build/autoconf/install-sh +0 -291
  258. data/ext/libarchive-2.8.4/build/autoconf/ltmain.sh +0 -8406
  259. data/ext/libarchive-2.8.4/build/autoconf/missing +0 -376
  260. data/ext/libarchive-2.8.4/config.h.in +0 -772
  261. data/ext/libarchive-2.8.4/configure +0 -17916
  262. data/ext/libarchive-2.8.4/libarchive/archive.h +0 -741
  263. data/ext/libarchive-2.8.4/libarchive/archive_entry.c +0 -2202
  264. data/ext/libarchive-2.8.4/libarchive/archive_hash.h +0 -281
  265. data/ext/libarchive-2.8.4/libarchive/archive_read.c +0 -1249
  266. data/ext/libarchive-2.8.4/libarchive/archive_read_disk.c +0 -198
  267. data/ext/libarchive-2.8.4/libarchive/archive_read_disk_entry_from_file.c +0 -570
  268. data/ext/libarchive-2.8.4/libarchive/archive_read_open_filename.c +0 -272
  269. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_cpio.c +0 -777
  270. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_mtree.c +0 -1304
  271. data/ext/libarchive-2.8.4/libarchive/archive_read_support_format_zip.c +0 -903
  272. data/ext/libarchive-2.8.4/libarchive/archive_string.c +0 -453
  273. data/ext/libarchive-2.8.4/libarchive/archive_string.h +0 -148
  274. data/ext/libarchive-2.8.4/libarchive/archive_util.c +0 -391
  275. data/ext/libarchive-2.8.4/libarchive/archive_write.c +0 -466
  276. data/ext/libarchive-2.8.4/libarchive/archive_write_disk.c +0 -2628
  277. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_bzip2.c +0 -408
  278. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_gzip.c +0 -477
  279. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_none.c +0 -257
  280. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_program.c +0 -347
  281. data/ext/libarchive-2.8.4/libarchive/archive_write_set_compression_xz.c +0 -438
  282. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_cpio.c +0 -344
  283. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_cpio_newc.c +0 -295
  284. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_mtree.c +0 -1050
  285. data/ext/libarchive-2.8.4/libarchive/archive_write_set_format_zip.c +0 -667
  286. data/ext/libarchive-2.8.4/libarchive/config_freebsd.h +0 -154
  287. data/ext/libarchive-2.8.4/libarchive/filter_fork_windows.c +0 -113
  288. data/ext/zlib-1.2.5/Makefile.in +0 -257
  289. data/ext/zlib-1.2.5/configure +0 -596
  290. data/ext/zlib-1.2.5/crc32.c +0 -442
  291. data/ext/zlib-1.2.5/crc32.h +0 -441
  292. data/ext/zlib-1.2.5/example.c +0 -565
  293. data/ext/zlib-1.2.5/gzread.c +0 -653
  294. data/ext/zlib-1.2.5/gzwrite.c +0 -531
  295. data/ext/zlib-1.2.5/minigzip.c +0 -440
  296. data/ext/zlib-1.2.5/uncompr.c +0 -59
@@ -28,7 +28,6 @@ __FBSDID("$FreeBSD$");
28
28
  #ifdef HAVE_ERRNO_H
29
29
  #include <errno.h>
30
30
  #endif
31
- #include <stdio.h>
32
31
  #ifdef HAVE_STDLIB_H
33
32
  #include <stdlib.h>
34
33
  #endif
@@ -44,17 +43,16 @@ __FBSDID("$FreeBSD$");
44
43
  #endif
45
44
  #if HAVE_LZMA_H
46
45
  #include <lzma.h>
47
- #elif HAVE_LZMADEC_H
48
- #include <lzmadec.h>
49
46
  #endif
50
47
  #ifdef HAVE_ZLIB_H
51
48
  #include <zlib.h>
52
49
  #endif
53
50
 
54
51
  #include "archive.h"
52
+ #include "archive_digest_private.h"
55
53
  #include "archive_endian.h"
56
54
  #include "archive_entry.h"
57
- #include "archive_hash.h"
55
+ #include "archive_entry_locale.h"
58
56
  #include "archive_private.h"
59
57
  #include "archive_read_private.h"
60
58
 
@@ -74,6 +72,8 @@ int
74
72
  archive_read_support_format_xar(struct archive *_a)
75
73
  {
76
74
  struct archive_read *a = (struct archive_read *)_a;
75
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
76
+ ARCHIVE_STATE_NEW, "archive_read_support_format_xar");
77
77
 
78
78
  archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
79
79
  "Xar not supported on this platform");
@@ -82,8 +82,8 @@ archive_read_support_format_xar(struct archive *_a)
82
82
 
83
83
  #else /* Support xar format */
84
84
 
85
- //#define DEBUG 1
86
- //#define DEBUG_PRINT_TOC 1
85
+ /* #define DEBUG 1 */
86
+ /* #define DEBUG_PRINT_TOC 1 */
87
87
  #if DEBUG_PRINT_TOC
88
88
  #define PRINT_TOC(d, outbytes) do { \
89
89
  unsigned char *x = (unsigned char *)(uintptr_t)d; \
@@ -167,6 +167,9 @@ struct xar_file {
167
167
  #define HAS_FFLAGS 0x01000
168
168
  #define HAS_XATTR 0x02000
169
169
  #define HAS_ACL 0x04000
170
+ #define HAS_CTIME 0x08000
171
+ #define HAS_MTIME 0x10000
172
+ #define HAS_ATIME 0x20000
170
173
 
171
174
  uint64_t id;
172
175
  uint64_t length;
@@ -181,9 +184,9 @@ struct xar_file {
181
184
  time_t mtime;
182
185
  time_t atime;
183
186
  struct archive_string uname;
184
- uid_t uid;
187
+ int64_t uid;
185
188
  struct archive_string gname;
186
- gid_t gid;
189
+ int64_t gid;
187
190
  mode_t mode;
188
191
  dev_t dev;
189
192
  dev_t devmajor;
@@ -303,7 +306,8 @@ struct xar {
303
306
  int64_t total;
304
307
  uint64_t h_base;
305
308
  int end_of_file;
306
- unsigned char buff[1024*32];
309
+ #define OUTBUFF_SIZE (1024 * 64)
310
+ unsigned char *outbuff;
307
311
 
308
312
  enum xmlstatus xmlsts;
309
313
  enum xmlstatus xmlsts_unknown;
@@ -331,9 +335,6 @@ struct xar {
331
335
  #if HAVE_LZMA_H && HAVE_LIBLZMA
332
336
  lzma_stream lzstream;
333
337
  int lzstream_valid;
334
- #elif HAVE_LZMADEC_H && HAVE_LIBLZMADEC
335
- lzmadec_stream lzstream;
336
- int lzstream_valid;
337
338
  #endif
338
339
  /*
339
340
  * For Checksum data.
@@ -350,10 +351,13 @@ struct xar {
350
351
  int entry_init;
351
352
  uint64_t entry_total;
352
353
  uint64_t entry_remaining;
354
+ size_t entry_unconsumed;
353
355
  uint64_t entry_size;
354
356
  enum enctype entry_encoding;
355
357
  struct chksumval entry_a_sum;
356
358
  struct chksumval entry_e_sum;
359
+
360
+ struct archive_string_conv *sconv;
357
361
  };
358
362
 
359
363
  struct xmlattr {
@@ -367,11 +371,11 @@ struct xmlattr_list {
367
371
  struct xmlattr **last;
368
372
  };
369
373
 
370
- static int xar_bid(struct archive_read *);
374
+ static int xar_bid(struct archive_read *, int);
371
375
  static int xar_read_header(struct archive_read *,
372
376
  struct archive_entry *);
373
377
  static int xar_read_data(struct archive_read *,
374
- const void **, size_t *, off_t *);
378
+ const void **, size_t *, int64_t *);
375
379
  static int xar_read_data_skip(struct archive_read *);
376
380
  static int xar_cleanup(struct archive_read *);
377
381
  static int move_reading_point(struct archive_read *, uint64_t);
@@ -383,41 +387,54 @@ static uint64_t atol10(const char *, size_t);
383
387
  static int64_t atol8(const char *, size_t);
384
388
  static size_t atohex(unsigned char *, size_t, const char *, size_t);
385
389
  static time_t parse_time(const char *p, size_t n);
386
- static void heap_add_entry(struct heap_queue *, struct xar_file *);
390
+ static int heap_add_entry(struct archive_read *a,
391
+ struct heap_queue *, struct xar_file *);
387
392
  static struct xar_file *heap_get_entry(struct heap_queue *);
388
- static void add_link(struct xar *, struct xar_file *);
393
+ static int add_link(struct archive_read *,
394
+ struct xar *, struct xar_file *);
389
395
  static void checksum_init(struct archive_read *, int, int);
390
396
  static void checksum_update(struct archive_read *, const void *,
391
397
  size_t, const void *, size_t);
392
398
  static int checksum_final(struct archive_read *, const void *,
393
399
  size_t, const void *, size_t);
400
+ static void checksum_cleanup(struct archive_read *);
394
401
  static int decompression_init(struct archive_read *, enum enctype);
395
402
  static int decompress(struct archive_read *, const void **,
396
403
  size_t *, const void *, size_t *);
397
404
  static int decompression_cleanup(struct archive_read *);
398
405
  static void xmlattr_cleanup(struct xmlattr_list *);
399
- static void file_new(struct xar *, struct xmlattr_list *);
406
+ static int file_new(struct archive_read *,
407
+ struct xar *, struct xmlattr_list *);
400
408
  static void file_free(struct xar_file *);
401
- static void xattr_new(struct xar *, struct xmlattr_list *);
409
+ static int xattr_new(struct archive_read *,
410
+ struct xar *, struct xmlattr_list *);
402
411
  static void xattr_free(struct xattr *);
403
412
  static int getencoding(struct xmlattr_list *);
404
413
  static int getsumalgorithm(struct xmlattr_list *);
405
- static void unknowntag_start(struct xar *, const char *);
414
+ static int unknowntag_start(struct archive_read *,
415
+ struct xar *, const char *);
406
416
  static void unknowntag_end(struct xar *, const char *);
407
- static void xml_start(void *, const char *, struct xmlattr_list *);
417
+ static int xml_start(struct archive_read *,
418
+ const char *, struct xmlattr_list *);
408
419
  static void xml_end(void *, const char *);
409
420
  static void xml_data(void *, const char *, int);
410
421
  static int xml_parse_file_flags(struct xar *, const char *);
411
422
  static int xml_parse_file_ext2(struct xar *, const char *);
412
423
  #if defined(HAVE_LIBXML_XMLREADER_H)
413
- static int xml2_xmlattr_setup(struct xmlattr_list *, xmlTextReaderPtr);
424
+ static int xml2_xmlattr_setup(struct archive_read *,
425
+ struct xmlattr_list *, xmlTextReaderPtr);
414
426
  static int xml2_read_cb(void *, char *, int);
415
427
  static int xml2_close_cb(void *);
416
428
  static void xml2_error_hdr(void *, const char *, xmlParserSeverities,
417
429
  xmlTextReaderLocatorPtr);
418
430
  static int xml2_read_toc(struct archive_read *);
419
431
  #elif defined(HAVE_BSDXML_H) || defined(HAVE_EXPAT_H)
420
- static void expat_xmlattr_setup(struct xmlattr_list *, const XML_Char **);
432
+ struct expat_userData {
433
+ int state;
434
+ struct archive_read *archive;
435
+ };
436
+ static int expat_xmlattr_setup(struct archive_read *,
437
+ struct xmlattr_list *, const XML_Char **);
421
438
  static void expat_start_cb(void *, const XML_Char *, const XML_Char **);
422
439
  static void expat_end_cb(void *, const XML_Char *);
423
440
  static void expat_data_cb(void *, const XML_Char *, int);
@@ -431,6 +448,9 @@ archive_read_support_format_xar(struct archive *_a)
431
448
  struct archive_read *a = (struct archive_read *)_a;
432
449
  int r;
433
450
 
451
+ archive_check_magic(_a, ARCHIVE_READ_MAGIC,
452
+ ARCHIVE_STATE_NEW, "archive_read_support_format_xar");
453
+
434
454
  xar = (struct xar *)calloc(1, sizeof(*xar));
435
455
  if (xar == NULL) {
436
456
  archive_set_error(&a->archive, ENOMEM,
@@ -438,6 +458,11 @@ archive_read_support_format_xar(struct archive *_a)
438
458
  return (ARCHIVE_FATAL);
439
459
  }
440
460
 
461
+ /* initialize xar->file_queue */
462
+ xar->file_queue.allocated = 0;
463
+ xar->file_queue.used = 0;
464
+ xar->file_queue.files = NULL;
465
+
441
466
  r = __archive_read_register_format(a,
442
467
  xar,
443
468
  "xar",
@@ -446,18 +471,23 @@ archive_read_support_format_xar(struct archive *_a)
446
471
  xar_read_header,
447
472
  xar_read_data,
448
473
  xar_read_data_skip,
449
- xar_cleanup);
474
+ NULL,
475
+ xar_cleanup,
476
+ NULL,
477
+ NULL);
450
478
  if (r != ARCHIVE_OK)
451
479
  free(xar);
452
480
  return (r);
453
481
  }
454
482
 
455
483
  static int
456
- xar_bid(struct archive_read *a)
484
+ xar_bid(struct archive_read *a, int best_bid)
457
485
  {
458
486
  const unsigned char *b;
459
487
  int bid;
460
488
 
489
+ (void)best_bid; /* UNUSED */
490
+
461
491
  b = __archive_read_ahead(a, HEADER_SIZE, NULL);
462
492
  if (b == NULL)
463
493
  return (-1);
@@ -579,7 +609,8 @@ read_toc(struct archive_read *a)
579
609
  r = move_reading_point(a, xar->toc_chksum_offset);
580
610
  if (r != ARCHIVE_OK)
581
611
  return (r);
582
- b = __archive_read_ahead(a, xar->toc_chksum_size, &bytes);
612
+ b = __archive_read_ahead(a,
613
+ (size_t)xar->toc_chksum_size, &bytes);
583
614
  if (bytes < 0)
584
615
  return ((int)bytes);
585
616
  if ((uint64_t)bytes < xar->toc_chksum_size) {
@@ -588,11 +619,14 @@ read_toc(struct archive_read *a)
588
619
  "Truncated archive file");
589
620
  return (ARCHIVE_FATAL);
590
621
  }
591
- r = checksum_final(a, b, xar->toc_chksum_size, NULL, 0);
622
+ r = checksum_final(a, b,
623
+ (size_t)xar->toc_chksum_size, NULL, 0);
592
624
  __archive_read_consume(a, xar->toc_chksum_size);
593
625
  xar->offset += xar->toc_chksum_size;
594
626
  if (r != ARCHIVE_OK)
627
+ #ifndef DONT_FAIL_ON_CRC_ERROR
595
628
  return (ARCHIVE_FATAL);
629
+ #endif
596
630
  }
597
631
 
598
632
  /*
@@ -638,8 +672,17 @@ xar_read_header(struct archive_read *a, struct archive_entry *entry)
638
672
  int r;
639
673
 
640
674
  xar = (struct xar *)(a->format->data);
675
+ r = ARCHIVE_OK;
641
676
 
642
677
  if (xar->offset == 0) {
678
+ /* Create a character conversion object. */
679
+ if (xar->sconv == NULL) {
680
+ xar->sconv = archive_string_conversion_from_charset(
681
+ &(a->archive), "UTF-8", 1);
682
+ if (xar->sconv == NULL)
683
+ return (ARCHIVE_FATAL);
684
+ }
685
+
643
686
  /* Read TOC. */
644
687
  r = read_toc(a);
645
688
  if (r != ARCHIVE_OK)
@@ -662,19 +705,75 @@ xar_read_header(struct archive_read *a, struct archive_entry *entry)
662
705
  */
663
706
  file_free(file);
664
707
  }
665
- archive_entry_set_atime(entry, file->atime, 0);
666
- archive_entry_set_ctime(entry, file->ctime, 0);
667
- archive_entry_set_mtime(entry, file->mtime, 0);
708
+ if (file->has & HAS_ATIME) {
709
+ archive_entry_set_atime(entry, file->atime, 0);
710
+ }
711
+ if (file->has & HAS_CTIME) {
712
+ archive_entry_set_ctime(entry, file->ctime, 0);
713
+ }
714
+ if (file->has & HAS_MTIME) {
715
+ archive_entry_set_mtime(entry, file->mtime, 0);
716
+ }
668
717
  archive_entry_set_gid(entry, file->gid);
669
- if (file->gname.length > 0)
670
- archive_entry_update_gname_utf8(entry, file->gname.s);
718
+ if (file->gname.length > 0 &&
719
+ archive_entry_copy_gname_l(entry, file->gname.s,
720
+ archive_strlen(&(file->gname)), xar->sconv) != 0) {
721
+ if (errno == ENOMEM) {
722
+ archive_set_error(&a->archive, ENOMEM,
723
+ "Can't allocate memory for Gname");
724
+ return (ARCHIVE_FATAL);
725
+ }
726
+ archive_set_error(&a->archive,
727
+ ARCHIVE_ERRNO_FILE_FORMAT,
728
+ "Gname cannot be converted from %s to current locale.",
729
+ archive_string_conversion_charset_name(xar->sconv));
730
+ r = ARCHIVE_WARN;
731
+ }
671
732
  archive_entry_set_uid(entry, file->uid);
672
- if (file->uname.length > 0)
673
- archive_entry_update_uname_utf8(entry, file->uname.s);
733
+ if (file->uname.length > 0 &&
734
+ archive_entry_copy_uname_l(entry, file->uname.s,
735
+ archive_strlen(&(file->uname)), xar->sconv) != 0) {
736
+ if (errno == ENOMEM) {
737
+ archive_set_error(&a->archive, ENOMEM,
738
+ "Can't allocate memory for Uname");
739
+ return (ARCHIVE_FATAL);
740
+ }
741
+ archive_set_error(&a->archive,
742
+ ARCHIVE_ERRNO_FILE_FORMAT,
743
+ "Uname cannot be converted from %s to current locale.",
744
+ archive_string_conversion_charset_name(xar->sconv));
745
+ r = ARCHIVE_WARN;
746
+ }
674
747
  archive_entry_set_mode(entry, file->mode);
675
- archive_entry_update_pathname_utf8(entry, file->pathname.s);
676
- if (file->symlink.length > 0)
677
- archive_entry_update_symlink_utf8(entry, file->symlink.s);
748
+ if (archive_entry_copy_pathname_l(entry, file->pathname.s,
749
+ archive_strlen(&(file->pathname)), xar->sconv) != 0) {
750
+ if (errno == ENOMEM) {
751
+ archive_set_error(&a->archive, ENOMEM,
752
+ "Can't allocate memory for Pathname");
753
+ return (ARCHIVE_FATAL);
754
+ }
755
+ archive_set_error(&a->archive,
756
+ ARCHIVE_ERRNO_FILE_FORMAT,
757
+ "Pathname cannot be converted from %s to current locale.",
758
+ archive_string_conversion_charset_name(xar->sconv));
759
+ r = ARCHIVE_WARN;
760
+ }
761
+
762
+
763
+ if (file->symlink.length > 0 &&
764
+ archive_entry_copy_symlink_l(entry, file->symlink.s,
765
+ archive_strlen(&(file->symlink)), xar->sconv) != 0) {
766
+ if (errno == ENOMEM) {
767
+ archive_set_error(&a->archive, ENOMEM,
768
+ "Can't allocate memory for Linkname");
769
+ return (ARCHIVE_FATAL);
770
+ }
771
+ archive_set_error(&a->archive,
772
+ ARCHIVE_ERRNO_FILE_FORMAT,
773
+ "Linkname cannot be converted from %s to current locale.",
774
+ archive_string_conversion_charset_name(xar->sconv));
775
+ r = ARCHIVE_WARN;
776
+ }
678
777
  /* Set proper nlink. */
679
778
  if ((file->mode & AE_IFMT) == AE_IFDIR)
680
779
  archive_entry_set_nlink(entry, file->subdirs + 2);
@@ -682,8 +781,7 @@ xar_read_header(struct archive_read *a, struct archive_entry *entry)
682
781
  archive_entry_set_nlink(entry, file->nlink);
683
782
  archive_entry_set_size(entry, file->size);
684
783
  if (archive_strlen(&(file->hardlink)) > 0)
685
- archive_entry_update_hardlink_utf8(entry,
686
- file->hardlink.s);
784
+ archive_entry_set_hardlink(entry, file->hardlink.s);
687
785
  archive_entry_set_ino64(entry, file->ino64);
688
786
  if (file->has & HAS_DEV)
689
787
  archive_entry_set_dev(entry, file->dev);
@@ -704,11 +802,11 @@ xar_read_header(struct archive_read *a, struct archive_entry *entry)
704
802
  /*
705
803
  * Read extended attributes.
706
804
  */
707
- r = ARCHIVE_OK;
708
805
  xattr = file->xattr_list;
709
806
  while (xattr != NULL) {
710
807
  const void *d;
711
- size_t outbytes, used;
808
+ size_t outbytes = 0;
809
+ size_t used = 0;
712
810
 
713
811
  r = move_reading_point(a, xattr->offset);
714
812
  if (r != ARCHIVE_OK)
@@ -730,8 +828,20 @@ xar_read_header(struct archive_read *a, struct archive_entry *entry)
730
828
  r = checksum_final(a,
731
829
  xattr->a_sum.val, xattr->a_sum.len,
732
830
  xattr->e_sum.val, xattr->e_sum.len);
733
- if (r != ARCHIVE_OK)
831
+ if (r != ARCHIVE_OK) {
832
+ #ifndef DONT_FAIL_ON_CRC_ERROR
833
+ archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC,
834
+ "Xattr checksum error");
835
+ r = ARCHIVE_WARN;
836
+ break;
837
+ #endif
838
+ }
839
+ if (xattr->name.s == NULL) {
840
+ archive_set_error(&(a->archive), ARCHIVE_ERRNO_MISC,
841
+ "Xattr name error");
842
+ r = ARCHIVE_WARN;
734
843
  break;
844
+ }
735
845
  archive_entry_xattr_add_entry(entry,
736
846
  xattr->name.s, d, outbytes);
737
847
  xattr = xattr->next;
@@ -754,13 +864,19 @@ xar_read_header(struct archive_read *a, struct archive_entry *entry)
754
864
 
755
865
  static int
756
866
  xar_read_data(struct archive_read *a,
757
- const void **buff, size_t *size, off_t *offset)
867
+ const void **buff, size_t *size, int64_t *offset)
758
868
  {
759
869
  struct xar *xar;
760
- size_t used;
870
+ size_t used = 0;
761
871
  int r;
762
872
 
763
873
  xar = (struct xar *)(a->format->data);
874
+
875
+ if (xar->entry_unconsumed) {
876
+ __archive_read_consume(a, xar->entry_unconsumed);
877
+ xar->entry_unconsumed = 0;
878
+ }
879
+
764
880
  if (xar->end_of_file || xar->entry_remaining <= 0) {
765
881
  r = ARCHIVE_EOF;
766
882
  goto abort_read_data;
@@ -786,7 +902,7 @@ xar_read_data(struct archive_read *a,
786
902
  xar->total += *size;
787
903
  xar->offset += used;
788
904
  xar->entry_remaining -= used;
789
- __archive_read_consume(a, used);
905
+ xar->entry_unconsumed = used;
790
906
 
791
907
  if (xar->entry_remaining == 0) {
792
908
  if (xar->entry_total != xar->entry_size) {
@@ -819,10 +935,12 @@ xar_read_data_skip(struct archive_read *a)
819
935
  xar = (struct xar *)(a->format->data);
820
936
  if (xar->end_of_file)
821
937
  return (ARCHIVE_EOF);
822
- bytes_skipped = __archive_read_skip(a, xar->entry_remaining);
938
+ bytes_skipped = __archive_read_consume(a, xar->entry_remaining +
939
+ xar->entry_unconsumed);
823
940
  if (bytes_skipped < 0)
824
941
  return (ARCHIVE_FATAL);
825
942
  xar->offset += bytes_skipped;
943
+ xar->entry_unconsumed = 0;
826
944
  return (ARCHIVE_OK);
827
945
  }
828
946
 
@@ -835,6 +953,7 @@ xar_cleanup(struct archive_read *a)
835
953
  int r;
836
954
 
837
955
  xar = (struct xar *)(a->format->data);
956
+ checksum_cleanup(a);
838
957
  r = decompression_cleanup(a);
839
958
  hdlink = xar->hdlink_list;
840
959
  while (hdlink != NULL) {
@@ -845,6 +964,7 @@ xar_cleanup(struct archive_read *a)
845
964
  }
846
965
  for (i = 0; i < xar->file_queue.used; i++)
847
966
  file_free(xar->file_queue.files[i]);
967
+ free(xar->file_queue.files);
848
968
  while (xar->unknowntags != NULL) {
849
969
  struct unknown_tag *tag;
850
970
 
@@ -853,6 +973,7 @@ xar_cleanup(struct archive_read *a)
853
973
  archive_string_free(&(tag->name));
854
974
  free(tag);
855
975
  }
976
+ free(xar->outbuff);
856
977
  free(xar);
857
978
  a->format->data = NULL;
858
979
  return (r);
@@ -870,15 +991,19 @@ move_reading_point(struct archive_read *a, uint64_t offset)
870
991
 
871
992
  step = offset - (xar->offset - xar->h_base);
872
993
  if (step > 0) {
873
- step = __archive_read_skip(a, step);
994
+ step = __archive_read_consume(a, step);
874
995
  if (step < 0)
875
996
  return ((int)step);
876
997
  xar->offset += step;
877
998
  } else {
878
- archive_set_error(&(a->archive),
879
- ARCHIVE_ERRNO_MISC,
880
- "Cannot seek.");
881
- return (ARCHIVE_FAILED);
999
+ int64_t pos = __archive_read_seek(a, xar->h_base + offset, SEEK_SET);
1000
+ if (pos == ARCHIVE_FAILED) {
1001
+ archive_set_error(&(a->archive),
1002
+ ARCHIVE_ERRNO_MISC,
1003
+ "Cannot seek.");
1004
+ return (ARCHIVE_FAILED);
1005
+ }
1006
+ xar->offset = pos;
882
1007
  }
883
1008
  }
884
1009
  return (ARCHIVE_OK);
@@ -944,6 +1069,9 @@ atol10(const char *p, size_t char_cnt)
944
1069
  uint64_t l;
945
1070
  int digit;
946
1071
 
1072
+ if (char_cnt == 0)
1073
+ return (0);
1074
+
947
1075
  l = 0;
948
1076
  digit = *p - '0';
949
1077
  while (digit >= 0 && digit < 10 && char_cnt-- > 0) {
@@ -958,7 +1086,10 @@ atol8(const char *p, size_t char_cnt)
958
1086
  {
959
1087
  int64_t l;
960
1088
  int digit;
961
-
1089
+
1090
+ if (char_cnt == 0)
1091
+ return (0);
1092
+
962
1093
  l = 0;
963
1094
  while (char_cnt-- > 0) {
964
1095
  if (*p >= '0' && *p <= '7')
@@ -1009,18 +1140,23 @@ static time_t
1009
1140
  time_from_tm(struct tm *t)
1010
1141
  {
1011
1142
  #if HAVE_TIMEGM
1012
- /* Use platform timegm() if available. */
1013
- return (timegm(t));
1143
+ /* Use platform timegm() if available. */
1144
+ return (timegm(t));
1145
+ #elif HAVE__MKGMTIME64
1146
+ return (_mkgmtime64(t));
1014
1147
  #else
1015
- /* Else use direct calculation using POSIX assumptions. */
1016
- /* First, fix up tm_yday based on the year/month/day. */
1017
- mktime(t);
1018
- /* Then we can compute timegm() from first principles. */
1019
- return (t->tm_sec + t->tm_min * 60 + t->tm_hour * 3600
1020
- + t->tm_yday * 86400 + (t->tm_year - 70) * 31536000
1021
- + ((t->tm_year - 69) / 4) * 86400 -
1022
- ((t->tm_year - 1) / 100) * 86400
1023
- + ((t->tm_year + 299) / 400) * 86400);
1148
+ /* Else use direct calculation using POSIX assumptions. */
1149
+ /* First, fix up tm_yday based on the year/month/day. */
1150
+ mktime(t);
1151
+ /* Then we can compute timegm() from first principles. */
1152
+ return (t->tm_sec
1153
+ + t->tm_min * 60
1154
+ + t->tm_hour * 3600
1155
+ + t->tm_yday * 86400
1156
+ + (t->tm_year - 70) * 31536000
1157
+ + ((t->tm_year - 69) / 4) * 86400
1158
+ - ((t->tm_year - 1) / 100) * 86400
1159
+ + ((t->tm_year + 299) / 400) * 86400);
1024
1160
  #endif
1025
1161
  }
1026
1162
 
@@ -1084,8 +1220,9 @@ parse_time(const char *p, size_t n)
1084
1220
  return (t);
1085
1221
  }
1086
1222
 
1087
- static void
1088
- heap_add_entry(struct heap_queue *heap, struct xar_file *file)
1223
+ static int
1224
+ heap_add_entry(struct archive_read *a,
1225
+ struct heap_queue *heap, struct xar_file *file)
1089
1226
  {
1090
1227
  uint64_t file_id, parent_id;
1091
1228
  int hole, parent;
@@ -1093,21 +1230,30 @@ heap_add_entry(struct heap_queue *heap, struct xar_file *file)
1093
1230
  /* Expand our pending files list as necessary. */
1094
1231
  if (heap->used >= heap->allocated) {
1095
1232
  struct xar_file **new_pending_files;
1096
- int new_size = heap->allocated * 2;
1233
+ int new_size;
1097
1234
 
1098
1235
  if (heap->allocated < 1024)
1099
1236
  new_size = 1024;
1237
+ else
1238
+ new_size = heap->allocated * 2;
1100
1239
  /* Overflow might keep us from growing the list. */
1101
- if (new_size <= heap->allocated)
1102
- __archive_errx(1, "Out of memory");
1240
+ if (new_size <= heap->allocated) {
1241
+ archive_set_error(&a->archive,
1242
+ ENOMEM, "Out of memory");
1243
+ return (ARCHIVE_FATAL);
1244
+ }
1103
1245
  new_pending_files = (struct xar_file **)
1104
1246
  malloc(new_size * sizeof(new_pending_files[0]));
1105
- if (new_pending_files == NULL)
1106
- __archive_errx(1, "Out of memory");
1107
- memcpy(new_pending_files, heap->files,
1108
- heap->allocated * sizeof(new_pending_files[0]));
1109
- if (heap->files != NULL)
1247
+ if (new_pending_files == NULL) {
1248
+ archive_set_error(&a->archive,
1249
+ ENOMEM, "Out of memory");
1250
+ return (ARCHIVE_FATAL);
1251
+ }
1252
+ if (heap->allocated) {
1253
+ memcpy(new_pending_files, heap->files,
1254
+ heap->allocated * sizeof(new_pending_files[0]));
1110
1255
  free(heap->files);
1256
+ }
1111
1257
  heap->files = new_pending_files;
1112
1258
  heap->allocated = new_size;
1113
1259
  }
@@ -1123,13 +1269,15 @@ heap_add_entry(struct heap_queue *heap, struct xar_file *file)
1123
1269
  parent_id = heap->files[parent]->id;
1124
1270
  if (file_id >= parent_id) {
1125
1271
  heap->files[hole] = file;
1126
- return;
1272
+ return (ARCHIVE_OK);
1127
1273
  }
1128
- // Move parent into hole <==> move hole up tree.
1274
+ /* Move parent into hole <==> move hole up tree. */
1129
1275
  heap->files[hole] = heap->files[parent];
1130
1276
  hole = parent;
1131
1277
  }
1132
1278
  heap->files[0] = file;
1279
+
1280
+ return (ARCHIVE_OK);
1133
1281
  }
1134
1282
 
1135
1283
  static struct xar_file *
@@ -1155,14 +1303,14 @@ heap_get_entry(struct heap_queue *heap)
1155
1303
  /*
1156
1304
  * Rebalance the heap.
1157
1305
  */
1158
- a = 0; // Starting element and its heap key
1306
+ a = 0; /* Starting element and its heap key */
1159
1307
  a_id = heap->files[a]->id;
1160
1308
  for (;;) {
1161
- b = a + a + 1; // First child
1309
+ b = a + a + 1; /* First child */
1162
1310
  if (b >= heap->used)
1163
1311
  return (r);
1164
1312
  b_id = heap->files[b]->id;
1165
- c = b + 1; // Use second child if it is smaller.
1313
+ c = b + 1; /* Use second child if it is smaller. */
1166
1314
  if (c < heap->used) {
1167
1315
  c_id = heap->files[c]->id;
1168
1316
  if (c_id < b_id) {
@@ -1179,8 +1327,8 @@ heap_get_entry(struct heap_queue *heap)
1179
1327
  }
1180
1328
  }
1181
1329
 
1182
- static void
1183
- add_link(struct xar *xar, struct xar_file *file)
1330
+ static int
1331
+ add_link(struct archive_read *a, struct xar *xar, struct xar_file *file)
1184
1332
  {
1185
1333
  struct hdlink *hdlink;
1186
1334
 
@@ -1189,18 +1337,21 @@ add_link(struct xar *xar, struct xar_file *file)
1189
1337
  file->hdnext = hdlink->files;
1190
1338
  hdlink->cnt++;
1191
1339
  hdlink->files = file;
1192
- return;
1340
+ return (ARCHIVE_OK);
1193
1341
  }
1194
1342
  }
1195
1343
  hdlink = malloc(sizeof(*hdlink));
1196
- if (hdlink == NULL)
1197
- __archive_errx(1, "No memory for add_link()");
1344
+ if (hdlink == NULL) {
1345
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
1346
+ return (ARCHIVE_FATAL);
1347
+ }
1198
1348
  file->hdnext = NULL;
1199
1349
  hdlink->id = file->link;
1200
1350
  hdlink->cnt = 1;
1201
1351
  hdlink->files = file;
1202
1352
  hdlink->next = xar->hdlink_list;
1203
1353
  xar->hdlink_list = hdlink;
1354
+ return (ARCHIVE_OK);
1204
1355
  }
1205
1356
 
1206
1357
  static void
@@ -1362,6 +1513,13 @@ decompression_init(struct archive_read *a, enum enctype encoding)
1362
1513
  break;
1363
1514
  #endif
1364
1515
  #if defined(HAVE_LZMA_H) && defined(HAVE_LIBLZMA)
1516
+ #if LZMA_VERSION_MAJOR >= 5
1517
+ /* Effectively disable the limiter. */
1518
+ #define LZMA_MEMLIMIT UINT64_MAX
1519
+ #else
1520
+ /* NOTE: This needs to check memory size which running system has. */
1521
+ #define LZMA_MEMLIMIT (1U << 30)
1522
+ #endif
1365
1523
  case XZ:
1366
1524
  case LZMA:
1367
1525
  if (xar->lzstream_valid) {
@@ -1370,11 +1528,11 @@ decompression_init(struct archive_read *a, enum enctype encoding)
1370
1528
  }
1371
1529
  if (xar->entry_encoding == XZ)
1372
1530
  r = lzma_stream_decoder(&(xar->lzstream),
1373
- (1U << 30),/* memlimit */
1531
+ LZMA_MEMLIMIT,/* memlimit */
1374
1532
  LZMA_CONCATENATED);
1375
1533
  else
1376
1534
  r = lzma_alone_decoder(&(xar->lzstream),
1377
- (1U << 30));/* memlimit */
1535
+ LZMA_MEMLIMIT);/* memlimit */
1378
1536
  if (r != LZMA_OK) {
1379
1537
  switch (r) {
1380
1538
  case LZMA_MEM_ERROR:
@@ -1404,34 +1562,6 @@ decompression_init(struct archive_read *a, enum enctype encoding)
1404
1562
  xar->lzstream.total_in = 0;
1405
1563
  xar->lzstream.total_out = 0;
1406
1564
  break;
1407
- #elif defined(HAVE_LZMADEC_H) && defined(HAVE_LIBLZMADEC)
1408
- case LZMA:
1409
- if (xar->lzstream_valid)
1410
- lzmadec_end(&(xar->lzstream));
1411
- r = lzmadec_init(&(xar->lzstream));
1412
- if (r != LZMADEC_OK) {
1413
- switch (r) {
1414
- case LZMADEC_HEADER_ERROR:
1415
- archive_set_error(&a->archive,
1416
- ARCHIVE_ERRNO_MISC,
1417
- "Internal error initializing "
1418
- "compression library: "
1419
- "invalid header");
1420
- break;
1421
- case LZMADEC_MEM_ERROR:
1422
- archive_set_error(&a->archive,
1423
- ENOMEM,
1424
- "Internal error initializing "
1425
- "compression library: "
1426
- "out of memory");
1427
- break;
1428
- }
1429
- return (ARCHIVE_FATAL);
1430
- }
1431
- xar->lzstream_valid = 1;
1432
- xar->lzstream.total_in = 0;
1433
- xar->lzstream.total_out = 0;
1434
- break;
1435
1565
  #endif
1436
1566
  /*
1437
1567
  * Unsupported compression.
@@ -1441,9 +1571,7 @@ decompression_init(struct archive_read *a, enum enctype encoding)
1441
1571
  case BZIP2:
1442
1572
  #endif
1443
1573
  #if !defined(HAVE_LZMA_H) || !defined(HAVE_LIBLZMA)
1444
- #if !defined(HAVE_LZMADEC_H) || !defined(HAVE_LIBLZMADEC)
1445
1574
  case LZMA:
1446
- #endif
1447
1575
  case XZ:
1448
1576
  #endif
1449
1577
  switch (xar->entry_encoding) {
@@ -1473,9 +1601,17 @@ decompress(struct archive_read *a, const void **buff, size_t *outbytes,
1473
1601
  avail_in = *used;
1474
1602
  outbuff = (void *)(uintptr_t)*buff;
1475
1603
  if (outbuff == NULL) {
1476
- outbuff = xar->buff;
1604
+ if (xar->outbuff == NULL) {
1605
+ xar->outbuff = malloc(OUTBUFF_SIZE);
1606
+ if (xar->outbuff == NULL) {
1607
+ archive_set_error(&a->archive, ENOMEM,
1608
+ "Couldn't allocate memory for out buffer");
1609
+ return (ARCHIVE_FATAL);
1610
+ }
1611
+ }
1612
+ outbuff = xar->outbuff;
1477
1613
  *buff = outbuff;
1478
- avail_out = sizeof(xar->buff);
1614
+ avail_out = OUTBUFF_SIZE;
1479
1615
  } else
1480
1616
  avail_out = *outbytes;
1481
1617
  switch (xar->rd_encoding) {
@@ -1555,51 +1691,17 @@ decompress(struct archive_read *a, const void **buff, size_t *outbytes,
1555
1691
  *used = avail_in - xar->lzstream.avail_in;
1556
1692
  *outbytes = avail_out - xar->lzstream.avail_out;
1557
1693
  break;
1558
- #elif defined(HAVE_LZMADEC_H) && defined(HAVE_LIBLZMADEC)
1559
- case LZMA:
1560
- xar->lzstream.next_in = (unsigned char *)(uintptr_t)b;
1561
- xar->lzstream.avail_in = avail_in;
1562
- xar->lzstream.next_out = (unsigned char *)outbuff;
1563
- xar->lzstream.avail_out = avail_out;
1564
- r = lzmadec_decode(&(xar->lzstream), 0);
1565
- switch (r) {
1566
- case LZMADEC_STREAM_END: /* Found end of stream. */
1567
- switch (lzmadec_end(&(xar->lzstream))) {
1568
- case LZMADEC_OK:
1569
- break;
1570
- default:
1571
- archive_set_error(&(a->archive),
1572
- ARCHIVE_ERRNO_MISC,
1573
- "Failed to clean up lzmadec decompressor");
1574
- return (ARCHIVE_FATAL);
1575
- }
1576
- xar->lzstream_valid = 0;
1577
- /* FALLTHROUGH */
1578
- case LZMADEC_OK: /* Decompressor made some progress. */
1579
- break;
1580
- default:
1581
- archive_set_error(&(a->archive),
1582
- ARCHIVE_ERRNO_MISC,
1583
- "lzmadec decompression failed(%d)",
1584
- r);
1585
- return (ARCHIVE_FATAL);
1586
- }
1587
- *used = avail_in - xar->lzstream.avail_in;
1588
- *outbytes = avail_out - xar->lzstream.avail_out;
1589
- break;
1590
1694
  #endif
1591
1695
  #if !defined(HAVE_BZLIB_H) || !defined(BZ_CONFIG_ERROR)
1592
1696
  case BZIP2:
1593
1697
  #endif
1594
1698
  #if !defined(HAVE_LZMA_H) || !defined(HAVE_LIBLZMA)
1595
- #if !defined(HAVE_LZMADEC_H) || !defined(HAVE_LIBLZMADEC)
1596
1699
  case LZMA:
1597
- #endif
1598
1700
  case XZ:
1599
1701
  #endif
1600
1702
  case NONE:
1601
1703
  default:
1602
- if (outbuff == xar->buff) {
1704
+ if (outbuff == xar->outbuff) {
1603
1705
  *buff = b;
1604
1706
  *used = avail_in;
1605
1707
  *outbytes = avail_in;
@@ -1657,6 +1759,16 @@ decompression_cleanup(struct archive_read *a)
1657
1759
  return (r);
1658
1760
  }
1659
1761
 
1762
+ static void
1763
+ checksum_cleanup(struct archive_read *a) {
1764
+ struct xar *xar;
1765
+
1766
+ xar = (struct xar *)(a->format->data);
1767
+
1768
+ _checksum_final(&(xar->a_sumwrk), NULL, 0);
1769
+ _checksum_final(&(xar->e_sumwrk), NULL, 0);
1770
+ }
1771
+
1660
1772
  static void
1661
1773
  xmlattr_cleanup(struct xmlattr_list *list)
1662
1774
  {
@@ -1674,19 +1786,21 @@ xmlattr_cleanup(struct xmlattr_list *list)
1674
1786
  list->last = &(list->first);
1675
1787
  }
1676
1788
 
1677
- static void
1678
- file_new(struct xar *xar, struct xmlattr_list *list)
1789
+ static int
1790
+ file_new(struct archive_read *a, struct xar *xar, struct xmlattr_list *list)
1679
1791
  {
1680
1792
  struct xar_file *file;
1681
1793
  struct xmlattr *attr;
1682
1794
 
1683
1795
  file = calloc(1, sizeof(*file));
1684
- if (file == NULL)
1685
- __archive_errx(1, "Out of memory");
1796
+ if (file == NULL) {
1797
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
1798
+ return (ARCHIVE_FATAL);
1799
+ }
1686
1800
  file->parent = xar->file;
1687
1801
  file->mode = 0777 | AE_IFREG;
1688
- file->atime = time(NULL);
1689
- file->mtime = time(NULL);
1802
+ file->atime = 0;
1803
+ file->mtime = 0;
1690
1804
  xar->file = file;
1691
1805
  xar->xattr = NULL;
1692
1806
  for (attr = list->first; attr != NULL; attr = attr->next) {
@@ -1694,7 +1808,9 @@ file_new(struct xar *xar, struct xmlattr_list *list)
1694
1808
  file->id = atol10(attr->value, strlen(attr->value));
1695
1809
  }
1696
1810
  file->nlink = 1;
1697
- heap_add_entry(&(xar->file_queue), file);
1811
+ if (heap_add_entry(a, &(xar->file_queue), file) != ARCHIVE_OK)
1812
+ return (ARCHIVE_FATAL);
1813
+ return (ARCHIVE_OK);
1698
1814
  }
1699
1815
 
1700
1816
  static void
@@ -1719,15 +1835,17 @@ file_free(struct xar_file *file)
1719
1835
  free(file);
1720
1836
  }
1721
1837
 
1722
- static void
1723
- xattr_new(struct xar *xar, struct xmlattr_list *list)
1838
+ static int
1839
+ xattr_new(struct archive_read *a, struct xar *xar, struct xmlattr_list *list)
1724
1840
  {
1725
1841
  struct xattr *xattr, **nx;
1726
1842
  struct xmlattr *attr;
1727
1843
 
1728
1844
  xattr = calloc(1, sizeof(*xattr));
1729
- if (xattr == NULL)
1730
- __archive_errx(1, "Out of memory");
1845
+ if (xattr == NULL) {
1846
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
1847
+ return (ARCHIVE_FATAL);
1848
+ }
1731
1849
  xar->xattr = xattr;
1732
1850
  for (attr = list->first; attr != NULL; attr = attr->next) {
1733
1851
  if (strcmp(attr->name, "id") == 0)
@@ -1741,6 +1859,8 @@ xattr_new(struct xar *xar, struct xmlattr_list *list)
1741
1859
  }
1742
1860
  xattr->next = *nx;
1743
1861
  *nx = xattr;
1862
+
1863
+ return (ARCHIVE_OK);
1744
1864
  }
1745
1865
 
1746
1866
  static void
@@ -1796,25 +1916,28 @@ getsumalgorithm(struct xmlattr_list *list)
1796
1916
  return (alg);
1797
1917
  }
1798
1918
 
1799
- static void
1800
- unknowntag_start(struct xar *xar, const char *name)
1919
+ static int
1920
+ unknowntag_start(struct archive_read *a, struct xar *xar, const char *name)
1801
1921
  {
1802
1922
  struct unknown_tag *tag;
1803
1923
 
1804
- #if DEBUG
1805
- fprintf(stderr, "unknowntag_start:%s\n", name);
1806
- #endif
1807
1924
  tag = malloc(sizeof(*tag));
1808
- if (tag == NULL)
1809
- __archive_errx(1, "Out of memory");
1925
+ if (tag == NULL) {
1926
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
1927
+ return (ARCHIVE_FATAL);
1928
+ }
1810
1929
  tag->next = xar->unknowntags;
1811
1930
  archive_string_init(&(tag->name));
1812
1931
  archive_strcpy(&(tag->name), name);
1813
1932
  if (xar->unknowntags == NULL) {
1933
+ #if DEBUG
1934
+ fprintf(stderr, "UNKNOWNTAG_START:%s\n", name);
1935
+ #endif
1814
1936
  xar->xmlsts_unknown = xar->xmlsts;
1815
1937
  xar->xmlsts = UNKNOWN;
1816
1938
  }
1817
1939
  xar->unknowntags = tag;
1940
+ return (ARCHIVE_OK);
1818
1941
  }
1819
1942
 
1820
1943
  static void
@@ -1822,9 +1945,6 @@ unknowntag_end(struct xar *xar, const char *name)
1822
1945
  {
1823
1946
  struct unknown_tag *tag;
1824
1947
 
1825
- #if DEBUG
1826
- fprintf(stderr, "unknowntag_end:%s\n", name);
1827
- #endif
1828
1948
  tag = xar->unknowntags;
1829
1949
  if (tag == NULL || name == NULL)
1830
1950
  return;
@@ -1832,19 +1952,21 @@ unknowntag_end(struct xar *xar, const char *name)
1832
1952
  xar->unknowntags = tag->next;
1833
1953
  archive_string_free(&(tag->name));
1834
1954
  free(tag);
1835
- if (xar->unknowntags == NULL)
1955
+ if (xar->unknowntags == NULL) {
1956
+ #if DEBUG
1957
+ fprintf(stderr, "UNKNOWNTAG_END:%s\n", name);
1958
+ #endif
1836
1959
  xar->xmlsts = xar->xmlsts_unknown;
1960
+ }
1837
1961
  }
1838
1962
  }
1839
1963
 
1840
- static void
1841
- xml_start(void *userData, const char *name, struct xmlattr_list *list)
1964
+ static int
1965
+ xml_start(struct archive_read *a, const char *name, struct xmlattr_list *list)
1842
1966
  {
1843
- struct archive_read *a;
1844
1967
  struct xar *xar;
1845
1968
  struct xmlattr *attr;
1846
1969
 
1847
- a = (struct archive_read *)userData;
1848
1970
  xar = (struct xar *)(a->format->data);
1849
1971
 
1850
1972
  #if DEBUG
@@ -1859,13 +1981,15 @@ xml_start(void *userData, const char *name, struct xmlattr_list *list)
1859
1981
  if (strcmp(name, "xar") == 0)
1860
1982
  xar->xmlsts = XAR;
1861
1983
  else
1862
- unknowntag_start(xar, name);
1984
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
1985
+ return (ARCHIVE_FATAL);
1863
1986
  break;
1864
1987
  case XAR:
1865
1988
  if (strcmp(name, "toc") == 0)
1866
1989
  xar->xmlsts = TOC;
1867
1990
  else
1868
- unknowntag_start(xar, name);
1991
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
1992
+ return (ARCHIVE_FATAL);
1869
1993
  break;
1870
1994
  case TOC:
1871
1995
  if (strcmp(name, "creation-time") == 0)
@@ -1873,11 +1997,13 @@ xml_start(void *userData, const char *name, struct xmlattr_list *list)
1873
1997
  else if (strcmp(name, "checksum") == 0)
1874
1998
  xar->xmlsts = TOC_CHECKSUM;
1875
1999
  else if (strcmp(name, "file") == 0) {
1876
- file_new(xar, list);
2000
+ if (file_new(a, xar, list) != ARCHIVE_OK)
2001
+ return (ARCHIVE_FATAL);
1877
2002
  xar->xmlsts = TOC_FILE;
1878
2003
  }
1879
2004
  else
1880
- unknowntag_start(xar, name);
2005
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
2006
+ return (ARCHIVE_FATAL);
1881
2007
  break;
1882
2008
  case TOC_CHECKSUM:
1883
2009
  if (strcmp(name, "offset") == 0)
@@ -1885,16 +2011,19 @@ xml_start(void *userData, const char *name, struct xmlattr_list *list)
1885
2011
  else if (strcmp(name, "size") == 0)
1886
2012
  xar->xmlsts = TOC_CHECKSUM_SIZE;
1887
2013
  else
1888
- unknowntag_start(xar, name);
2014
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
2015
+ return (ARCHIVE_FATAL);
1889
2016
  break;
1890
2017
  case TOC_FILE:
1891
2018
  if (strcmp(name, "file") == 0) {
1892
- file_new(xar, list);
2019
+ if (file_new(a, xar, list) != ARCHIVE_OK)
2020
+ return (ARCHIVE_FATAL);
1893
2021
  }
1894
2022
  else if (strcmp(name, "data") == 0)
1895
2023
  xar->xmlsts = FILE_DATA;
1896
2024
  else if (strcmp(name, "ea") == 0) {
1897
- xattr_new(xar, list);
2025
+ if (xattr_new(a, xar, list) != ARCHIVE_OK)
2026
+ return (ARCHIVE_FATAL);
1898
2027
  xar->xmlsts = FILE_EA;
1899
2028
  }
1900
2029
  else if (strcmp(name, "ctime") == 0)
@@ -1931,10 +2060,12 @@ xml_start(void *userData, const char *name, struct xmlattr_list *list)
1931
2060
  xar->file->hdnext = xar->hdlink_orgs;
1932
2061
  xar->hdlink_orgs = xar->file;
1933
2062
  } else {
1934
- xar->file->link = atol10(attr->value,
2063
+ xar->file->link = (unsigned)atol10(attr->value,
1935
2064
  strlen(attr->value));
1936
2065
  if (xar->file->link > 0)
1937
- add_link(xar, xar->file);
2066
+ if (add_link(a, xar, xar->file) != ARCHIVE_OK) {
2067
+ return (ARCHIVE_FATAL);
2068
+ };
1938
2069
  }
1939
2070
  }
1940
2071
  }
@@ -1954,7 +2085,8 @@ xml_start(void *userData, const char *name, struct xmlattr_list *list)
1954
2085
  else if (strcmp(name, "ext2") == 0)
1955
2086
  xar->xmlsts = FILE_EXT2;
1956
2087
  else
1957
- unknowntag_start(xar, name);
2088
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
2089
+ return (ARCHIVE_FATAL);
1958
2090
  break;
1959
2091
  case FILE_DATA:
1960
2092
  if (strcmp(name, "length") == 0)
@@ -1978,7 +2110,8 @@ xml_start(void *userData, const char *name, struct xmlattr_list *list)
1978
2110
  else if (strcmp(name, "content") == 0)
1979
2111
  xar->xmlsts = FILE_DATA_CONTENT;
1980
2112
  else
1981
- unknowntag_start(xar, name);
2113
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
2114
+ return (ARCHIVE_FATAL);
1982
2115
  break;
1983
2116
  case FILE_DEVICE:
1984
2117
  if (strcmp(name, "major") == 0)
@@ -1986,10 +2119,12 @@ xml_start(void *userData, const char *name, struct xmlattr_list *list)
1986
2119
  else if (strcmp(name, "minor") == 0)
1987
2120
  xar->xmlsts = FILE_DEVICE_MINOR;
1988
2121
  else
1989
- unknowntag_start(xar, name);
2122
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
2123
+ return (ARCHIVE_FATAL);
1990
2124
  break;
1991
2125
  case FILE_DATA_CONTENT:
1992
- unknowntag_start(xar, name);
2126
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
2127
+ return (ARCHIVE_FATAL);
1993
2128
  break;
1994
2129
  case FILE_EA:
1995
2130
  if (strcmp(name, "length") == 0)
@@ -2010,25 +2145,29 @@ xml_start(void *userData, const char *name, struct xmlattr_list *list)
2010
2145
  else if (strcmp(name, "fstype") == 0)
2011
2146
  xar->xmlsts = FILE_EA_FSTYPE;
2012
2147
  else
2013
- unknowntag_start(xar, name);
2148
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
2149
+ return (ARCHIVE_FATAL);
2014
2150
  break;
2015
2151
  case FILE_ACL:
2016
2152
  if (strcmp(name, "appleextended") == 0)
2017
2153
  xar->xmlsts = FILE_ACL_APPLEEXTENDED;
2018
- if (strcmp(name, "default") == 0)
2154
+ else if (strcmp(name, "default") == 0)
2019
2155
  xar->xmlsts = FILE_ACL_DEFAULT;
2020
2156
  else if (strcmp(name, "access") == 0)
2021
2157
  xar->xmlsts = FILE_ACL_ACCESS;
2022
2158
  else
2023
- unknowntag_start(xar, name);
2159
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
2160
+ return (ARCHIVE_FATAL);
2024
2161
  break;
2025
2162
  case FILE_FLAGS:
2026
2163
  if (!xml_parse_file_flags(xar, name))
2027
- unknowntag_start(xar, name);
2164
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
2165
+ return (ARCHIVE_FATAL);
2028
2166
  break;
2029
2167
  case FILE_EXT2:
2030
2168
  if (!xml_parse_file_ext2(xar, name))
2031
- unknowntag_start(xar, name);
2169
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
2170
+ return (ARCHIVE_FATAL);
2032
2171
  break;
2033
2172
  case TOC_CREATION_TIME:
2034
2173
  case TOC_CHECKSUM_OFFSET:
@@ -2096,9 +2235,11 @@ xml_start(void *userData, const char *name, struct xmlattr_list *list)
2096
2235
  case FILE_EXT2_TopDir:
2097
2236
  case FILE_EXT2_Reserved:
2098
2237
  case UNKNOWN:
2099
- unknowntag_start(xar, name);
2238
+ if (unknowntag_start(a, xar, name) != ARCHIVE_OK)
2239
+ return (ARCHIVE_FATAL);
2100
2240
  break;
2101
2241
  }
2242
+ return (ARCHIVE_OK);
2102
2243
  }
2103
2244
 
2104
2245
  static void
@@ -2470,28 +2611,29 @@ static const int base64[256] = {
2470
2611
  };
2471
2612
 
2472
2613
  static void
2473
- strappend_base64(struct archive_string *as, const char *s, size_t l)
2614
+ strappend_base64(struct xar *xar,
2615
+ struct archive_string *as, const char *s, size_t l)
2474
2616
  {
2475
2617
  unsigned char buff[256];
2476
2618
  unsigned char *out;
2477
2619
  const unsigned char *b;
2478
2620
  size_t len;
2479
2621
 
2622
+ (void)xar; /* UNUSED */
2480
2623
  len = 0;
2481
2624
  out = buff;
2482
2625
  b = (const unsigned char *)s;
2483
2626
  while (l > 0) {
2484
2627
  int n = 0;
2485
2628
 
2486
- if (l > 0) {
2487
- if (base64[b[0]] < 0 || base64[b[1]] < 0)
2488
- break;
2489
- n = base64[*b++] << 18;
2490
- n |= base64[*b++] << 12;
2491
- *out++ = n >> 16;
2492
- len++;
2493
- l -= 2;
2494
- }
2629
+ if (base64[b[0]] < 0 || base64[b[1]] < 0)
2630
+ break;
2631
+ n = base64[*b++] << 18;
2632
+ n |= base64[*b++] << 12;
2633
+ *out++ = n >> 16;
2634
+ len++;
2635
+ l -= 2;
2636
+
2495
2637
  if (l > 0) {
2496
2638
  if (base64[*b] < 0)
2497
2639
  break;
@@ -2518,6 +2660,14 @@ strappend_base64(struct archive_string *as, const char *s, size_t l)
2518
2660
  archive_strncat(as, (const char *)buff, len);
2519
2661
  }
2520
2662
 
2663
+ static int
2664
+ is_string(const char *known, const char *data, size_t len)
2665
+ {
2666
+ if (strlen(known) != len)
2667
+ return -1;
2668
+ return memcmp(data, known, len);
2669
+ }
2670
+
2521
2671
  static void
2522
2672
  xml_data(void *userData, const char *s, int len)
2523
2673
  {
@@ -2530,9 +2680,9 @@ xml_data(void *userData, const char *s, int len)
2530
2680
  #if DEBUG
2531
2681
  {
2532
2682
  char buff[1024];
2533
- if (len > sizeof(buff)-1)
2534
- len = sizeof(buff)-1;
2535
- memcpy(buff, s, len);
2683
+ if (len > (int)(sizeof(buff)-1))
2684
+ len = (int)(sizeof(buff)-1);
2685
+ strncpy(buff, s, len);
2536
2686
  buff[len] = 0;
2537
2687
  fprintf(stderr, "\tlen=%d:\"%s\"\n", len, buff);
2538
2688
  }
@@ -2558,9 +2708,10 @@ xml_data(void *userData, const char *s, int len)
2558
2708
  archive_strappend_char(&(xar->file->pathname), '/');
2559
2709
  }
2560
2710
  xar->file->has |= HAS_PATHNAME;
2561
- if (xar->base64text)
2562
- strappend_base64(&(xar->file->pathname), s, len);
2563
- else
2711
+ if (xar->base64text) {
2712
+ strappend_base64(xar,
2713
+ &(xar->file->pathname), s, len);
2714
+ } else
2564
2715
  archive_strncat(&(xar->file->pathname), s, len);
2565
2716
  break;
2566
2717
  case FILE_LINK:
@@ -2568,26 +2719,26 @@ xml_data(void *userData, const char *s, int len)
2568
2719
  archive_strncpy(&(xar->file->symlink), s, len);
2569
2720
  break;
2570
2721
  case FILE_TYPE:
2571
- if (strncmp("file", s, len) == 0 ||
2572
- strncmp("hardlink", s, len) == 0)
2722
+ if (is_string("file", s, len) == 0 ||
2723
+ is_string("hardlink", s, len) == 0)
2573
2724
  xar->file->mode =
2574
2725
  (xar->file->mode & ~AE_IFMT) | AE_IFREG;
2575
- if (strncmp("directory", s, len) == 0)
2726
+ if (is_string("directory", s, len) == 0)
2576
2727
  xar->file->mode =
2577
2728
  (xar->file->mode & ~AE_IFMT) | AE_IFDIR;
2578
- if (strncmp("symlink", s, len) == 0)
2729
+ if (is_string("symlink", s, len) == 0)
2579
2730
  xar->file->mode =
2580
2731
  (xar->file->mode & ~AE_IFMT) | AE_IFLNK;
2581
- if (strncmp("character special", s, len) == 0)
2732
+ if (is_string("character special", s, len) == 0)
2582
2733
  xar->file->mode =
2583
2734
  (xar->file->mode & ~AE_IFMT) | AE_IFCHR;
2584
- if (strncmp("block special", s, len) == 0)
2735
+ if (is_string("block special", s, len) == 0)
2585
2736
  xar->file->mode =
2586
2737
  (xar->file->mode & ~AE_IFMT) | AE_IFBLK;
2587
- if (strncmp("socket", s, len) == 0)
2738
+ if (is_string("socket", s, len) == 0)
2588
2739
  xar->file->mode =
2589
2740
  (xar->file->mode & ~AE_IFMT) | AE_IFSOCK;
2590
- if (strncmp("fifo", s, len) == 0)
2741
+ if (is_string("fifo", s, len) == 0)
2591
2742
  xar->file->mode =
2592
2743
  (xar->file->mode & ~AE_IFMT) | AE_IFIFO;
2593
2744
  xar->file->has |= HAS_TYPE;
@@ -2612,7 +2763,7 @@ xml_data(void *userData, const char *s, int len)
2612
2763
  xar->file->has |= HAS_MODE;
2613
2764
  xar->file->mode =
2614
2765
  (xar->file->mode & AE_IFMT) |
2615
- (atol8(s, len) & ~AE_IFMT);
2766
+ ((mode_t)(atol8(s, len)) & ~AE_IFMT);
2616
2767
  break;
2617
2768
  case FILE_GROUP:
2618
2769
  xar->file->has |= HAS_GID;
@@ -2631,15 +2782,15 @@ xml_data(void *userData, const char *s, int len)
2631
2782
  xar->file->uid = atol10(s, len);
2632
2783
  break;
2633
2784
  case FILE_CTIME:
2634
- xar->file->has |= HAS_TIME;
2785
+ xar->file->has |= HAS_TIME | HAS_CTIME;
2635
2786
  xar->file->ctime = parse_time(s, len);
2636
2787
  break;
2637
2788
  case FILE_MTIME:
2638
- xar->file->has |= HAS_TIME;
2789
+ xar->file->has |= HAS_TIME | HAS_MTIME;
2639
2790
  xar->file->mtime = parse_time(s, len);
2640
2791
  break;
2641
2792
  case FILE_ATIME:
2642
- xar->file->has |= HAS_TIME;
2793
+ xar->file->has |= HAS_TIME | HAS_ATIME;
2643
2794
  xar->file->atime = parse_time(s, len);
2644
2795
  break;
2645
2796
  case FILE_DATA_LENGTH:
@@ -2909,7 +3060,8 @@ xml_parse_file_ext2(struct xar *xar, const char *name)
2909
3060
  #ifdef HAVE_LIBXML_XMLREADER_H
2910
3061
 
2911
3062
  static int
2912
- xml2_xmlattr_setup(struct xmlattr_list *list, xmlTextReaderPtr reader)
3063
+ xml2_xmlattr_setup(struct archive_read *a,
3064
+ struct xmlattr_list *list, xmlTextReaderPtr reader)
2913
3065
  {
2914
3066
  struct xmlattr *attr;
2915
3067
  int r;
@@ -2919,16 +3071,25 @@ xml2_xmlattr_setup(struct xmlattr_list *list, xmlTextReaderPtr reader)
2919
3071
  r = xmlTextReaderMoveToFirstAttribute(reader);
2920
3072
  while (r == 1) {
2921
3073
  attr = malloc(sizeof*(attr));
2922
- if (attr == NULL)
2923
- __archive_errx(1, "Out of memory");
3074
+ if (attr == NULL) {
3075
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
3076
+ return (ARCHIVE_FATAL);
3077
+ }
2924
3078
  attr->name = strdup(
2925
3079
  (const char *)xmlTextReaderConstLocalName(reader));
2926
- if (attr->name == NULL)
2927
- __archive_errx(1, "Out of memory");
3080
+ if (attr->name == NULL) {
3081
+ free(attr);
3082
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
3083
+ return (ARCHIVE_FATAL);
3084
+ }
2928
3085
  attr->value = strdup(
2929
3086
  (const char *)xmlTextReaderConstValue(reader));
2930
- if (attr->value == NULL)
2931
- __archive_errx(1, "Out of memory");
3087
+ if (attr->value == NULL) {
3088
+ free(attr->name);
3089
+ free(attr);
3090
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
3091
+ return (ARCHIVE_FATAL);
3092
+ }
2932
3093
  attr->next = NULL;
2933
3094
  *list->last = attr;
2934
3095
  list->last = &(attr->next);
@@ -2944,7 +3105,7 @@ xml2_read_cb(void *context, char *buffer, int len)
2944
3105
  struct xar *xar;
2945
3106
  const void *d;
2946
3107
  size_t outbytes;
2947
- size_t used;
3108
+ size_t used = 0;
2948
3109
  int r;
2949
3110
 
2950
3111
  a = (struct archive_read *)context;
@@ -3020,13 +3181,14 @@ xml2_read_toc(struct archive_read *a)
3020
3181
  switch (type) {
3021
3182
  case XML_READER_TYPE_ELEMENT:
3022
3183
  empty = xmlTextReaderIsEmptyElement(reader);
3023
- r = xml2_xmlattr_setup(&list, reader);
3024
- if (r == 0) {
3025
- xml_start(a, name, &list);
3026
- xmlattr_cleanup(&list);
3027
- if (empty)
3028
- xml_end(a, name);
3029
- }
3184
+ r = xml2_xmlattr_setup(a, &list, reader);
3185
+ if (r == ARCHIVE_OK)
3186
+ r = xml_start(a, name, &list);
3187
+ xmlattr_cleanup(&list);
3188
+ if (r != ARCHIVE_OK)
3189
+ return (r);
3190
+ if (empty)
3191
+ xml_end(a, name);
3030
3192
  break;
3031
3193
  case XML_READER_TYPE_END_ELEMENT:
3032
3194
  xml_end(a, name);
@@ -3050,52 +3212,67 @@ xml2_read_toc(struct archive_read *a)
3050
3212
 
3051
3213
  #elif defined(HAVE_BSDXML_H) || defined(HAVE_EXPAT_H)
3052
3214
 
3053
- static void
3054
- expat_xmlattr_setup(struct xmlattr_list *list, const XML_Char **atts)
3215
+ static int
3216
+ expat_xmlattr_setup(struct archive_read *a,
3217
+ struct xmlattr_list *list, const XML_Char **atts)
3055
3218
  {
3056
3219
  struct xmlattr *attr;
3220
+ char *name, *value;
3057
3221
 
3058
3222
  list->first = NULL;
3059
3223
  list->last = &(list->first);
3060
3224
  if (atts == NULL)
3061
- return;
3225
+ return (ARCHIVE_OK);
3062
3226
  while (atts[0] != NULL && atts[1] != NULL) {
3063
3227
  attr = malloc(sizeof*(attr));
3064
- if (attr == NULL)
3065
- __archive_errx(1, "Out of memory");
3066
- attr->name = strdup(atts[0]);
3067
- if (attr->name == NULL)
3068
- __archive_errx(1, "Out of memory");
3069
- attr->value = strdup(atts[1]);
3070
- if (attr->value == NULL)
3071
- __archive_errx(1, "Out of memory");
3228
+ name = strdup(atts[0]);
3229
+ value = strdup(atts[1]);
3230
+ if (attr == NULL || name == NULL || value == NULL) {
3231
+ archive_set_error(&a->archive, ENOMEM, "Out of memory");
3232
+ free(attr);
3233
+ free(name);
3234
+ free(value);
3235
+ return (ARCHIVE_FATAL);
3236
+ }
3237
+ attr->name = name;
3238
+ attr->value = value;
3072
3239
  attr->next = NULL;
3073
3240
  *list->last = attr;
3074
3241
  list->last = &(attr->next);
3075
3242
  atts += 2;
3076
3243
  }
3244
+ return (ARCHIVE_OK);
3077
3245
  }
3078
3246
 
3079
3247
  static void
3080
3248
  expat_start_cb(void *userData, const XML_Char *name, const XML_Char **atts)
3081
3249
  {
3250
+ struct expat_userData *ud = (struct expat_userData *)userData;
3251
+ struct archive_read *a = ud->archive;
3082
3252
  struct xmlattr_list list;
3253
+ int r;
3083
3254
 
3084
- expat_xmlattr_setup(&list, atts);
3085
- xml_start(userData, (const char *)name, &list);
3255
+ r = expat_xmlattr_setup(a, &list, atts);
3256
+ if (r == ARCHIVE_OK)
3257
+ r = xml_start(a, (const char *)name, &list);
3086
3258
  xmlattr_cleanup(&list);
3259
+ ud->state = r;
3087
3260
  }
3088
3261
 
3089
3262
  static void
3090
3263
  expat_end_cb(void *userData, const XML_Char *name)
3091
3264
  {
3092
- xml_end(userData, (const char *)name);
3265
+ struct expat_userData *ud = (struct expat_userData *)userData;
3266
+
3267
+ xml_end(ud->archive, (const char *)name);
3093
3268
  }
3094
3269
 
3095
3270
  static void
3096
3271
  expat_data_cb(void *userData, const XML_Char *s, int len)
3097
3272
  {
3098
- xml_data(userData, s, len);
3273
+ struct expat_userData *ud = (struct expat_userData *)userData;
3274
+
3275
+ xml_data(ud->archive, s, len);
3099
3276
  }
3100
3277
 
3101
3278
  static int
@@ -3103,6 +3280,10 @@ expat_read_toc(struct archive_read *a)
3103
3280
  {
3104
3281
  struct xar *xar;
3105
3282
  XML_Parser parser;
3283
+ struct expat_userData ud;
3284
+
3285
+ ud.state = ARCHIVE_OK;
3286
+ ud.archive = a;
3106
3287
 
3107
3288
  xar = (struct xar *)(a->format->data);
3108
3289
 
@@ -3113,12 +3294,12 @@ expat_read_toc(struct archive_read *a)
3113
3294
  "Couldn't allocate memory for xml parser");
3114
3295
  return (ARCHIVE_FATAL);
3115
3296
  }
3116
- XML_SetUserData(parser, a);
3297
+ XML_SetUserData(parser, &ud);
3117
3298
  XML_SetElementHandler(parser, expat_start_cb, expat_end_cb);
3118
3299
  XML_SetCharacterDataHandler(parser, expat_data_cb);
3119
3300
  xar->xmlsts = INIT;
3120
3301
 
3121
- while (xar->toc_remaining) {
3302
+ while (xar->toc_remaining && ud.state == ARCHIVE_OK) {
3122
3303
  enum XML_Status xr;
3123
3304
  const void *d;
3124
3305
  size_t outbytes;
@@ -3129,13 +3310,13 @@ expat_read_toc(struct archive_read *a)
3129
3310
  r = rd_contents(a, &d, &outbytes, &used, xar->toc_remaining);
3130
3311
  if (r != ARCHIVE_OK)
3131
3312
  return (r);
3132
- __archive_read_consume(a, used);
3133
3313
  xar->toc_remaining -= used;
3134
3314
  xar->offset += used;
3135
3315
  xar->toc_total += outbytes;
3136
3316
  PRINT_TOC(d, outbytes);
3137
3317
 
3138
3318
  xr = XML_Parse(parser, d, outbytes, xar->toc_remaining == 0);
3319
+ __archive_read_consume(a, used);
3139
3320
  if (xr == XML_STATUS_ERROR) {
3140
3321
  XML_ParserFree(parser);
3141
3322
  archive_set_error(&a->archive, ARCHIVE_ERRNO_MISC,
@@ -3144,7 +3325,7 @@ expat_read_toc(struct archive_read *a)
3144
3325
  }
3145
3326
  }
3146
3327
  XML_ParserFree(parser);
3147
- return (ARCHIVE_OK);
3328
+ return (ud.state);
3148
3329
  }
3149
3330
  #endif /* defined(HAVE_BSDXML_H) || defined(HAVE_EXPAT_H) */
3150
3331