summaryrefslogtreecommitdiff
path: root/libavcodec/movtextdec.c
Commit message (Collapse)AuthorAge
* avcodec/codec_internal: Constify AVPacket in decode_sub cbAndreas Rheinhardt2022-04-05
| | | | | | No subtitle decoder ever modifies the AVPacket given to it. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal: Use union for FFCodec decode/encode callbacksAndreas Rheinhardt2022-04-05
| | | | | | | | | | | This is possible, because every given FFCodec has to implement exactly one of these. Doing so decreases sizeof(FFCodec) and therefore decreases the size of the binary. Notice that in case of position-independent code the decrease is in .data.rel.ro, so that this translates to decreased memory consumption. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal: Add FFCodec.decode_subAndreas Rheinhardt2022-04-05
| | | | | | | | | This increases type-safety by avoiding conversions from/through void*. It also avoids the boilerplate "AVSubtitle *sub = data;" line for subtitle decoders. Its only downside is that it increases sizeof(FFCodec), yet this can be more than offset lateron. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/codec_internal: Add FFCodec, hide internal part of AVCodecAndreas Rheinhardt2022-03-21
| | | | | | | | | | | | | | | | Up until now, codec.h contains both public and private parts of AVCodec. This exposes the internals of AVCodec to users and leads them into the temptation of actually using them and forces us to forward-declare structures and types that users can't use at all. This commit changes this by adding a new structure FFCodec to codec_internal.h that extends AVCodec, i.e. contains the public AVCodec as first member; the private fields of AVCodec are moved to this structure, leaving codec.h clean. Reviewed-by: Anton Khirnov <anton@khirnov.net> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/internal: Move FF_CODEC_CAP_* to a new header codec_internal.hAndreas Rheinhardt2022-03-21
| | | | | | | | | | Also move FF_CODEC_TAGS_END as well as struct AVCodecDefault. This reduces the amount of files that have to include internal.h (which comes with quite a lot of indirect inclusions), as e.g. most encoders don't need it. It is furthemore in preparation for moving the private part of AVCodec out of the public codec.h. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/movtextdec: add () to CMP() macro to avoid unexpected behaviorMichael Niedermayer2022-02-25
| | | | | Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/movtextdec: Fix wrong error codeAndreas Rheinhardt2021-12-11
| | | | | Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/movtextdec: Switch to pointer comparisons and bytestream APIAndreas Rheinhardt2021-12-11
| | | | | | | | Improves readability and avoids a redundant index variable that was mistakenly called "tracksize". Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/movtextdec: Redo TextSampleModifierBox size checksAndreas Rheinhardt2021-12-11
| | | | | | | | | | | | The current checks just check whether the boxes fit into the remaining size of the packet instead of whether they actually fit into the box size. This has been changed; part of this change is to pass the size of the box (minus the box header) as parameter instead of a pointer to the AVPacket by which the box parsing function is supposed to recalculate whether enough data is available. Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/movtextdec: Use const where appropriateAndreas Rheinhardt2021-12-11
| | | | | Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/movtextdec: Improve size checkAndreas Rheinhardt2021-12-11
| | | | | Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/movtextdec: Switch to smaller typeAndreas Rheinhardt2021-12-11
| | | | | | | | | | The base size of a box refers to the size the box has in a file, not in memory; so size_t is not their natural type. Therefore use a plain unsigned which is smaller on 64bit systems and still big enough to represent any conceivable base size. Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/movtextdec: Sanitize style entriesAndreas Rheinhardt2021-12-08
| | | | | | | | | | | | | | | | | | | | | There are three types of style entries which are redundant: a) Entries with length zero. They are already discarded. b) Entries that are equivalent to the default style: They can be safely discarded. c) Entries that are equivalent to the immediately preceding style if the start of the current style coincides with the end of the preceding style. In this case the styles can be merged. This commit implements discarding/merging in cases b) and c). This fixes ticket #9548. In said ticket each packet contained exactly one style entry that covered the complete packet with the exception of the last character (probably created by a tool that didn't know that the style's end is exclusive). Said style coincided with the default style, leading to a superfluous reset, which is now gone. Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/movtextdec: Perform RGB->BGR color conversion earlyAndreas Rheinhardt2021-12-08
| | | | | | | Reduces the amount of conversions. Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/movtextdec: Deduplicate parsing of StyleRecordsAndreas Rheinhardt2021-12-08
| | | | | | | | | Both TextSampleEntry and TextSample can contain StyleRecords; yet both the code as well as the structures for them were duplicated. This commit changes this. Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec/movtextdec: Rename several structure elementsAndreas Rheinhardt2021-12-08
| | | | | | | | | Giving elements of a structure called StyleBox names like "style_start" or "style_end" is redundant, especially given that the relevant variables are also called style. Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
* avcodec: Mark ff_ass_subtitle_header based decoders as init-threadsafeAndreas Rheinhardt2021-05-02
| | | | | | | ff_ass_subtitle_header_full() just uses av_asprintf() and is therefore thread-safe itself. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec: Constify AVCodecsAndreas Rheinhardt2021-04-27
| | | | | | | | | | Given that the AVCodec.next pointer has now been removed, most of the AVCodecs are not modified at all any more and can therefore be made const (as this patch does); the only exceptions are the very few codecs for external libraries that have a init_static_data callback. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com> Signed-off-by: James Almer <jamrial@gmail.com>
* avcodec: Constify some AVPacketsAndreas Rheinhardt2021-03-09
| | | | | Reviewed-by: James Almer <jamrial@gmail.com> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/movtextdec: ReindentationAndreas Rheinhardt2020-10-19
| | | | | Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/movtextdec: Use bytestream APIAndreas Rheinhardt2020-10-19
| | | | | | | Improves readability. Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/movtextdec: Avoid loop when writing UTF-8 character to AVBPrintAndreas Rheinhardt2020-10-19
| | | | | Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/movtextdec: Remove unnecessary variableAndreas Rheinhardt2020-10-19
| | | | | | | | style_active doesn't do anything any more: It is already assured that style_active is one when one reaches the end of a style. Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/movtextdec: Fix immediately adjacent stylesAndreas Rheinhardt2020-10-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | The checks for whether a style should be opened/closed at the current character position are as follows: A variable entry contained the index of the currently active or potentially next active style. If the current character position coincided with the start of style[entry], the style was activated; this was followed by a check whether the current character position coincided with the end of style[entry]; if so, the style was deactivated and entry incremented. Afterwards the char was processed. The order of the checks leads to problems in case the endChar of style A coincides with the startChar of the next style (say B): Style B was never opened. When we are at said common position, the currently active style is A and so the start pos check does not succeed; but the end pos check does and it closes the currently active style A and increments entry. At the next iteration of the loop, the current character position is bigger than the start position of style B (which is style[entry]) and therefore the style is not activated. The solution is of course to first check for whether a style needs to be closed (and increment entry if it does) before checking whether the next style needs to be opened. Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/movtextdec: Skip empty stylesAndreas Rheinhardt2020-10-19
| | | | | | | | | | | | | | | They would either lead to unnecessary ASS tags being emitted (namely tags that are reset immediately thereafter) or would lead to problems when parsing: e.g. if a zero-length style immediately follows another style, the current code will end the preceding style and set the zero-length style as the next potentially active style, but it is only tested for activation when the next character is parsed at which point the current offset is already greater than both the starting as well as the end offset of the empty style. It will therefore neither be opened nor closed and all subsequent styles will be ignored. Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/movtextdec: Fix leaks on (re)allocation failureAndreas Rheinhardt2020-10-19
| | | | | | | | | | | | | | | | | | | | | Up until now, the 3GPP Timed Text decoder used av_dynarray_add() for a list of style entries. Said entries are individually allocated and owned by the pointers in the dynamic array and are therefore unsuitable for av_dynarray_add() which simply frees the array, but not the entries on error. In this case the intended new entry also leaks because it has been forgotten to free it. This commit fixes this. It is now allocated in one go and not reallocated multiple times (and it won't be overallocated any more). After all, the final number of elements (pending errors) is already known in advance. Furthermore, the style entries are now the entries of the new array, i.e. they are no longer allocated separately. This also removes one level of indirection. Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/movtextdec: Simplify finding default fontAndreas Rheinhardt2020-10-19
| | | | | | | There is no need to walk through the list of fonts twice. Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/movtextdec: Simplify checking for invalid extradataAndreas Rheinhardt2020-10-19
| | | | | | | | | Every font entry occupies at least three bytes, so checking early whether there is that much data available is a low-effort way to exclude invalid extradata. Doing so leads to an overall simplification. Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/movtextdec: Fix leaks of strings upon reallocation failureAndreas Rheinhardt2020-10-19
| | | | | | | | | | | | | | | | | | | | Up until now, the 3GPP Timed Text decoder used av_dynarray_add() for a list of font entries, a structure which contains an allocated string. The font entries are owned by the pointers in the dynamic array and are therefore unsuitable for av_dynarray_add() which simply frees the array, but not the font entries and of course not the strings. The latter all leak if reallocating the dynamic array fails. This commit fixes this. It stops reallocating the array altogether: After all, the final number of elements (pending errors) is already known in advance. Furthermore, the font entries are now the entries of the new array, i.e. the font entries are no longer allocated separately. This also removes one level of indirection. Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/movtextdec: Reset counter of fonts when freeing themAndreas Rheinhardt2020-10-19
| | | | | | | | | | | If allocating fonts fails when reading the header, all fonts are freed, yet the counter of fonts is not reset and no error is returned; when subtitles are decoded lateron, the inexistent list of fonts is searched for the matching font for this particular entry which of course leads to a segfault. Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
* avcodec/movtextdec: Fix shift overflows in mov_text_init()Michael Niedermayer2020-06-11
| | | | | | | | Fixes: left shift of 243 by 24 places cannot be represented in type 'int' Fixes: 22716/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MOVTEXT_fuzzer-5704263425851392 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* lavc/movtextdec: allow setting subtitle frame dimensionsJohn Stebbins2020-04-10
| | | | | | | | Font sizes are relative to the subtitle frame dimensions. If the expected frame dimensions are not known, the font sizes will most likely be incorrect. Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextdec: restore active style color after hiliteJohn Stebbins2020-04-10
| | | | Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextdec: add color and alpha style tagsJohn Stebbins2020-04-10
| | | | Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextdec: add alpha default to ass header colorsJohn Stebbins2020-04-10
| | | | Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextdec: make sure default font name is setJohn Stebbins2020-04-10
| | | | Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextdec: only write fontsize, fontID tags if not defaultJohn Stebbins2020-04-10
| | | | Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextdec: handle changes to default style flagsJohn Stebbins2020-04-10
| | | | | | | Style flags were only being turned on. If the default was on and style record turned off, style flag remained on. Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextdec: fix bold, italic, underline flagsJohn Stebbins2020-04-10
| | | | | | They should be 0 or 1 so that 0 or -1 is written to the ass header Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextdec: simplify style record walkJohn Stebbins2020-04-10
| | | | | | | It's not necessary to walk the style record list twice per subtitle character. style records are in order and do not overlap. Signed-off-by: Philip Langdale <philipl@overt.org>
* lavc/movtextdec: fix ass header colorsJohn Stebbins2020-04-10
| | | | | | A conversion from rgb to bgr is necessary Signed-off-by: Philip Langdale <philipl@overt.org>
* avcodec/movtextdec: Check style_start/endMichael Niedermayer2018-04-09
| | | | | | | | | | Limits based on 3GPP TS 26.245 V14.0.0 Fixes: Timeout Fixes: 6377/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_MOVTEXT_fuzzer-5175929115508736 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg Reviewed-by: Philip Langdale <philipl@overt.org> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* movtextdec: fix handling of UTF-8 subtitleswm42018-03-25
| | | | | | | | | | | | | | | | Subtitles which contained styled UTF-8 subtitles (i.e. not just 7 bit ASCII characters) were not handled correctly. The spec mandates that styling start/end ranges are in "characters". It's not quite clear what a "character" is supposed to be, but maybe they mean unicode codepoints. FFmpeg's decoder treated the style ranges as byte idexes, which could lead to UTF-8 sequences being broken, and the common code dropping the whole subtitle line. Change this and count the codepoint instead. This also means that even if this is somehow wrong, the decoder won't break UTF-8 sequences anymore. The sample which led me to investigate this now appears to work correctly.
* movtextdec: Move declaration out of for initialisation statementMark Thompson2017-10-21
|
* avcodec/movtextdec: run mov_text_cleanup() before overwriting pointersMichael Niedermayer2017-03-09
| | | | | | | | Fixes: memleak Fixes: 741/clusterfuzz-testcase-586996200452915 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/movtextdec: Call mov_text_cleanup() on closeMichael Niedermayer2017-03-06
| | | | | | | | Fixes memleak Fixes: 548/clusterfuzz-testcase-5511470875934720 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/movtextdec: Fix decode_styl() cleanupMichael Niedermayer2017-02-06
| | | | | | | | Fixes: null pointer dereference Fixes: 555/clusterfuzz-testcase-5986646595993600 Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/movtextdec: Add error message for tsmb_size checkMichael Niedermayer2016-11-15
| | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/movtextdec: Fix tsmb_size check==0 checkMichael Niedermayer2016-11-15
| | | | | | | Fixes: 173/fuzz-3-ffmpeg_SUBTITLE_AV_CODEC_ID_MOV_TEXT_fuzzer Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/targets/ffmpeg Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
* avcodec/movtextdec: Fix potential integer overflowMichael Niedermayer2016-11-15
| | | | Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>