summaryrefslogtreecommitdiff
path: root/libavformat/matroskadec.c
Commit message (Collapse)AuthorAge
* avformat/matroskadec: fix setting channel layout using the Channels elementJames Almer2022-07-04
| | | | | | | | | | | | | | If the stream's channel layout is first set into a native layout using codec private parameters, this code here could potentially result in an invalid native layout where popcnt(ch_layout.u.mask) != ch_layout.nb_channels being propagated. Fixes: Timeout printing a billion channels Fixes: 48099/clusterfuzz-testcase-minimized-ffmpeg_dem_MATROSKA_fuzzer-6754782204788736 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Tested-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/matroskadec: avoid integer overflows in SAR computationMichael Niedermayer2022-06-25
| | | | | | | | | | | | This ignores >64bit Alternatively we could support that if it occurs in reality Fixes: negation of -9223372036854775808 Fixes: integer overflows Fixes: 46072/clusterfuzz-testcase-minimized-ffmpeg_dem_MATROSKA_fuzzer-5029840966778880 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* lavf/matroskadec: stop mapping text/plain attachments to AV_CODEC_ID_TEXTAnton Khirnov2022-06-08
| | | | | | There is no reason to think that an attachment will contain text subtitles. Furthermore, attachments are exported in extradata, so the AV_CODEC_ID_TEXT decoder would not do anything useful with them anyway.
* avformat/matroskadec: assert non NULL bufMichael Niedermayer2022-05-26
| | | | | | | | | The code is only called if size is > 0 so buf should not be NULL Helps: CID610554 Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/demux: Add new demux.h headerAndreas Rheinhardt2022-05-10
| | | | | | And move those stuff already in demuxer-only files to it. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/matroskadec: Check pre_nsMichael Niedermayer2022-03-18
| | | | | | | | Fixes: division by 0 Fixes: 44615/clusterfuzz-testcase-minimized-ffmpeg_dem_WEBM_DASH_MANIFEST_fuzzer-6681108677263360 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/matroskadec: Use rounded down duration in get_cue_desc() checkMichael Niedermayer2022-03-17
| | | | | | | | | | Floating point is evil, it would be better if duration was not a double Fixes: Infinite loop Fixes: 45123/clusterfuzz-testcase-minimized-ffmpeg_dem_WEBM_DASH_MANIFEST_fuzzer-6725052291219456 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* configure: Use a separate config_components.h header for $ALL_COMPONENTSMartin Storsjö2022-03-16
| | | | | | | | This avoids unnecessary rebuilds of most source files if only the list of enabled components has changed, but not the other properties of the build, set in config.h. Signed-off-by: Martin Storsjö <martin@martin.st>
* matroska: convert to new channel layout APIVittorio Giovara2022-03-15
| | | | | | Signed-off-by: Vittorio Giovara <vittorio.giovara@gmail.com> Signed-off-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: James Almer <jamrial@gmail.com>
* configure: stop allowing disabling lzoJames Almer2022-02-26
| | | | | | The module is now always compiled in. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/matroskadec: Check durationMichael Niedermayer2022-02-25
| | | | | | | | | Fixes: -nan is outside the range of representable values of type 'long' Fixes: 44614/clusterfuzz-testcase-minimized-ffmpeg_dem_WEBM_DASH_MANIFEST_fuzzer-6216204841254912 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/matroskadec: Check desc_bytesMichael Niedermayer2022-02-09
| | | | | | | | Fixes: Division by 0 Fixes: 44035/clusterfuzz-testcase-minimized-ffmpeg_dem_WEBM_DASH_MANIFEST_fuzzer-4826721386364928 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/matroskadec: Fix infinite loop with bz decompressionMichael Niedermayer2022-02-09
| | | | | | | | | | | The same check is added to zlib too, it seems not needed there though Fixes: Infinite loop Fixes: 43932/clusterfuzz-testcase-minimized-ffmpeg_dem_MATROSKA_fuzzer-6175167573786624 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/matroskadec: Export rectangular projection as displaymatrixAndreas Rheinhardt2022-01-29
| | | | | | | This is the officially supported way to express rotations and flips in Matroska. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/matroskadec: Use correct type for field_orderAndreas Rheinhardt2022-01-19
| | | | | | It is unsigned in the spec and read from an uint64_t field. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/packet_internal: Add proper PacketList structAndreas Rheinhardt2022-01-04
| | | | | | | | | | | | | | | Up until now, we had a PacketList structure which is actually a PacketListEntry; a proper PacketList did not exist and all the related functions just passed pointers to pointers to the head and tail elements around. All these pointers were actually consecutive elements of their containing structs, i.e. the users already treated them as if they were a struct. So add a proper PacketList struct and rename the current PacketList to PacketListEntry; also make the functions use this structure instead of the pair of pointers. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/mpeg4audio: Unavpriv and deduplicate mpeg4audio_sample_ratesAndreas Rheinhardt2022-01-04
| | | | | | | | | | | | | | | | | | | | | avpriv_mpeg4audio_sample_rates has a size of 64B and it is currently avpriv; a clone of it exists in aacenctab.h and from there it is inlined in aacenc.c (which also uses the avpriv version) and in the FLV muxer. This means that despite it being avpriv both libavformat as well as libavcodec have copies already. This situation is clearly suboptimal. Given the overhead of exporting symbols (for x64 Elf/Linux/GNU: 2x2B version, 2x24B .dynsym, 24B .rela.dyn, 8B .got, 4B hash + twice the size of the name (here 31B)) the object is unavprived, i.e. duplicated into libavformat when creating a shared build; but the duplicates in the AAC encoder and FLV muxer are removed. This involves splitting of the sample rate table into a file of its own; this allowed to break some spurious dependencies (e.g. both the AAC encoder as well as the Matroska demuxer actually don't need the mpeg4audio_get_config stuff). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/matroska{dec, enc}: Parse BlockAdditionMapping elementsquietvoid2022-01-04
| | | | | | | | | | | | | Adds handling of dvcC/dvvC block addition mappings. The parsing creates AVDOVIDecoderConfigurationRecord side data. The configuration block is written when muxing into Matroska, if DOVI side data is present for the track. Most of the Matroska element parsing is based on Plex's FFmpeg source code. Signed-off-by: quietvoid <tcChlisop0@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/matroskadec: Don't unnecessarily reduce aspect ratioAndreas Rheinhardt2021-11-07
| | | | | | | Fixes ticket #9497. Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/matroskadec: Reset state also on failure in matroska_reset_status()Michael Niedermayer2021-10-09
| | | | | | | | | | | The calling code does not handle failures and will fail with assertion failures later. Seeking can always fail even when the position was previously read. Fixes: Assertion failure Fixes: 35253/clusterfuzz-testcase-minimized-ffmpeg_dem_MATROSKA_fuzzer-4693059982983168 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat: Avoid allocation for AVStreamInternalAndreas Rheinhardt2021-09-17
| | | | | | | | | | Do this by allocating AVStream together with the data that is currently in AVStreamInternal; or rather: Put AVStream at the beginning of a new structure called FFStream (which encompasses more than just the internal fields and is a proper context in its own right, hence the name) and remove AVStreamInternal altogether. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat: Avoid allocation for AVFormatInternalAndreas Rheinhardt2021-09-17
| | | | | | | | | | | | | Do this by allocating AVFormatContext together with the data that is currently in AVFormatInternal; or rather: Put AVFormatContext at the beginning of a new structure called FFFormatContext (which encompasses more than just the internal fields and is a proper context in its own right, hence the name) and remove AVFormatInternal altogether. The biggest simplifications occured in avformat_alloc_context(), where one can now simply call avformat_free_context() in case of errors. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/matroskadec: Fix heap-buffer overflow upon gigantic timestampsAndreas Rheinhardt2021-08-30
| | | | | | | | | | | | | | | | | | | The WebM DASH Manifest demuxer creates a comma-delimited list of all the timestamps of index entries. It allocates 20 bytes per timestamp; yet the largest 64bit numbers have 20 decimal digits (for int64_t it can be '-'+ 19 digits), so that one needs 21B per entry because of the comma (resp. the final NUL). The code uses snprintf, but snprintf returns the strlen of the string that would have been written had the supplied buffer been big enough. And if this is 21, then the next entry is written at an offset of 21 from the current position. So if enough such entries exist, the buffer won't suffice. This commit fixes this by replacing the allocation of buffer for the supposedly worst-case with dynamic allocations by using an AVBPrint. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/avio: Move internal AVIOContext fields to avio_internal.hAndreas Rheinhardt2021-08-25
| | | | | | | | | | | | | | Currently AVIOContext's private fields are all over AVIOContext. This commit moves them into a new structure in avio_internal.h instead. Said structure contains the public AVIOContext as its first element in order to avoid having to allocate a separate AVIOContextInternal which is costly for those use cases where one just wants to access an already existing buffer via the AVIOContext-API. For these cases ffio_init_context() can't fail and always returned zero, which was typically not checked. Therefore it has been made to not return anything. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/matroskadec: Read RealAudio extradata directlyAndreas Rheinhardt2021-08-25
| | | | | | Don't use the avio-API to read a few bytes at fixed offsets. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/matroskadec: Include webm_dash_manifest demuxer only if enabledAndreas Rheinhardt2021-08-24
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/matroskadec: Simplify cleanup after read_header failureAndreas Rheinhardt2021-07-07
| | | | | | by setting the FF_FMT_INIT_CLEANUP flag. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/matroskadec: Fix handling of huge default durationsMichael Niedermayer2021-07-06
| | | | | | | | Fixes: negation of -9223372036854775808 cannot be represented in type 'int64_t' (aka 'long'); cast to an unsigned type to negate this value to itself Fixes: 33997/clusterfuzz-testcase-minimized-ffmpeg_dem_WEBM_DASH_MANIFEST_fuzzer-6752039691485184 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/utils: make ff_update_cur_dts() sharedJames Almer2021-06-09
| | | | | | libavdevice needs it. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/matroskadec: remove special handling of av1c extradataJan Ekström2021-05-08
| | | | | Libavcodec can now handle the standard AV1CodecConfigurationRecord extradata as-is.
* avformat: move AVStream.{parser,need_parsing} to AVStreamInternalJames Almer2021-05-07
| | | | | | | Those are private fields, no reason to have them exposed in a public header. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: Constify all muxer/demuxersAndreas Rheinhardt2021-04-27
| | | | | | | This is possible now that the next-API is gone. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec, avformat: Remove AVPacket.convergence_durationAndreas Rheinhardt2021-04-27
| | | | | | | Deprecated in 948f3c19a8bd069768ca411212aaf8c1ed96b10d. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avformat: Add and use helper function to add attachment streamsAndreas Rheinhardt2021-04-01
| | | | | | | | | All instances of adding attached pictures to a stream or adding a stream and an attached packet to said stream have several things in common like setting the index and flags of the packet, setting the stream disposition etc. This commit therefore factors this out. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avformat/matroskadec: Reuse AVFormatInternal.parse_pktAndreas Rheinhardt2021-03-24
| | | | | | | | | | | | | | | | | Before 8d78e90a6ba96646f7f25aff6ca3e12e71cec164 the Matroska demuxer used stack packets to hold temporary packets; now it uses a temporary packet allocated by the Matroska demuxer. Yet because it used stack packets the code has always properly reset the packet on error, while on success these temporary packets were put into a packet list via avpriv_packet_list_put(), which already resets the source packet. This means that this code is compatible with just reusing AVFormatInternal.parse_pkt (which is unused while one is in the demuxer's read_packet() function). Compared to before 8d78e90a6 this no longer wastes one initialization per AVPacket read (the resetting of the stack packet performed by av_packet_move_ref() in avpriv_packet_list_put() was for naught). Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskadec: use av_packet_alloc() to allocate packetsJames Almer2021-03-17
| | | | Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec/packet_internal: make avpriv_packet_list_* functions use an internal ↵James Almer2021-03-17
| | | | | | | | | struct The next pointer is kept at the end for backwards compatability until the major bump, when it should ideally be moved at the front. Signed-off-by: James Almer <jamrial@gmail.com>
* avformat/matroskadec: Check for EOF in resync loopMichael Niedermayer2021-03-15
| | | | | | | | | Fixes: Timeout (too long -> instantly) Fixes: 29136/clusterfuzz-testcase-minimized-ffmpeg_dem_WEBM_DASH_MANIFEST_fuzzer-4586141227548672 Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avformat/matroskadec: Add support for FlagOriginalAndreas Rheinhardt2021-03-02
| | | | | | | | | | | | | | | | Needs a CountedElement in order to distinguish the case of the element not being present and the element being present with a value of zero. (It has been argued by Ridley Combs that one should only ever use the AV_DISPOSITION_DUB field for audio tracks. Yet given that there is no definition for the disposition flags, one can also interpret it to mean that e.g. a subtitle track is meant to be used with the dubbed audio track or the original audio track. This commit interprets this flag in this sense, which also allows to maintain it on remuxing.) Reviewed-by: Anton Khirnov <anton@khirnov.net> Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskadec: Use av_strstart instead of strncmpAndreas Rheinhardt2021-02-28
| | | | | | | It makes the intent clearer and avoids calculating the length separately. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskadec: Add webm file extensionAndreas Rheinhardt2021-02-27
| | | | Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskadec: Add support for FlagTextDescriptionsAndreas Rheinhardt2021-02-22
| | | | | | | | This is the equivalent of the WebM "D_WEBVTT/DESCRIPTIONS" and is therefore only exported for subtitles. Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskadec: Add support for FlagHearing/VisualImpairedAndreas Rheinhardt2021-02-22
| | | | | | | | | | Given that our disposition flags provide no way to distinguish the cases of "track is unsuitable for hearing impaired users" and "it is unknown whether the track is suitable for hearing impaired users" we do not need to use a CountedElement for these flags. Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskadec: Add support for FlagCommentaryAndreas Rheinhardt2021-02-22
| | | | | | | | | | Hint: Matroska actually provides a way to distinguish the cases of "track is no commentary track" and "it is unknown whether the track is a commentary track", but our disposition flags do not. Therefore we need not use a CountedElement. Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskadec: Beautify setting default valuesAndreas Rheinhardt2021-02-22
| | | | | Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskadec: Reindent after the previous commitAndreas Rheinhardt2021-02-22
| | | | | Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskadec: Make reading zero-length elements spec-compliantAndreas Rheinhardt2021-02-22
| | | | | | | | | | | | For a very long time, the payload of integer and float elements had to have a length > 0. Our parser treated such invalid elements as having a value zero. But now it has been defined what an EBML element with length zero means: It is a shorthand for the default value. This has also been defined for strings (both ASCII and UTF-8). This commit modifies our parser to support this. Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskadec: Don't use fake default value for ReferenceBlockAndreas Rheinhardt2021-02-22
| | | | | | | | | This has been done in order to find out whether this element is present at all; but this can now be done in a cleaner way by using a CountedElement for it. Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskadec: Check min_luminance more thoroughlyAndreas Rheinhardt2021-02-22
| | | | | | | | | | | | | | | | | | | | In the absence of an explicitly coded minimal luminance, the current code inferred it to be -1, an invalid value. Yet it did not check the value lateron at all, so that if a valid maximum luminance is encountered, but no minimal luminance, an invalid minimal luminance of -1 is exported. If an minimal luminance element with a negative value is present, it is exported, too. This can be simply fixed by adding a check for the value of the element. Yet given that a minimal luminance of zero Cd/m² is legal and can be coded with a length of zero, we must not use a fake default value to find out whether the element is present or not. Therefore this patch uses an explicit counter for it. While just at it, also check for max_luminance > min_luminance. Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avformat/matroskadec: Allow to count the number of element occurencesAndreas Rheinhardt2021-02-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Up until now, the generic EBML reader used by the Matroska demuxer did not have the capability to record whether an element was actually present or not; instead, in cases where it mattered one typically added an invalid default value and checked whether the value is valid (in which case it is guaranteed to be present). This worked pretty well so far, yet the EBML specifications have evolved: It is now legal to use zero-length elements for floats, ints, uints and strings (both ASCII and UTF-8); the value of these elements is the default value of the element (if it has one) or zero for scalar types and an empty string for strings. Furthermore, having a default value does no longer imply that the element may be presumed to be present (with its default value) if it is absent; this is only true if the element is mandatory, too. These rules are designed to allow size savings as follows: Consider the newly added FlagOriginal: It being zero means the track is not in its original language, it being one means it is. For backward compatibility reasons, neither of the two values may be inferred automatically in the absence of the element. But one can still save a byte when one wants to write the element with a value of zero, as one can write the integer with a length of zero: 0x55AE 80 instead of 0x55AE 81 00. In the former case, a parser has to infer the value of the element to be zero (which is the element's default value). When encountering an element with length zero, our parser always infers a value of zero (or an empty string); this is wrong for values with a different default value. It needs to infer the default value (or zero in its absence) and this precludes using an invalid default value for elements like FlagOriginal. Ergo one needs to be able to record whether an element is present or not by other means. This patch allows to use a simple counter for this. While just at it, some invalid and unnecessary default values have been removed (mastering metadata elements used default values of -1.0, despite these elements only being used if they are > 0). Reviewed-by: Ridley Combs <rcombs@rcombs.me> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>