ziperu 0.4.0-aarch64-linux-gnu → 0.4.1-aarch64-linux-gnu

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4d12c4f163600c9ead3a6d8178ce69ba6da1573169fa822aeae5ac5264d9020a
4
- data.tar.gz: 752d8809635efc41ecc3ca2866a0e1ac81b237af45bd2cbb806e8cca85ce5281
3
+ metadata.gz: f4eba36fe96c327920c027c4b0ac1d615ff6009003dc8aea0e38480a1481f428
4
+ data.tar.gz: 4ed1508faa5c9cfca26867ad83a20fbb4160cfc09ad523595ec1085abc8ab131
5
5
  SHA512:
6
- metadata.gz: bcf4068019a51863facc08578e38ba8f251db456c9ff91e2111bd346ec13c004b71421f66ed1b50a270eeb42ee2294e29af4099b2b40a501aa072e01ecf26fb0
7
- data.tar.gz: 2bc07a490f3df284595e62bf07775fa81e873316907fd6d630803a5dd36cba18e565002b062b938e0eb02b8da0b1cd78ea938aa648e5a978ac3b8c04199c2911
6
+ metadata.gz: 52b510426e0e4d984f0d35fa280566e479801362ef3abbbf0ab93088d171fceb2a664172e855794ab3e52d3733ef9b34a9070c7e1cbefa9125a6bfecf7b0fc25
7
+ data.tar.gz: 373f2ea25a029068d7ee41f6f73ec316e1264d413bc2c3dd1e315ba5dd1256ff691778a5954073553eaa342f79f43887527d088527247e5449774b822e434684
data/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.1 (2026-12-06)
4
+
5
+ Fixed:
6
+
7
+ - An archive opened with `write: false` could still be rewritten: a
8
+ setter on one of its entries (`entry.comment = ...`, `name=`, `time=`
9
+ and the rest) marked it changed, and closing the archive wrote it out.
10
+ Those setters now raise `Ziperu::Error` at the call, and a commit of a
11
+ read-only archive writes nothing whatever was changed.
12
+ - `OutputStream#rollback_entry`, refused because the entry's first bytes
13
+ had already gone out on a stream that cannot seek, dropped what was
14
+ still buffered for that entry, so the archive came out with the entry
15
+ short. The data is kept.
16
+ - `File#rename` to a name the entry cannot take (absolute, too long)
17
+ raised only after the entry had been removed, and the next commit
18
+ wrote the archive without it. The name is checked first.
19
+ - An append in place that failed while the archive was being finished
20
+ (an archive comment too long, a disk that filled, a read-back that
21
+ failed) left the archive without a central directory: the saved one
22
+ was let go before the last steps. It is now kept until they are done
23
+ and put back if any fails, and `OutputStream.open(append: true)`
24
+ abandons the append when closing raises.
25
+ - `OutputStream.estimated_size` with `write_zip64_support: :always`
26
+ came out short by the zip64 fields every entry is then written with.
27
+ The estimator and the writer now ask the same question.
28
+ - Committing an append re-read the appended entries in time that grew
29
+ with the square of the archive: 1,000 entries appended to an archive
30
+ of 60,000 took 2.5 s to commit and now take 0.35 s.
31
+ - A file whose name was within about twenty bytes of the 255 a name may
32
+ have could be extracted but not replaced: the replacement is written
33
+ beside it under a longer name, which the file system refused (`File
34
+ name too long`). That stopped a tar archive listing such a name twice,
35
+ an extraction with `on_exists: :overwrite` over such a file, and
36
+ `Ziperu::Tar.create` to an archive so named. The name written beside
37
+ is now cut to fit. Found by the nightly tar fuzzer.
38
+
3
39
  ## 0.4.0 (2026-11-21)
4
40
 
5
41
  Added:
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -26,16 +26,23 @@ module Ziperu
26
26
  dirty_fields << field unless dirty_fields.include?(field)
27
27
  end
28
28
 
29
+ # Called before a setter changes anything; raises to refuse the edit.
30
+ def before_edit(_field); end
31
+
29
32
  module ClassMethods # :nodoc:
30
33
  def mark_dirty(*symbols) # :nodoc:
31
- # Move the original method and call it after we've set the dirty flag.
34
+ # Move the original method, and set the dirty flag once it has
35
+ # taken the value: a setter that refuses one changes nothing, and
36
+ # must not leave the object looking edited.
32
37
  symbols.each do |symbol|
33
38
  orig_name = "orig_#{symbol}"
34
39
  alias_method orig_name, symbol
35
40
 
36
41
  define_method(symbol) do |param|
42
+ before_edit(symbol)
43
+ result = send(orig_name, param)
37
44
  mark_dirty!(symbol)
38
- send(orig_name, param)
45
+ result
39
46
  end
40
47
  end
41
48
  end
data/lib/ziperu/entry.rb CHANGED
@@ -181,6 +181,13 @@ module Ziperu
181
181
 
182
182
  # Validated here rather than when the archive is written, so a bad
183
183
  # value fails at the call site (rubyzip writes a corrupt header).
184
+ # Raises unless an entry may be called `name`. `File#rename` asks
185
+ # before it moves anything, of whatever kind of entry it holds.
186
+ def self.check_name(name) # :nodoc:
187
+ raise EntryNameError, name if name.start_with?('/')
188
+ raise EntryNameError if name.length > MAX_FIELD_LENGTH
189
+ end
190
+
184
191
  def name=(name)
185
192
  name = name.to_s
186
193
  check_name(name)
@@ -200,6 +207,19 @@ module Ziperu
200
207
  :fstype=, :gp_flags=, :name=, :size=,
201
208
  :unix_gid=, :unix_perms=, :unix_uid=
202
209
 
210
+ # Every setter that edits the entry asks here first, so this is where
211
+ # an entry of an archive opened with `write: false` refuses.
212
+ def before_edit(_field = nil) # :nodoc:
213
+ check_editable!
214
+ end
215
+
216
+ # Raises for an entry of an archive opened read-only.
217
+ def check_editable! # :nodoc:
218
+ return unless @zipfile.kind_of?(::Ziperu::File) && @zipfile.read_only?
219
+
220
+ raise Error, "#{@zipfile.name} was opened read-only (write: false)"
221
+ end
222
+
203
223
  # Create a new Ziperu::Entry.
204
224
  def initialize(
205
225
  zipfile = '', name = '', *legacy,
@@ -356,10 +376,11 @@ module Ziperu
356
376
  end
357
377
 
358
378
  def time=(value, component: :mtime)
379
+ check_editable!
380
+ value = DOSTime.from_time(value)
359
381
  mark_dirty!(:time=)
360
382
  extra.create(:universaltime) unless extra.member?(:universaltime) || extra.member?(:ntfs)
361
383
 
362
- value = DOSTime.from_time(value)
363
384
  setter = component.to_s.end_with?('=') ? component : "#{component}="
364
385
  (extra[:universaltime] || extra[:ntfs]).send(setter, value)
365
386
  @time = value if component == :mtime
@@ -389,6 +410,7 @@ module Ziperu
389
410
  end
390
411
 
391
412
  def compression_method=(method)
413
+ check_editable!
392
414
  @dirty = true
393
415
  @compression_method = (ftype == :directory ? STORED : method)
394
416
  end
@@ -945,7 +967,7 @@ module Ziperu
945
967
  # A hidden name beside `path` for its replacement, on the same file
946
968
  # system so the rename stays one step.
947
969
  def staging_path(path)
948
- ::File.join(::File.dirname(path), ".#{::File.basename(path)}.ziperu-#{::Process.pid}-#{rand(1 << 32).to_s(16)}")
970
+ IOExtras.staging_path(path, rand(1 << 32).to_s(16))
949
971
  end
950
972
 
951
973
  # The entry's data, decompressed, into `os`.
@@ -1048,8 +1070,7 @@ module Ziperu
1048
1070
  end
1049
1071
 
1050
1072
  def check_name(name) # :nodoc:
1051
- raise EntryNameError, name if name.start_with?('/')
1052
- raise EntryNameError if name.length > MAX_FIELD_LENGTH
1073
+ Entry.check_name(name)
1053
1074
  end
1054
1075
 
1055
1076
  def init_from_row(archive, row, zipfile, metadata_encoding, settings, owner)
@@ -51,6 +51,18 @@ module Ziperu
51
51
 
52
52
  alias push <<
53
53
 
54
+ # Puts `fresh` in place of the entries from position `start` on,
55
+ # which it matches name for name: the same entries, read again. One
56
+ # pass, where `<<` would look each one up among all the others.
57
+ def replace_from(start, fresh)
58
+ fresh.each_with_index do |entry, i|
59
+ key = to_key(entry)
60
+ @entry_set[key] = entry if @entry_set[key].equal?(@all[start + i])
61
+ @all[start + i] = entry
62
+ end
63
+ self
64
+ end
65
+
54
66
  # Adds a record read from an archive. Unlike `<<`, an earlier record
55
67
  # of the very same name stays listed (and readable); the lookup by name
56
68
  # finds the later one, as rubyzip's does. Names that only share a key
@@ -9,6 +9,9 @@ module Ziperu
9
9
  # new archive is written beside the old one and renamed over it.
10
10
  def commit
11
11
  return if name.kind_of?(StringIO) || !commit_required?
12
+ # Whatever was changed, and however: an archive opened with
13
+ # `write: false` is not written.
14
+ return if @read_only
12
15
 
13
16
  appended = write_changes
14
17
  # Only now are the changes on disk; until here the entries keep
@@ -113,7 +116,7 @@ module Ziperu
113
116
 
114
117
  kept = @cdir.entries.first(held)
115
118
  kept.each { |e| e.rebind_native(native) }
116
- fresh.each { |e| @cdir << e }
119
+ @cdir.replace_from(held, fresh)
117
120
  @native.close
118
121
  @native = native
119
122
  @dirty = false
data/lib/ziperu/file.rb CHANGED
@@ -396,6 +396,9 @@ module Ziperu
396
396
  check_writable!
397
397
  found_entry = get_entry(entry)
398
398
  new_name = new_name.to_path if new_name.respond_to?(:to_path)
399
+ # Before anything is removed: a name the entry cannot take must
400
+ # leave it, and an entry of that name, where they were.
401
+ Entry.check_name(new_name.to_s)
399
402
  check_entry_exists(new_name, continue_on_exists_proc, 'rename')
400
403
  @cdir.delete(found_entry)
401
404
  found_entry.name = new_name
@@ -45,6 +45,17 @@ module Ziperu
45
45
  ::Ziperu::RUNNING_ON_WINDOWS && name.to_s.include?(':')
46
46
  end
47
47
 
48
+ # A hidden name beside `path` for the file that will replace it, in
49
+ # the same directory so that the rename is one step. `tag` tells
50
+ # one from another. The name says which file it is for as far as
51
+ # the 255 bytes a name may have allow.
52
+ def staging_path(path, tag)
53
+ dir, base = ::File.split(path)
54
+ tail = ".ziperu-#{::Process.pid}-#{tag}"
55
+ kept = base.byteslice(0, 254 - tail.bytesize).scrub('')
56
+ ::File.join(dir, ".#{kept}#{tail}")
57
+ end
58
+
48
59
  # Whether the native core can take `str` as a name or path: it wants
49
60
  # valid UTF-8.
50
61
  def native_text?(str)
@@ -102,16 +102,18 @@ module Ziperu
102
102
  return new(file_name, **opts) unless block_given?
103
103
 
104
104
  zos = new(file_name, stream: false, **opts)
105
- result =
106
- begin
107
- yield zos
108
- rescue Exception # rubocop:disable Lint/RescueException
109
- # The archive is abandoned: the entries written so far must
110
- # not learn offsets and sizes from it.
111
- zos.abort
112
- raise
113
- end
114
- zos.close
105
+ begin
106
+ result = yield zos
107
+ # Inside the handler too: an append is not over, and can still
108
+ # fail (a comment too long, a disk that fills), until the
109
+ # archive is closed.
110
+ zos.close
111
+ rescue Exception # rubocop:disable Lint/RescueException
112
+ # The archive is abandoned: the entries written so far must
113
+ # not learn offsets and sizes from it.
114
+ zos.abort
115
+ raise
116
+ end
115
117
  result
116
118
  end
117
119
 
@@ -258,12 +260,14 @@ module Ziperu
258
260
  entry = @current_entry
259
261
  raise Error, 'there is no entry being written to take back' if entry.nil? || !@written.last.equal?(entry)
260
262
 
261
- discard_writes
262
263
  if @deferred
263
264
  @deferred = nil
264
265
  else
265
266
  @writer.rollback_entry
266
267
  end
268
+ # Only now: where the entry cannot be taken back (its first bytes
269
+ # have gone out on a stream) what was written to it is still owed.
270
+ discard_writes
267
271
  @written.pop
268
272
  @stream_names&.delete(entry.name.b)
269
273
  @current_entry = nil
@@ -471,6 +475,17 @@ module Ziperu
471
475
  self
472
476
  end
473
477
 
478
+ # Whether a file entry under 4 GiB, with no `zip64:` of its own, is
479
+ # written zip64-ready under `settings`. `unsized` is true for one
480
+ # whose size is not known up front (or that already has the field).
481
+ # The size estimator asks the same question, so the two cannot differ.
482
+ def self.zip64_file?(settings, suppressed: false, unsized: false) # :nodoc:
483
+ return true if settings.write_zip64_support == :always && !suppressed
484
+ return false if suppressed || !settings.write_zip64_support
485
+
486
+ unsized
487
+ end
488
+
474
489
  private
475
490
 
476
491
  # Hands the gathered small writes (see `<<`) to the native writer.
@@ -642,10 +657,8 @@ module Ziperu
642
657
  return true if entry.size >= ZIP64_SIZE_LIMIT || entry.compressed_size >= ZIP64_SIZE_LIMIT
643
658
  return false unless entry.file?
644
659
  return entry.zip64 unless entry.zip64.nil?
645
- return true if @settings.write_zip64_support == :always && !suppressed
646
- return false if suppressed || !@settings.write_zip64_support
647
660
 
648
- entry.zip64? || !entry.size_known?
661
+ self.class.zip64_file?(@settings, suppressed: suppressed, unsized: entry.zip64? || !entry.size_known?)
649
662
  end
650
663
  end
651
664
  end
@@ -90,7 +90,8 @@ module Ziperu
90
90
  def add_file(name, size, compressed_size)
91
91
  fields = default_fields
92
92
  name = name.to_s.b
93
- large = size >= ZIP64_THRESHOLD || compressed_size >= ZIP64_THRESHOLD
93
+ large = size >= ZIP64_THRESHOLD || compressed_size >= ZIP64_THRESHOLD ||
94
+ OutputStream.zip64_file?(@settings)
94
95
  offset_large = @data >= ZIP64_THRESHOLD
95
96
  @entries += 1
96
97
  # The local header, with a zip64 extra for a large entry; the data;
@@ -240,8 +240,7 @@ module Ziperu
240
240
  # A name beside the archive's own, in the same directory so that the
241
241
  # rename at the end cannot cross a file system.
242
242
  def staging_path
243
- dir, base = ::File.split(@path)
244
- ::File.join(dir, ".#{base}.ziperu-#{::Process.pid}-#{::SecureRandom.hex(8)}")
243
+ IOExtras.staging_path(@path, ::SecureRandom.hex(8))
245
244
  end
246
245
 
247
246
  # A name as the archive takes it: not empty, no NUL, and no slash at
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ziperu
4
- VERSION = '0.4.0'
4
+ VERSION = '0.4.1'
5
5
  # The rubyzip API this gem tracks.
6
6
  RUBYZIP_COMPAT_VERSION = '3.7'
7
7
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ziperu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: aarch64-linux-gnu
6
6
  authors:
7
7
  - Maor Caplan
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-11-21 00:00:00.000000000 Z
10
+ date: 2026-12-06 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: Zip reading and writing for Ruby with rubyzip's API under the Ziperu
13
13
  namespace, implemented on the Rust `zip` crate via Magnus. `require "zip"` aliases