format_parser 0.13.5 → 0.13.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8837741d44c95c25f1b68ae19991bf6b1c1819b17f8a645d5c53a9d9ba97a8bb
4
- data.tar.gz: 58dac9d742cf2b59bbf05ae8b810b8a6b15b144035ca625a52e4a9fbed74f93e
3
+ metadata.gz: 236f35fe657e5bb8f51cf08724fb3138f17b6a20605af4131a7643711f43cd93
4
+ data.tar.gz: 65037da607c406be2bf0d8e7eb549537199a4ed8c97243c68b63c62e20bdb9e5
5
5
  SHA512:
6
- metadata.gz: 5be5537ea121c3eff8ec4520d049b1ff0e813f22cc4ea800ad01be7ccb823e0580ea3155d9d561b6854e1f211a98ecd23e6a8de4ef4c2a735b81a6b69a7aa780
7
- data.tar.gz: 9b056ff9cb825a4d925a03ad3fcb245e0e93545057a1cf7c3ef778f84955b16b12175c9d8f3c0ab2e04542364c8bb1c5f65e8c0ad39ff70e199774217282a087
6
+ metadata.gz: aaa8a5c25a9b9b6884e0ec22adf90390aa2a32e4268e7e1d01c98a5d88a20bb25a4635ca53fd891d28bae8de34287ff57c943af76c905425f41ade98985408d9
7
+ data.tar.gz: 54a417ead7b3d12d585f6775feee2295d95f40fe9ac66a7a5e0788dfd6791271d95ddc1ef230a7c3e17c04635765916090db2a0cf98a722e5c7d662f80eb7d37
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 0.13.6
2
+ * Make all reads in the MOOV decoder strict - fail early if reads are improperly sized
3
+ * Disable parsing for `udta` atoms in MP4/MOV since we do not have a good way of parsing them yet
4
+
1
5
  ## 0.13.5
2
6
  * Use the same TIFF parsing flow for CR2 files as it seems we are not very reliable _yet._ The CR2 parser will need some work.
3
7
 
@@ -1,3 +1,3 @@
1
1
  module FormatParser
2
- VERSION = '0.13.5'
2
+ VERSION = '0.13.6'
3
3
  end
@@ -2,6 +2,8 @@
2
2
  # read atoms and parse their data fields if applicable. Also contains
3
3
  # a few utility functions for finding atoms in a list etc.
4
4
  class FormatParser::MOOVParser::Decoder
5
+ include FormatParser::IOUtils
6
+
5
7
  class Atom < Struct.new(:at, :atom_size, :atom_type, :path, :children, :atom_fields)
6
8
  def to_s
7
9
  '%s (%s): %d bytes at offset %d' % [atom_type, path.join('.'), atom_size, at]
@@ -18,11 +20,13 @@ class FormatParser::MOOVParser::Decoder
18
20
  end
19
21
  end
20
22
 
21
- # Atoms (boxes) that are known to only contain children, no data fields
22
- KNOWN_BRANCH_ATOM_TYPES = %w(moov mdia trak clip edts minf dinf stbl udta meta)
23
+ # Atoms (boxes) that are known to only contain children, no data fields.
24
+ # Avoid including udta or udta.meta here since we do not have methods
25
+ # for dealing with them yet.
26
+ KNOWN_BRANCH_ATOM_TYPES = %w(moov mdia trak clip edts minf dinf stbl)
23
27
 
24
- # Atoms (boxes) that are known to contain both leaves and data fields
25
- KNOWN_BRANCH_AND_LEAF_ATOM_TYPES = %w(meta) # the udta.meta thing used by iTunes
28
+ # Mark that udta may contain both
29
+ KNOWN_BRANCH_AND_LEAF_ATOM_TYPES = [] # %w(udta) # the udta.meta thing used by iTunes
26
30
 
27
31
  # Limit how many atoms we scan in sequence, to prevent derailments
28
32
  MAX_ATOMS_AT_LEVEL = 128
@@ -169,16 +173,24 @@ class FormatParser::MOOVParser::Decoder
169
173
 
170
174
  def parse_hdlr_atom(io, atom_size)
171
175
  sub_io = StringIO.new(io.read(atom_size - 8))
172
- {
173
- version: read_byte_value(sub_io),
176
+ version = read_byte_value(sub_io)
177
+ base_fields = {
178
+ version: version,
174
179
  flags: read_bytes(sub_io, 3),
175
180
  component_type: read_bytes(sub_io, 4),
176
181
  component_subtype: read_bytes(sub_io, 4),
177
182
  component_manufacturer: read_bytes(sub_io, 4),
178
- component_flags: read_bytes(sub_io, 4),
179
- component_flags_mask: read_bytes(sub_io, 4),
180
- component_name: sub_io.read,
181
183
  }
184
+ if version == 1
185
+ version1_fields = {
186
+ component_flags: read_bytes(sub_io, 4),
187
+ component_flags_mask: read_bytes(sub_io, 4),
188
+ component_name: sub_io.read,
189
+ }
190
+ base_fields.merge(version1_fields)
191
+ else
192
+ base_fields
193
+ end
182
194
  end
183
195
 
184
196
  def parse_meta_atom(io, atom_size)
@@ -217,11 +229,8 @@ class FormatParser::MOOVParser::Decoder
217
229
  # If atom_size is specified to be 1, it is larger than what fits into the
218
230
  # 4 bytes and we need to read it right after the atom type
219
231
  atom_size = read_64bit_uint(io) if atom_size == 1
220
-
221
- # We are allowed to read what comes after
222
- # the atom size and atom type, but not any more than that
223
- size_of_atom_type_and_size = io.pos - atom_pos
224
- atom_size_sans_header = atom_size - size_of_atom_type_and_size
232
+ atom_header_size = io.pos - atom_pos
233
+ atom_size_sans_header = atom_size - atom_header_size
225
234
 
226
235
  children, fields = if KNOWN_BRANCH_AND_LEAF_ATOM_TYPES.include?(atom_type)
227
236
  parse_atom_children_and_data_fields(io, atom_size_sans_header, atom_type, current_branch)
@@ -239,39 +248,39 @@ class FormatParser::MOOVParser::Decoder
239
248
  end
240
249
 
241
250
  def read_16bit_fixed_point(io)
242
- _whole, _fraction = io.read(2).unpack('CC')
251
+ _whole, _fraction = safe_read(io, 2).unpack('CC')
243
252
  end
244
253
 
245
254
  def read_32bit_fixed_point(io)
246
- _whole, _fraction = io.read(4).unpack('nn')
255
+ _whole, _fraction = safe_read(io, 4).unpack('nn')
247
256
  end
248
257
 
249
258
  def read_chars(io, n)
250
- io.read(n)
259
+ safe_read(io, n)
251
260
  end
252
261
 
253
262
  def read_byte_value(io)
254
- io.read(1).unpack('C').first
263
+ safe_read(io, 1).unpack('C').first
255
264
  end
256
265
 
257
266
  def read_bytes(io, n)
258
- io.read(n)
267
+ safe_read(io, n)
259
268
  end
260
269
 
261
270
  def read_16bit_uint(io)
262
- io.read(2).unpack('n').first
271
+ safe_read(io, 2).unpack('n').first
263
272
  end
264
273
 
265
274
  def read_32bit_uint(io)
266
- io.read(4).unpack('N').first
275
+ safe_read(io, 4).unpack('N').first
267
276
  end
268
277
 
269
278
  def read_64bit_uint(io)
270
- io.read(8).unpack('Q>').first
279
+ safe_read(io, 8).unpack('Q>').first
271
280
  end
272
281
 
273
282
  def read_binary_coded_decimal(io)
274
- bcd_string = io.read(4)
283
+ bcd_string = safe_read(io, 4)
275
284
  [bcd_string].pack('H*').unpack('C*')
276
285
  end
277
286
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: format_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.5
4
+ version: 0.13.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Noah Berman