Commit Graph

1462 Commits

Author SHA1 Message Date
Justin Ruggles 97f47fd601 mov: Fix start_time for streams with empty edits in the middle
Empty edits can occur at any position within the edit list except for at
the end. Empty edits in the middle should not impact the reported stream
start_time or the video PTS adjustment, so only include empty edits at
the start of the list in empty_edits_sum_duration.

Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com>
2019-02-26 14:48:27 -05:00
Michael Niedermayer b0d8b7cb8e avformat/mov: Do not use reference stream in mov_read_sidx() if there is no reference stream
Fixes: NULL pointer dereference
Fixes: clusterfuzz-testcase-minimized-audio_decoder_fuzzer-5634316373721088

Reported-by: Chris Cunningham <chcunningham@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-02-14 21:55:43 +01:00
Charles Liu aa25198f1b avformat/mov: fix hang while seek on a kind of fragmented mp4
Binary searching would hang if the fragment items do NOT have timestamp for the
specified stream.

For example, a fmp4 consists of separated 'moof' boxes for each track, and
separated 'sidx' for each segment, but no 'mfra' box.  Then every fragment item
only have the timestamp for one of its tracks.

Example:
ffmpeg -f lavfi -i testsrc -f lavfi -i sine -movflags dash+frag_keyframe+skip_trailer+separate_moof -t 1 out.mp4
ffmpeg -ss 0.5 -i out.mp4 -f null none

Also fixes the hang in ticket #7572, but not the reason for having
AV_NOPTS_VALUE timestamps there.

Signed-off-by: Charles Liu <liuchh83@gmail.com>
Signed-off-by: Marton Balint <cus@passwd.hu>
2019-02-11 22:01:06 +01:00
James Almer 00fd38f184 avformat/mov: don't rescale mastering display values from the SmDm atom
Simplifies code.

Reviewed-by: Michael Niedermayer <michaelni@gmx.at>
Signed-off-by: James Almer <jamrial@gmail.com>
2019-02-11 16:58:27 -03:00
chcunningham 1c15449ca9 avformat/mov: validate chunk_count vs stsc_data
Bad content may contain stsc boxes with a first_chunk index that
exceeds stco.entries (chunk_count). This ammends the existing check to
include cases where chunk_count == 0. It also patches up the case
when stsc refers to unknown chunks, but stts has no samples (so we
can simply ignore stsc).

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-02-08 12:00:59 +01:00
chcunningham 3ea87e5d9e avformat/mov.c: require tfhd to begin parsing trun
Detecting missing tfhd avoids re-using tfhd track info from the previous
moof. For files with multiple tracks, this may make a mess of the
avindex and fragindex, which can later trigger av_assert0 in
mov_read_trun().

Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2019-02-08 12:00:59 +01:00
Carl Eugen Hoyos 5d958f0955 lavf/mov: Do not fail hard for more invalid atoms.
This is what several other players do and what FFmpeg already does for the sidx atom.

Fixes ticket #7679.
2019-01-14 22:30:27 +01:00
Derek Buitenhuis 8f585c3c55 mov: Remove duration-of-last-frame heuristic hack
This breaks totally valid files that get caught in its heuristic.

This, according to the commit message, is my own doing, having asked
Michael to implement this check and providing a sample that was
"wrong". I am now atoning for my sins, and removing this hack, having
seen the light (aka that this was silly to do in the first place).

Resotores correct behavior on valid files.

This reverts commit 8e5e84c2a2.

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2019-01-02 10:45:43 -05:00
Jacob Trimble 555f332e7a libavformat/mov: Fix NULL-dereference read for some encrypted content.
When reading frames, we need to use the fragment for the correct
stream.  Sometimes the "current" fragment is not the same as the one
the frame is for.

Found by Chromium's ClusterFuzz:
https://crbug.com/906392 and https://crbug.com/915524

Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-12-20 23:32:36 +01:00
Michael Niedermayer 21f4b456f1 avformat/mov: Simplify get_stream_info_time()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-12-19 20:09:03 +01:00
Jan Ekström a1f0dd24f6 lavf/mov: document the dvh1 codec switch based on hvcC availability 2018-12-17 23:25:43 +02:00
chcunningham c9f7b6f7a9 lavf/mov: ensure only one tkhd per trak
Chromium fuzzing produced a whacky file with extra tkhds. This caused
an AVStream that was already in use to be corrupted by assigning it a
new id, which blows up later in mov_read_trun because the
MOVFragmentStreamInfo.index_entry now points OOB.

Reviewed-by: Baptiste Coudurier <baptiste.coudurier@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-12-16 09:49:07 +01:00
Justin Ruggles d2047c14c0 Use QT format for audio sample descriptors depending on stsd version.
ISOBMFF does not allow AudioSampleEntryV1 in stsd version 0, so
assume the descriptor format is QTFF SoundDescriptionV1. ISOBMFF does
not define a version 2.

This fixes audio decoding for some MP4 files generated with Apple
tools. The additional fields present in SoundDescriptionV1/V2 need to
be read in order to correctly read additional boxes that contain
information required for decoding the stream.

Fixes #7376.

Also see: https://github.com/HandBrake/HandBrake/issues/1555

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2018-09-09 19:52:53 +01:00
John Stebbins 3318ac5b9a lavf/mov: factor out setting codec_id
Since it is performed in all cases now.

Signed-off-by: James Almer <jamrial@gmail.com>
2018-09-08 19:08:35 -03:00
John Stebbins c9a992d931 lavf/mov: add AVCodecTag entry for GoPro metadata
This allows for validation of the track type

Signed-off-by: James Almer <jamrial@gmail.com>
2018-09-08 19:08:34 -03:00
Dale Curtis 320b631a99 avformat/mov: Error on too large stsd entry counts.
Entries are always at least 8 bytes per the parsing code, so if we
see an impossible entry count avoid massive allocations. This is
similar to an existing check in mov_read_stsc().

Since ff_mov_read_stsd_entries() does eof checks, an alternative
approach could be to clamp the entry count to atom.size / 8.

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-09-01 19:26:40 +02:00
Dale Curtis e7080d1fe2 avformat/mov: Correct opus-in-mp4 pre-skip to be uint16_t versus int16_t.
This field is a uint16_t, see docs:
http://opus-codec.org/docs/opus_in_isobmff.html#4.3.2

Signed-off-by: Dale Curtis <dalecurtis@chromium.org>
Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-08-23 16:00:26 +02:00
Jacob Trimble eb350ab738 avformat/mov: Allow saio/saiz in clear content.
If there is a saio/saiz in clear content, we shouldn't create the
encryption index if we don't already have one.  Otherwise it will
confuse the cenc_filter.

The changed method is also used for senc atoms, but they should not
appear in clear content.

Found by Chromium's ClusterFuzz: https://crbug.com/873432

Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-08-22 18:54:23 +02:00
James Almer 8d5604a69a avformat/av1: update ff_isom_write_av1c() to the latest revision of the spec
This will get ISOBMFF and Matroska up to date with the revised AV1 Codec
Configuration Box spec.
For now keep propagating raw OBUs as extradata until all libavcodec modules
are adapted to handle AV1CodecConfigurationRecord formatted extradata.

Tested-by: Thomas Daede <bztdlinux@gmail.com>
Signed-off-by: James Almer <jamrial@gmail.com>
2018-08-17 15:09:02 -03:00
Sasi Inguva 12673bb253 lavf/mov.c: Set start_time for all streams (in case of edit lists).
Fixes vorbis mp4 audio files, with edit list specified. Since
st->skip_samples is not set in case of vorbis , ffmpeg computes the
start_time as negative.

Signed-off-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-08-11 02:37:42 +02:00
Carl Eugen Hoyos 6130068453 lavf/mov: Force HEVC codec_id for code-point dvh1 and an hvcC atom.
The mp4 registration authority accepted a code-point for Dolby Vision
HEVC that was already used as a fourcc for DVCPRO 100.

Fixes ticket #7347.
2018-08-09 00:44:07 +02:00
Michael Niedermayer a37c620269 avformat/mov: Check default_encrypted_sample before use in mov_read_sample_encryption_info()
Fixes: 2018-0721-sample
Fixes: null pointer dereference

Found-by: Nikita Knyzhov (knnikita@yandex.ru)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-07-26 02:42:42 +02:00
James Almer 9ca7ad246d avformat/mov: add support for AV1 streams
Signed-off-by: James Almer <jamrial@gmail.com>
2018-07-20 11:43:25 -03:00
Gyan Doshi 8aa6d9a8d3 avformat/mov: only set handler_name from mdia->hdlr
6 FATE references updated.

Fixes #7104
2018-07-16 21:33:01 +05:30
Michael Niedermayer b0644f7f72 avformat/mov: Simplify last element computation in mov_estimate_video_delay()
Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Reviewed-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-07-13 02:19:50 +02:00
Michael Niedermayer aba13dc13e avformat/mov: Break out of inner loop early in mov_estimate_video_delay()
0.266 <- 0.299 sec (this is time ffmpeg so containing alot other things)

Sample for benchmark was: ffmpeg -f rawvideo -pix_fmt yuv420p -s 32x32 -i /dev/zero -t 24:00:00.00 out.mp4

Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Reviewed-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-07-13 02:19:50 +02:00
Michael Niedermayer 3ce4034308 avformat/mov: Eliminate variable buf_size from mov_estimate_video_delay()
Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Reviewed-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-07-12 01:28:23 +02:00
Michael Niedermayer c995e01b1e avformat/mov: remove modulo operations from mov_estimate_video_delay()
0.324 <-0.491 sec

Reviewed-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Reviewed-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-07-12 01:28:23 +02:00
Jacob Trimble 7e22f5d457 avformat/mov: Expose encryption info to the app.
This exposes encryption info from the container to the app.  This
includes key ID, IV, and subsample byte ranges.  The info is passed
using the new side-data AV_PKT_DATA_ENCRYPTION_DATA and
AV_PKT_DATA_ENCRYPTION_INIT_DATA.

Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-07-04 01:10:28 +02:00
Carl Eugen Hoyos a990184007 lavf/mov: Do not fail hard for truncated stsz atoms.
Fixes ticket #6433.
2018-06-19 22:48:04 +02:00
Michael Niedermayer 8176799f31 avformat/mov: Only set pkt->duration to non negative values
Reviewed-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-06-14 18:55:45 +02:00
Jacob Trimble 4aba45ca1f avformat/mov: Add check for per-sample IV size.
Found by Chrome's ClusterFuzz: http://crbug.com/849062.

Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-06-13 16:46:40 +02:00
Jacob Trimble cf81a9c078 avformat/mov: Fix reading saio/saiz for clear content.
This validates that the common encryption saio/saiz atoms only appear
when the data is actually encrypted.  This also ignores those atoms
in clear content.

Found by Chrome's ClusterFuzz: http://crbug.com/850389

Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-06-09 20:44:50 +02:00
Sasi Inguva fe6c4f0c47 lavf/mov.c: Set st->start_time for video streams explicitly.
If start_time is not set, ffmpeg takes the duration from the global
movie instead of the per stream duration.
Signed-off-by: Sasi Inguva <isasi@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-06-06 01:53:30 +02:00
Sasi Inguva 318d0fcbfe lavf/mov.c: Fix timestamps to be strictly monotonic for video also.
We already do this for audio, but it should be done for video too.
If we don't, seeking back to the start of the file, for example, can
become quite broken, since the first N packets will have repeating
and nonmonotonic PTS, yet they need to be decoded even if they are
to be discarded.

Signed-off-by: Sasi Inguva <isasi@isasi.mtv.corp.google.com>
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2018-06-05 16:00:19 +01:00
Jacob Trimble 9827bb88e7 libavformat/mov: Fix heap buffer overflow.
Found by Chrome's ClusterFuzz: https://crbug.com/847060

Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-06-02 01:55:12 +02:00
Michael Niedermayer fe84f70819 avformat/mov: replace a value error by clipping into valid range in mov_read_stsc()
Fixes: #7165

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-05-22 21:05:45 +02:00
Michael Niedermayer 2c2d689c56 avformat/mov: Only fail for STCO/STSC contradictions if both exist
Fixes regression with playback of GF9720Repeal20the20Eighth20with20Helen20Linehan.m4a
See: crbug 822666

Found-by: "Mattias Wadman <mattias.wadman@gmail.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-05-21 01:50:21 +02:00
Michael Niedermayer 56e76bd057 avformat/mov: Break out early if chunk_count is 0 in mov_build_index()
Without this some operations might overflow (undefined behavior)
even though the index adding loop would never execute

No testcase known

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-05-21 01:38:56 +02:00
Derek Buitenhuis 28503c5aea mov: Properly abide by the track's media duration
The track's media duration from the mdhd atom takes precedence
over both the stts and elst atom for calculating and setting
the track's total duraion.

Technically, we shouldn't be using the stts atom at all for
calculating stream durations.

This fixes incorrect stream and final packet durations on files
with edit lists that are longer than the media duration.

The FATE changes are expected, and output is more correct (the
AAC frame is not 1028 samples).

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
2018-04-26 14:42:15 +01:00
Jacob Trimble e5ba5fab49 avformat/mov: Fix parsing of saio/siaz atoms in encrypted content.
This doesn't support saio atoms with more than one offset.

Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-21 00:45:31 +02:00
Jacob Trimble baf9c0bd99 avformat/mov: Remove old encryption info methods.
Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-19 21:49:47 +02:00
Jacob Trimble 606c5c7f3a avformat/mov: Fix memory leak in encryption info.
Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-19 21:49:47 +02:00
Jacob Trimble f7221d8e67 avformat/mov: Increase support for common encryption.
- Parse schm atom to get different encryption schemes.
- Allow senc atom to appear in track fragments.
- Allow 16-byte IVs.
- Allow constant IVs (specified in tenc).
- Allow only tenc to specify encryption (i.e. no senc/saiz/saio).
- Use sample descriptor to detect clear fragments.

This doesn't support:
- Different sample descriptor holding different encryption info.
  - Only first sample descriptor can be encrypted.
- Encrypted sample groups (i.e. seig).
- Non-'cenc' encryption scheme when using -decryption_key.

Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-19 03:15:32 +02:00
Michael Niedermayer 0a8133119c avformat/mov: Fix extradata memleak
Fixes: crbug 822705

Reported-by: Matt Wolenetz <wolenetz@google.com>
Reviewed-by: Matt Wolenetz <wolenetz@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-12 23:52:59 +02:00
Jacob Trimble b08c132a9c avformat/mov: Fix parsing of tfdt when using sample descriptors.
Signed-off-by: Jacob Trimble <modmaker@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-05 20:10:24 +02:00
Timo Teräs 8c980b1c92 avformat/mov: parse multiple iTunes cover images
Multiple cover images are supported by having multiple data atoms
inside the covr atom. AtomicParsley and mutagen amongst others
support and document this construct.

Signed-off-by: Timo Teräs <timo.teras@iki.fi>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-04-01 02:58:51 +02:00
Michael Niedermayer eb60b9d3aa avformat/mov: Move +1 in check to avoid hypothetical overflow in add_ctts_entry()
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-03-26 02:16:48 +02:00
Michael Niedermayer 9e67447a4f avformat/mov: Check STSC and remove invalid entries
Fixes assertion failure
Fixes: crbug 822547, crbug 822666 and crbug 823009

Affects: aark15sd_9A62E2FA.mp4

Found-by: ClusterFuzz
Reviewed-by: Matt Wolenetz <wolenetz@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-03-20 22:59:40 +01:00
Michael Niedermayer 2f37082827 avformat/mov: Fix integer overflows related to sample_duration
Fixes: runtime error: signed integer overflow: -9166684017437101870 + -2495066639299164439 cannot be represented in type

Fixes: Chromium bug 791349

Reported-by: Matt Wolenetz <wolenetz@google.com>
Reviewed-by: Matt Wolenetz <wolenetz@google.com>
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2018-03-12 01:32:42 +01:00