CFPropertyList 3.0.7 → 3.0.8

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: c734531a6c132c8d3c52ae8ad388a1bcc88584a060349c9430835a768d518bba
4
- data.tar.gz: 3d8f7d928e5a7bb1bddef3caae9b3785b071dc295fa727ef2163d255a882ae44
3
+ metadata.gz: f000bdc67bb044df320d7afd97a7d721669dc90939a5dcfa4ec3138cc88a6950
4
+ data.tar.gz: 693e1dda1acc30bac87f29076a8704ef8ea171bec3c088c3bead7871139e23e4
5
5
  SHA512:
6
- metadata.gz: e5be43e0290ffc2761a8830ce34d4b0a6d088b3c178050650242f6f9289b38b207474be6e045fd89c0a9e5ad7651739b7f0d6e48d083aad5e05a1d4175ad0384
7
- data.tar.gz: ccf92743adea6007c999e80aaf44ff7e882007b71ce458a11a2acc2fe117c866f2091932252d3ff4388a2a6381dff465bfbe58b18c66c6579c31dc389d386df5
6
+ metadata.gz: ea3294565339dd9a35c8b83e13e46c121843b90f51e645e5fac5568f39f1d21b8f2348ea950f9b8be4a44591a8d518a9955819118993e87972ee5b1012ad1b98
7
+ data.tar.gz: c20f731f5c4aae32432c37169c51de6de04d2706d68fe3d4413180dd57ede0494e667341473c4edae3dd49826f9b314630c59bef0d89d2c0196b22bb59d530d5
@@ -5,6 +5,8 @@ require 'stringio'
5
5
  module CFPropertyList
6
6
  # Binary PList parser class
7
7
  class Binary
8
+ MAX_DEPTH = 512
9
+
8
10
  # Read a binary plist file
9
11
  def load(opts)
10
12
  @unique_table = {}
@@ -31,11 +33,12 @@ module CFPropertyList
31
33
  buff = fd.read(32)
32
34
 
33
35
  offset_size, object_ref_size, number_of_objects, top_object, table_offset = buff.unpack "x6CCx4Nx4Nx4N"
36
+ raise CFFormatError.new("#{file}: Invalid offset_size #{offset_size}") unless [1, 2, 3, 4].include?(offset_size)
34
37
 
35
38
  # after that, get the offset table
36
39
  fd.seek(table_offset, IO::SEEK_SET)
37
40
  coded_offset_table = fd.read(number_of_objects * offset_size)
38
- raise CFFormatError.new("#{file}: Format error!") unless coded_offset_table.bytesize == number_of_objects * offset_size
41
+ raise CFFormatError.new("#{file}: Format error!") unless coded_offset_table && coded_offset_table.bytesize == number_of_objects * offset_size
39
42
 
40
43
  @count_objects = number_of_objects
41
44
 
@@ -214,28 +217,18 @@ module CFPropertyList
214
217
 
215
218
  # Convert the given string from one charset to another
216
219
  def Binary.charset_convert(str,from,to="UTF-8")
217
- return str.dup.force_encoding(from).encode(to) if str.respond_to?("encode")
218
- Iconv.conv(to,from,str)
220
+ str.dup.force_encoding(from).encode(to)
219
221
  end
220
222
 
221
223
  # Count characters considering character set
222
224
  def Binary.charset_strlen(str,charset="UTF-8")
223
- if str.respond_to?(:encode)
224
- size = str.length
225
- else
226
- utf8_str = Iconv.conv("UTF-8",charset,str)
227
- size = utf8_str.scan(/./mu).size
228
- end
225
+ size = str.length
229
226
 
230
227
  # UTF-16 code units in the range D800-DBFF are the beginning of
231
228
  # a surrogate pair, and count as one additional character for
232
229
  # length calculation.
233
230
  if charset =~ /^UTF-16/
234
- if str.respond_to?(:encode)
235
- str.bytes.to_a.each_slice(2) { |pair| size += 1 if (0xd8..0xdb).include?(pair[0]) }
236
- else
237
- str.split('').each_slice(2) { |pair| size += 1 if ("\xd8".."\xdb").include?(pair[0]) }
238
- end
231
+ str.bytes.to_a.each_slice(2) { |pair| size += 1 if (0xd8..0xdb).include?(pair[0]) }
239
232
  end
240
233
 
241
234
  size
@@ -264,7 +257,7 @@ module CFPropertyList
264
257
  end
265
258
 
266
259
  # Read an binary array value, including contained objects
267
- def read_binary_array(fname,fd,length)
260
+ def read_binary_array(fname,fd,length,depth=0)
268
261
  ary = []
269
262
 
270
263
  # first: read object refs
@@ -274,7 +267,7 @@ module CFPropertyList
274
267
 
275
268
  # now: read objects
276
269
  0.upto(length-1) do |i|
277
- object = read_binary_object_at(fname,fd,objects[i])
270
+ object = read_binary_object_at(fname,fd,objects[i],depth+1)
278
271
  ary.push object
279
272
  end
280
273
  end
@@ -284,7 +277,7 @@ module CFPropertyList
284
277
  protected :read_binary_array
285
278
 
286
279
  # Read a dictionary value, including contained objects
287
- def read_binary_dict(fname,fd,length)
280
+ def read_binary_dict(fname,fd,length,depth=0)
288
281
  dict = {}
289
282
 
290
283
  # first: read keys
@@ -298,8 +291,8 @@ module CFPropertyList
298
291
 
299
292
  # read real keys and objects
300
293
  0.upto(length-1) do |i|
301
- key = read_binary_object_at(fname,fd,keys[i])
302
- object = read_binary_object_at(fname,fd,objects[i])
294
+ key = read_binary_object_at(fname,fd,keys[i],depth+1)
295
+ object = read_binary_object_at(fname,fd,objects[i],depth+1)
303
296
  dict[key.value] = object
304
297
  end
305
298
  end
@@ -310,7 +303,7 @@ module CFPropertyList
310
303
 
311
304
  # Read an object type byte, decode it and delegate to the correct
312
305
  # reader function
313
- def read_binary_object(fname,fd)
306
+ def read_binary_object(fname,fd,depth=0)
314
307
  # first: read the marker byte
315
308
  buff = fd.read(1)
316
309
 
@@ -321,7 +314,7 @@ module CFPropertyList
321
314
  object_type = buff[0][0].chr
322
315
 
323
316
  if(object_type != "0" && object_length == 15) then
324
- object_length = read_binary_object(fname,fd)
317
+ object_length = read_binary_object(fname,fd,depth)
325
318
  object_length = object_length.value
326
319
  end
327
320
 
@@ -343,18 +336,19 @@ module CFPropertyList
343
336
  when '8'
344
337
  CFUid.new(read_binary_int(fname, fd, object_length).value)
345
338
  when 'a' # array
346
- read_binary_array(fname,fd,object_length)
339
+ read_binary_array(fname,fd,object_length,depth)
347
340
  when 'd' # dictionary
348
- read_binary_dict(fname,fd,object_length)
341
+ read_binary_dict(fname,fd,object_length,depth)
349
342
  end
350
343
  end
351
344
  protected :read_binary_object
352
345
 
353
346
  # Read an object type byte at position $pos, decode it and delegate to the correct reader function
354
- def read_binary_object_at(fname,fd,pos)
347
+ def read_binary_object_at(fname,fd,pos,depth=0)
348
+ raise CFFormatError.new("#{fname}: Maximum depth exceeded") if depth > MAX_DEPTH
355
349
  position = @offsets[pos]
356
350
  fd.seek(position,IO::SEEK_SET)
357
- read_binary_object(fname,fd)
351
+ read_binary_object(fname,fd,depth)
358
352
  end
359
353
  protected :read_binary_object_at
360
354
 
@@ -80,8 +80,7 @@ require dirname + '/rbPlainCFPropertyList.rb'
80
80
 
81
81
  begin
82
82
  require dirname + '/rbLibXMLParser.rb'
83
- temp = LibXML::XML::Parser::Options::NOBLANKS # check if we have a version with parser options
84
- temp = false # avoid a warning
83
+ _ = LibXML::XML::Parser::Options::NOBLANKS # check if we have a version with parser options
85
84
  try_nokogiri = false
86
85
  CFPropertyList.xml_parser_interface = CFPropertyList::LibXMLParser
87
86
  rescue LoadError, NameError
@@ -60,7 +60,7 @@ module CFPropertyList
60
60
  end
61
61
 
62
62
  def to_plain(plist)
63
- if @value =~ /^\w+$/
63
+ if @value =~ /\A\w+\z/
64
64
  @value
65
65
  else
66
66
  quoted
@@ -74,7 +74,7 @@ module CFPropertyList
74
74
  when '"'
75
75
  '\\"'
76
76
  when '\\'
77
- '\\'
77
+ '\\\\'
78
78
  when "\a"
79
79
  "\\a"
80
80
  when "\b"
@@ -82,7 +82,7 @@ module CFPropertyList
82
82
  when "\f"
83
83
  "\\f"
84
84
  when "\n"
85
- "\n"
85
+ "\\n"
86
86
  when "\v"
87
87
  "\\v"
88
88
  when "\r"
metadata CHANGED
@@ -1,57 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: CFPropertyList
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.7
4
+ version: 3.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Kruse
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-02-15 00:00:00.000000000 Z
11
+ date: 2025-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rexml
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: nkf
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: base64
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
13
  - !ruby/object:Gem::Dependency
56
14
  name: libxml-ruby
57
15
  requirement: !ruby/object:Gem::Requirement
@@ -133,7 +91,7 @@ homepage: https://github.com/ckruse/CFPropertyList
133
91
  licenses:
134
92
  - MIT
135
93
  metadata: {}
136
- post_install_message:
94
+ post_install_message:
137
95
  rdoc_options: []
138
96
  require_paths:
139
97
  - lib
@@ -148,8 +106,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
106
  - !ruby/object:Gem::Version
149
107
  version: '0'
150
108
  requirements: []
151
- rubygems_version: 3.5.3
152
- signing_key:
109
+ rubygems_version: 3.0.3.1
110
+ signing_key:
153
111
  specification_version: 4
154
112
  summary: Read, write and manipulate both binary and XML property lists as defined
155
113
  by apple