Skip to content

Commit

Permalink
Fixing issues when inconsistent size information on ftyp boxes caused…
Browse files Browse the repository at this point in the history
… MP4 parser to throw errors instead of rejecting the files
  • Loading branch information
rcpalacio committed Sep 14, 2023
1 parent a8a4d07 commit b713c05
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/parsers/mp4_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def call(io)
private

def file_format(box_tree)
major_brand = box_tree.find { |box| box.type == 'ftyp' }&.fields[:major_brand]
major_brand = box_tree.find { |box| box.type == 'ftyp' }&.fields&.[](:major_brand)
BRAND_FORMATS[major_brand.downcase] if major_brand
end

Expand Down
Binary file not shown.
11 changes: 11 additions & 0 deletions spec/parsers/mp4_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@
end
end

context "when the 'ftyp' box can't be parsed" do
let(:result) do
path = fixtures_dir + '/MP4/invalid/inconsistent_ftyp_box.mp4'
subject.call(File.open(path, 'rb'))
end

it 'should be nil' do
expect(result).to be_nil
end
end

Dir.glob(fixtures_dir + '/MP4/valid/video/*.*').sort.each do |path|
context "for #{path}" do
let(:result) { subject.call(File.open(path, 'rb')) }
Expand Down

0 comments on commit b713c05

Please sign in to comment.