format_parser 0.13.5 → 0.13.6
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/format_parser/version.rb +1 -1
- data/lib/parsers/moov_parser/decoder.rb +32 -23
- metadata +1 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 236f35fe657e5bb8f51cf08724fb3138f17b6a20605af4131a7643711f43cd93
         | 
| 4 | 
            +
              data.tar.gz: 65037da607c406be2bf0d8e7eb549537199a4ed8c97243c68b63c62e20bdb9e5
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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 |  | 
| @@ -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 | 
            -
               | 
| 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 | 
            -
              #  | 
| 25 | 
            -
              KNOWN_BRANCH_AND_LEAF_ATOM_TYPES = %w( | 
| 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 | 
            -
             | 
| 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 | 
            -
                   | 
| 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 | 
| 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 | 
| 255 | 
            +
                _whole, _fraction = safe_read(io, 4).unpack('nn')
         | 
| 247 256 | 
             
              end
         | 
| 248 257 |  | 
| 249 258 | 
             
              def read_chars(io, n)
         | 
| 250 | 
            -
                io | 
| 259 | 
            +
                safe_read(io, n)
         | 
| 251 260 | 
             
              end
         | 
| 252 261 |  | 
| 253 262 | 
             
              def read_byte_value(io)
         | 
| 254 | 
            -
                io | 
| 263 | 
            +
                safe_read(io, 1).unpack('C').first
         | 
| 255 264 | 
             
              end
         | 
| 256 265 |  | 
| 257 266 | 
             
              def read_bytes(io, n)
         | 
| 258 | 
            -
                io | 
| 267 | 
            +
                safe_read(io, n)
         | 
| 259 268 | 
             
              end
         | 
| 260 269 |  | 
| 261 270 | 
             
              def read_16bit_uint(io)
         | 
| 262 | 
            -
                io | 
| 271 | 
            +
                safe_read(io, 2).unpack('n').first
         | 
| 263 272 | 
             
              end
         | 
| 264 273 |  | 
| 265 274 | 
             
              def read_32bit_uint(io)
         | 
| 266 | 
            -
                io | 
| 275 | 
            +
                safe_read(io, 4).unpack('N').first
         | 
| 267 276 | 
             
              end
         | 
| 268 277 |  | 
| 269 278 | 
             
              def read_64bit_uint(io)
         | 
| 270 | 
            -
                io | 
| 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 | 
| 283 | 
            +
                bcd_string = safe_read(io, 4)
         | 
| 275 284 | 
             
                [bcd_string].pack('H*').unpack('C*')
         | 
| 276 285 | 
             
              end
         | 
| 277 286 | 
             
            end
         |