minitar 1.0.2 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +326 -0
  3. data/CODE_OF_CONDUCT.md +167 -0
  4. data/CONTRIBUTING.md +312 -0
  5. data/CONTRIBUTORS.md +27 -0
  6. data/LICENCE.md +42 -0
  7. data/Manifest.txt +31 -8
  8. data/README.md +82 -0
  9. data/Rakefile +74 -20
  10. data/SECURITY.md +54 -0
  11. data/lib/minitar/input.rb +242 -189
  12. data/lib/minitar/output.rb +72 -64
  13. data/lib/minitar/pax_header.rb +111 -0
  14. data/lib/minitar/posix_header.rb +276 -239
  15. data/lib/minitar/reader.rb +226 -231
  16. data/lib/minitar/version.rb +5 -0
  17. data/lib/minitar/writer.rb +246 -299
  18. data/lib/minitar.rb +134 -115
  19. data/licenses/bsdl.txt +20 -0
  20. data/licenses/dco.txt +34 -0
  21. data/licenses/ruby.txt +52 -0
  22. data/test/fixtures/issue_46.tar.gz +0 -0
  23. data/test/fixtures/issue_62.tar.gz +0 -0
  24. data/test/fixtures/tar_input.tgz +0 -0
  25. data/test/fixtures/test_input_non_strict_octal.tgz +0 -0
  26. data/test/fixtures/test_input_relative.tgz +0 -0
  27. data/test/fixtures/test_input_space_octal.tgz +0 -0
  28. data/test/fixtures/test_minitar.tar.gz +0 -0
  29. data/test/minitest_helper.rb +12 -1
  30. data/test/support/minitar_test_helpers/fixtures.rb +38 -0
  31. data/test/support/minitar_test_helpers/header.rb +130 -0
  32. data/test/support/minitar_test_helpers/tarball.rb +324 -0
  33. data/test/support/minitar_test_helpers.rb +36 -0
  34. data/test/test_filename_boundary_conditions.rb +74 -0
  35. data/test/test_gnu_tar_compatibility.rb +92 -0
  36. data/test/test_integration_pack_unpack_cycle.rb +38 -0
  37. data/test/test_issue_46.rb +5 -23
  38. data/test/test_issue_62.rb +50 -0
  39. data/test/test_minitar.rb +168 -39
  40. data/test/test_path_normalization.rb +170 -0
  41. data/test/test_pax_header.rb +104 -0
  42. data/test/test_pax_support.rb +66 -0
  43. data/test/test_tar_header.rb +289 -75
  44. data/test/test_tar_input.rb +14 -61
  45. data/test/test_tar_output.rb +7 -9
  46. data/test/test_tar_reader.rb +17 -18
  47. data/test/test_tar_writer.rb +105 -126
  48. data/test/test_windows_extraction.rb +121 -0
  49. metadata +108 -95
  50. data/Code-of-Conduct.md +0 -128
  51. data/Contributing.md +0 -94
  52. data/History.md +0 -236
  53. data/Licence.md +0 -15
  54. data/README.rdoc +0 -92
  55. data/docs/bsdl.txt +0 -19
  56. data/docs/ruby.txt +0 -56
  57. data/test/support/tar_test_helpers.rb +0 -134
data/SECURITY.md ADDED
@@ -0,0 +1,54 @@
1
+ # Minitar Security Policy
2
+
3
+ Minitar aims to be secure by default for the data _inside_ of a tar file.
4
+
5
+ ## LLM-Generated Security Report Policy
6
+
7
+ Absolutely no security reports will be accepted that have been generated
8
+ solely by LLM agents. There must be a human that confirms the issue.
9
+
10
+ ## Supported Versions
11
+
12
+ Security reports are accepted only for the most recent major release.
13
+
14
+ ## Reporting a Vulnerability
15
+
16
+ Report vulnerabilities via the [Tidelift security contact][tidelift]. Tidelift
17
+ will coordinate the fix and disclosure.
18
+
19
+ Alternatively, create a [private vulnerability report][advisory] with GitHub.
20
+
21
+ ## Exclusions
22
+
23
+ There are several classes of potential security issues that will **not** be
24
+ accepted for Minitar, because any issues arising from these are a matter of
25
+ the library being used incorrectly.
26
+
27
+ - [CWE-073](https://cwe.mitre.org/data/definitions/73.html)
28
+ - [CWE-078](https://cwe.mitre.org/data/definitions/78.html)
29
+ - [CWE-088](https://cwe.mitre.org/data/definitions/88.html)
30
+
31
+ Minitar does _not_ perform validation or sanitization of path names provided
32
+ to the convenience classes `Minitar::Output` and `Minitar::Input`, which use
33
+ `Kernel.open` for their underlying implementations when not given an IO-like
34
+ object.
35
+
36
+ Improper use of these convenience classes with arbitrary input filenames may
37
+ leave your your software to the same class of vulnerability as reported for
38
+ Net::FTP ([CVE-2017-17405][CVE-2017-17405]). If the input filename argument
39
+ starts with the pipe character (`|`), the command following the pipe character
40
+ is executed.
41
+
42
+ Additionally, the use of the `open-uri` library (which extends `Kernel.open`
43
+ with transparent implementations for `Net::HTTP`, `Net::HTTPS`, and
44
+ `Net::FTP`), there are other possible vulnerabilities when accepting arbitrary
45
+ input, as [detailed][openuri] by Egor Homakov.
46
+
47
+ These security vulnerabilities may be avoided, even with the `Minitar::Output`
48
+ and `Minitar::Input` convenience classes, by providing IO-like objects instead
49
+ of pathname-like objects as the source or destination of these classes.
50
+
51
+ [CVE-2017-17405]: https://nvd.nist.gov/vuln/detail/CVE-2017-17405
52
+ [advisory]: https://github.com/halostatue/diff-lcs/security/advisories/new
53
+ [openuri]: https://sakurity.com/blog/2015/02/28/openuri.html
54
+ [tidelift]: https://tidelift.com/security
data/lib/minitar/input.rb CHANGED
@@ -1,239 +1,292 @@
1
- require "minitar/reader"
2
-
3
- class Minitar
4
- # Wraps a Minitar::Reader with convenience methods and wrapped
5
- # stream management; Input only works with data streams that can be rewound.
6
- class Input
7
- include Enumerable
8
-
9
- # With no associated block, +Input.open+ is a synonym for +Input.new+. If
10
- # the optional code block is given, it will be given the new Input as an
11
- # argument and the Input object will automatically be closed when the block
12
- # terminates (this also closes the wrapped stream object). In this
13
- # instance, +Input.open+ returns the value of the block.
14
- #
15
- # call-seq:
16
- # Minitar::Input.open(io) -> input
17
- # Minitar::Input.open(io) { |input| block } -> obj
18
- def self.open(input)
19
- stream = new(input)
20
-
21
- if block_given?
22
- # This exception context must remain, otherwise the stream closes on
23
- # open even if a block is not given.
24
- begin
25
- yield stream
26
- ensure
27
- stream.close
28
- end
29
- else
30
- stream
1
+ # frozen_string_literal: true
2
+
3
+ # This wraps a Minitar::Reader with convenience methods and wrapped stream management;
4
+ # Input only works with data streams that can be rewound.
5
+ #
6
+ # ### Security Notice
7
+ #
8
+ # Constructing a Minitar::Input will use Kernel.open if the provided input is not
9
+ # a readable stream object. Using an untrusted value for input may allow a malicious
10
+ # user to execute arbitrary system commands. It is the **caller's responsibility** to
11
+ # ensure that the input value is safe.
12
+ #
13
+ # * [CWE-073](https://cwe.mitre.org/data/definitions/73.html)
14
+ # * [CWE-078](https://cwe.mitre.org/data/definitions/78.html)
15
+ # * [CWE-088](https://cwe.mitre.org/data/definitions/88.html)
16
+ #
17
+ # This notice applies to Minitar::Input.open, Minitar::Input.each_entry, and
18
+ # Minitar::Input.new.
19
+ class Minitar::Input
20
+ include Enumerable
21
+
22
+ # With no associated block, `Input.open` is a synonym for `Input.new`.
23
+ #
24
+ # If a block is given, the new Input will be yielded to the block as an argument and
25
+ # the Input object will automatically be closed when the block terminates (this also
26
+ # closes the wrapped stream object). The return value will be the value of the block.
27
+ #
28
+ # :call-seq:
29
+ # Minitar::Input.open(io) -> input
30
+ # Minitar::Input.open(io) { |input| block } -> obj
31
+ def self.open(input)
32
+ stream = new(input)
33
+
34
+ if block_given?
35
+ # This exception context must remain, otherwise the stream closes on open even if
36
+ # a block is not given.
37
+ begin
38
+ yield stream
39
+ ensure
40
+ stream.close
31
41
  end
42
+ else
43
+ stream
32
44
  end
45
+ end
33
46
 
34
- # Iterates over each entry in the provided input. This wraps the common
35
- # pattern of:
36
- #
37
- # Minitar::Input.open(io) do |i|
38
- # inp.each do |entry|
39
- # # ...
40
- # end
41
- # end
42
- #
43
- # If a block is not provided, an enumerator will be created with the same
44
- # behaviour.
45
- #
46
- # call-seq:
47
- # Minitar::Input.each_entry(io) -> enumerator
48
- # Minitar::Input.each_entry(io) { |entry| block } -> obj
49
- def self.each_entry(input)
50
- return to_enum(__method__, input) unless block_given?
51
-
52
- Input.open(input) do |stream|
53
- stream.each do |entry|
54
- yield entry
55
- end
47
+ # Iterates over each entry in the provided input. This wraps the common pattern of:
48
+ #
49
+ # ```ruby
50
+ # Minitar::Input.open(io) do |i|
51
+ # inp.each do |entry|
52
+ # # ...
53
+ # end
54
+ # end
55
+ # ```
56
+ #
57
+ # If a block is not provided, an enumerator will be created with the same behaviour.
58
+ #
59
+ # :call-seq:
60
+ # Minitar::Input.each_entry(io) -> enumerator
61
+ # Minitar::Input.each_entry(io) { |entry| block } -> obj
62
+ def self.each_entry(input)
63
+ return to_enum(__method__, input) unless block_given?
64
+
65
+ Input.open(input) do |stream|
66
+ stream.each do |entry|
67
+ yield entry
56
68
  end
57
69
  end
70
+ end
58
71
 
59
- # Creates a new Input object. If +input+ is a stream object that responds
60
- # to #read, then it will simply be wrapped. Otherwise, one will be created
61
- # and opened using Kernel#open. When Input#close is called, the stream
62
- # object wrapped will be closed.
63
- #
64
- # An exception will be raised if the stream that is wrapped does not
65
- # support rewinding.
66
- #
67
- # call-seq:
68
- # Minitar::Input.new(io) -> input
69
- # Minitar::Input.new(path) -> input
70
- def initialize(input)
71
- @io = if input.respond_to?(:read)
72
+ # Creates a new Input object. If `input` is a stream object that responds to #read,
73
+ # then it will simply be wrapped. Otherwise, one will be created and opened using
74
+ # Kernel.open. When Input#close is called, the stream object wrapped will be closed.
75
+ #
76
+ # An exception will be raised if the stream that is wrapped does not support
77
+ # rewinding.
78
+ #
79
+ # :call-seq:
80
+ # Minitar::Input.new(io) -> input
81
+ # Minitar::Input.new(path) -> input
82
+ def initialize(input)
83
+ @io =
84
+ if input.respond_to?(:read)
72
85
  input
73
86
  else
74
87
  ::Kernel.open(input, "rb")
75
88
  end
76
89
 
77
- unless Minitar.seekable?(@io, :rewind)
78
- raise Minitar::NonSeekableStream
79
- end
90
+ raise Minitar::NonSeekableStream unless Minitar.seekable?(@io, :rewind)
80
91
 
81
- @tar = Reader.new(@io)
82
- end
92
+ @tar = Minitar::Reader.new(@io)
93
+ end
83
94
 
84
- # When provided a block, iterates through each entry in the archive. When
85
- # finished, rewinds to the beginning of the stream.
86
- #
87
- # If not provided a block, creates an enumerator with the same semantics.
88
- def each_entry
89
- return to_enum unless block_given?
95
+ # When provided a block, iterates through each entry in the archive. When finished,
96
+ # rewinds to the beginning of the stream.
97
+ #
98
+ # If not provided a block, creates an enumerator with the same semantics.
99
+ def each_entry
100
+ return to_enum unless block_given?
90
101
 
91
- @tar.each do |entry|
92
- yield entry
93
- end
94
- ensure
95
- @tar.rewind
102
+ @tar.each do |entry|
103
+ yield entry
96
104
  end
97
- alias_method :each, :each_entry
98
-
99
- # Extracts the current +entry+ to +destdir+. If a block is provided, it
100
- # yields an +action+ Symbol, the full name of the file being extracted
101
- # (+name+), and a Hash of statistical information (+stats+).
102
- #
103
- # The +action+ will be one of:
104
- # <tt>:dir</tt>:: The +entry+ is a directory.
105
- # <tt>:file_start</tt>:: The +entry+ is a file; the extract of the
106
- # file is just beginning.
107
- # <tt>:file_progress</tt>:: Yielded every 4096 bytes during the extract
108
- # of the +entry+.
109
- # <tt>:file_done</tt>:: Yielded when the +entry+ is completed.
110
- #
111
- # The +stats+ hash contains the following keys:
112
- # <tt>:current</tt>:: The current total number of bytes read in the
113
- # +entry+.
114
- # <tt>:currinc</tt>:: The current number of bytes read in this read
115
- # cycle.
116
- # <tt>:entry</tt>:: The entry being extracted; this is a
117
- # Reader::EntryStream, with all methods thereof.
118
- def extract_entry(destdir, entry, options = {}, &) # :yields action, name, stats:
119
- stats = {
120
- current: 0,
121
- currinc: 0,
122
- entry: entry
123
- }
124
-
125
- # extract_entry is not vulnerable to prefix '/' vulnerabilities, but it
126
- # is vulnerable to relative path directories. This code will break this
127
- # vulnerability. For this version, we are breaking relative paths HARD by
128
- # throwing an exception.
129
- #
130
- # Future versions may permit relative paths as long as the file does not
131
- # leave +destdir+.
132
- #
133
- # However, squeeze consecutive '/' characters together.
134
- full_name = entry.full_name.squeeze("/")
135
-
136
- if /\.{2}(?:\/|\z)/.match?(full_name)
137
- raise SecureRelativePathError, "Path contains '..'"
138
- end
105
+ ensure
106
+ @tar.rewind
107
+ end
108
+ alias_method :each, :each_entry
109
+
110
+ # Extracts the current `entry` to `destdir`. If a block is provided, it yields an
111
+ # `action` Symbol, the full name of the file being extracted (`name`), and a Hash of
112
+ # statistical information (`stats`).
113
+ #
114
+ # The `action` will be one of:
115
+ #
116
+ # - `:dir`: The `entry` is a directory.
117
+ # - `:file_start`: The `entry` is a file; the extract of the file is just beginning.
118
+ # - `:file_progress`: Yielded every 4096 bytes during the extract of the `entry`.
119
+ # - `:file_done`: Yielded when the `entry` is completed.
120
+ #
121
+ # The `stats` hash may contain the following keys:
122
+ #
123
+ # - `:current`: The current total number of bytes read in the `entry`.
124
+ # - `:currinc`: The current number of bytes read in this read cycle.
125
+ # - `:entry`: The entry being extracted; this is a Minitar::Reader::EntryStream.
126
+ def extract_entry(destdir, entry, options = {}, &) # :yields: action, name, stats
127
+ stats = {
128
+ current: 0,
129
+ currinc: 0,
130
+ entry: entry
131
+ }
132
+
133
+ # extract_entry is not vulnerable to prefix '/' vulnerabilities; check and reject
134
+ # relative path directories on both Windows and Unix-like systems. This is a hard
135
+ # rejection by throwing exceptions. Future versions may permit relative paths as long
136
+ # as the file does not leave `destdir`.
137
+ full_name = normalize_entry_name(entry.full_name)
138
+ check_relative_path!(full_name)
139
+
140
+ if entry.directory?
141
+ extract_directory(destdir, full_name, entry, stats, options, &)
142
+ else # it's a file
143
+ extract_file(destdir, full_name, entry, stats, options, &)
144
+ end
145
+ end
139
146
 
140
- if entry.directory?
141
- extract_directory(destdir, full_name, entry, stats, options, &)
142
- else # it's a file
143
- extract_file(destdir, full_name, entry, stats, options, &)
144
- end
147
+ # Returns false if the wrapped data stream is open.
148
+ def closed? = @io.closed?
149
+
150
+ # Returns the Minitar::Reader object for direct access.
151
+ attr_reader :tar
152
+
153
+ # Closes both the Minitar::Reader object and the wrapped data stream.
154
+ def close
155
+ @io.close
156
+ @tar.close
157
+ end
158
+
159
+ private
160
+
161
+ # Normalizes an entry name as the filesystem will interpret it.
162
+ #
163
+ # On Unix-like systems (`File::ALT_SEPARATOR.nil?`), consecutive `/` are always
164
+ # squeezed to a single `/`.
165
+ #
166
+ # On Windows, the normalization _and check_ are more extensive:
167
+ #
168
+ # - All `\` are normalized to `/` and squeezed.
169
+ # - Drive designators `[A-Z]:` are rejected with UnsafeFileNameError.
170
+ # - Files with `:` are rejected with UnsafeFileNameError (NTFS alternate data streams
171
+ # are removed with `File.basename`, causing file aliasing).
172
+ # - Each path component is examined to see if, aside from `..` and `.`, it contains
173
+ # a trailing dot or space. These are rejected with UnsafeFileNameError due to file
174
+ # aliasing.
175
+ def normalize_entry_name(name, alt_separator = File::ALT_SEPARATOR)
176
+ return name.squeeze("/") unless alt_separator
177
+
178
+ name = name.tr(alt_separator, "/").squeeze("/")
179
+
180
+ # A drive designator looks like a directory (`C:` is a drive, not a stream name), so
181
+ # it is called out separately from the general `:` check below.
182
+ if name.match?(/\A[A-Za-z]:/)
183
+ raise Minitar::UnsafeFileNameError, "Path begins with a drive designator"
145
184
  end
146
185
 
147
- # Returns false if the wrapped data stream is open.
148
- def closed?
149
- @io.closed?
186
+ if name.include?(":")
187
+ raise Minitar::UnsafeFileNameError, "Path contains ':'"
150
188
  end
151
189
 
152
- # Returns the Reader object for direct access.
153
- attr_reader :tar
190
+ # Win32 trims trailing dots and spaces from path components, so `...`, `.. `, and
191
+ # `dirname..` alias a different name (often the containing directory) than the
192
+ # literal name in the archive. `.` and `..` are left alone: `.` is harmless and `..`
193
+ # is handled by #check_relative_path!.
194
+ name.split("/").each do |part|
195
+ next if part == "." || part == ".."
154
196
 
155
- # Closes both the Reader object and the wrapped data stream.
156
- def close
157
- @io.close
158
- @tar.close
197
+ if part.match?(/[ .]\z/)
198
+ raise Minitar::UnsafeFileNameError, "Path component ends with '.' or ' '"
199
+ end
159
200
  end
160
201
 
161
- private
202
+ name
203
+ end
162
204
 
163
- def fsync_dir(dirname)
164
- # make sure this hits the disc
165
- dir = IO.open(dirname, "rb")
166
- dir.fsync
167
- rescue # ignore IOError if it's an unpatched (old) Ruby
168
- nil
169
- ensure
170
- dir&.close rescue nil # standard:disable Style/RescueModifier
205
+ # Raises Minitar::SecureRelativePathError if any path component of the (normalized)
206
+ # `name` is `..`.
207
+ def check_relative_path!(name)
208
+ if %r{(?:\A|/)\.\.(?:/|\z)}.match?(name)
209
+ raise Minitar::SecureRelativePathError, "Path contains '..'"
171
210
  end
211
+ end
172
212
 
173
- def extract_directory(destdir, full_name, entry, stats, options)
174
- dest = File.join(destdir, full_name)
213
+ def fsync_dir(dirname)
214
+ # make sure this hits the disc
215
+ dir = IO.open(dirname, "rb")
216
+ dir.fsync
217
+ rescue # ignore IOError if it's an unpatched (old) Ruby
218
+ nil
219
+ ensure
220
+ dir&.close rescue nil # standard:disable Style/RescueModifier
221
+ end
175
222
 
176
- yield :dir, full_name, stats if block_given?
223
+ def extract_directory(destdir, full_name, entry, stats, options)
224
+ dest = File.join(destdir, full_name)
177
225
 
178
- if Minitar.dir?(dest)
179
- begin
180
- FileUtils.chmod(entry.mode, dest)
181
- rescue
182
- nil
183
- end
184
- else
185
- File.unlink(dest.chomp("/")) if File.symlink?(dest.chomp("/"))
226
+ yield :dir, full_name, stats if block_given?
186
227
 
187
- FileUtils.mkdir_p(dest, mode: entry.mode)
228
+ if Minitar.dir?(dest)
229
+ begin
188
230
  FileUtils.chmod(entry.mode, dest)
231
+ rescue
232
+ nil
189
233
  end
234
+ else
235
+ File.unlink(dest.chomp("/")) if File.symlink?(dest.chomp("/"))
190
236
 
191
- if options.fetch(:fsync, true)
192
- fsync_dir(dest)
193
- fsync_dir(File.join(dest, ".."))
194
- end
237
+ FileUtils.mkdir_p(dest, mode: entry.mode)
238
+ FileUtils.chmod(entry.mode, dest)
195
239
  end
196
240
 
197
- def extract_file(destdir, full_name, entry, stats, options)
198
- destdir = File.join(destdir, File.dirname(full_name))
199
- FileUtils.mkdir_p(destdir, mode: 0o755)
241
+ if options.fetch(:fsync, true)
242
+ fsync_dir(dest)
243
+ fsync_dir(File.join(dest, ".."))
244
+ end
245
+ end
200
246
 
201
- destfile = File.join(destdir, File.basename(full_name))
247
+ def extract_file(destdir, full_name, entry, stats, options)
248
+ destdir = File.join(destdir, File.dirname(full_name))
249
+ FileUtils.mkdir_p(destdir, mode: 0o755)
202
250
 
203
- File.unlink(destfile) if File.symlink?(destfile)
251
+ destfile = File.join(destdir, File.basename(full_name))
204
252
 
205
- # Errno::ENOENT
206
- FileUtils.chmod(0o600, destfile) rescue nil # standard:disable Style/RescueModifier
253
+ File.unlink(destfile) if File.symlink?(destfile)
207
254
 
208
- yield :file_start, full_name, stats if block_given?
255
+ # Errno::ENOENT
256
+ begin
257
+ FileUtils.chmod(0o600, destfile)
258
+ rescue
259
+ nil
260
+ end
209
261
 
210
- File.open(destfile, "wb", entry.mode) do |os|
211
- loop do
212
- data = entry.read(4096)
213
- break unless data
262
+ yield :file_start, full_name, stats if block_given?
214
263
 
215
- stats[:currinc] = os.write(data)
216
- stats[:current] += stats[:currinc]
264
+ File.open(destfile, "wb", entry.mode) do |os|
265
+ loop do
266
+ data = entry.read(4096)
267
+ break unless data
217
268
 
218
- yield :file_progress, full_name, stats if block_given?
219
- end
269
+ stats[:currinc] = os.write(data)
270
+ stats[:current] += stats[:currinc]
220
271
 
221
- if options.fetch(:fsync, true)
222
- yield :file_fsync, full_name, stats if block_given?
223
- os.fsync
224
- end
272
+ yield :file_progress, full_name, stats if block_given?
225
273
  end
226
274
 
227
- FileUtils.chmod(entry.mode, destfile)
228
-
229
275
  if options.fetch(:fsync, true)
230
- yield :dir_fsync, full_name, stats if block_given?
231
-
232
- fsync_dir(File.dirname(destfile))
233
- fsync_dir(File.join(File.dirname(destfile), ".."))
276
+ yield :file_fsync, full_name, stats if block_given?
277
+ os.fsync
234
278
  end
279
+ end
280
+
281
+ FileUtils.chmod(entry.mode, destfile)
235
282
 
236
- yield :file_done, full_name, stats if block_given?
283
+ if options.fetch(:fsync, true)
284
+ yield :dir_fsync, full_name, stats if block_given?
285
+
286
+ fsync_dir(File.dirname(destfile))
287
+ fsync_dir(File.join(File.dirname(destfile), ".."))
237
288
  end
289
+
290
+ yield :file_done, full_name, stats if block_given?
238
291
  end
239
292
  end