1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00
Commit Graph

60 Commits

Author SHA1 Message Date
Andreas Rheinhardt
9018257751 avcodec/movtextdec: Reindentation
Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-19 05:15:00 +02:00
Andreas Rheinhardt
71981d7d4d avcodec/movtextdec: Use bytestream API
Improves readability.

Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-19 05:13:00 +02:00
Andreas Rheinhardt
ba795890ec avcodec/movtextdec: Avoid loop when writing UTF-8 character to AVBPrint
Reviewed-by: Philip Langdale <philipl@overt.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
2020-10-19 05:09:00 +02:00
Andreas Rheinhardt
c84a91eff7 avcodec/movtextdec: Remove unnecessary variable
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>
2020-10-19 05:08:02 +02:00
Andreas Rheinhardt
dd80066c97 avcodec/movtextdec: Fix immediately adjacent styles
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>
2020-10-19 05:03:39 +02:00
Andreas Rheinhardt
40c16907bb avcodec/movtextdec: Skip empty styles
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>
2020-10-19 05:02:00 +02:00
Andreas Rheinhardt
94ad68ee17 avcodec/movtextdec: Fix leaks on (re)allocation failure
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>
2020-10-19 04:59:08 +02:00
Andreas Rheinhardt
c33b9fa74b avcodec/movtextdec: Simplify finding default font
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>
2020-10-19 04:58:30 +02:00
Andreas Rheinhardt
a42695c072 avcodec/movtextdec: Simplify checking for invalid extradata
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>
2020-10-19 04:56:32 +02:00
Andreas Rheinhardt
38cdd27e9b avcodec/movtextdec: Fix leaks of strings upon reallocation failure
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>
2020-10-19 04:52:48 +02:00
Andreas Rheinhardt
5758620560 avcodec/movtextdec: Reset counter of fonts when freeing them
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>
2020-10-19 04:49:57 +02:00
Michael Niedermayer
d7a2311a2c avcodec/movtextdec: Fix shift overflows in mov_text_init()
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>
2020-06-11 13:49:54 +02:00
John Stebbins
b8d4a66b29 lavc/movtextdec: allow setting subtitle frame dimensions
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>
2020-04-10 09:32:13 -07:00
John Stebbins
f406dc9ceb lavc/movtextdec: restore active style color after hilite
Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 09:32:13 -07:00
John Stebbins
032ad7a0bb lavc/movtextdec: add color and alpha style tags
Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 09:32:13 -07:00
John Stebbins
91447ae3ba lavc/movtextdec: add alpha default to ass header colors
Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 09:32:13 -07:00
John Stebbins
c0d3fea600 lavc/movtextdec: make sure default font name is set
Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 09:32:13 -07:00
John Stebbins
e5b99df096 lavc/movtextdec: only write fontsize, fontID tags if not default
Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 09:32:13 -07:00
John Stebbins
d3c012ff42 lavc/movtextdec: handle changes to default style flags
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>
2020-04-10 09:32:13 -07:00
John Stebbins
5f39f63a65 lavc/movtextdec: fix bold, italic, underline flags
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>
2020-04-10 09:32:13 -07:00
John Stebbins
2949f17e99 lavc/movtextdec: simplify style record walk
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>
2020-04-10 09:32:13 -07:00
John Stebbins
47e88adc0d lavc/movtextdec: fix ass header colors
A conversion from rgb to bgr is necessary

Signed-off-by: Philip Langdale <philipl@overt.org>
2020-04-10 09:32:13 -07:00
Michael Niedermayer
249aca8f98 avcodec/movtextdec: Check style_start/end
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>
2018-04-09 03:09:08 +02:00
wm4
b0644c3e1a movtextdec: fix handling of UTF-8 subtitles
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.
2018-03-25 19:27:02 +02:00
Mark Thompson
e7d20d5e35 movtextdec: Move declaration out of for initialisation statement 2017-10-21 22:19:50 +01:00
Michael Niedermayer
bac9c03ed9 avcodec/movtextdec: run mov_text_cleanup() before overwriting pointers
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>
2017-03-09 23:28:10 +01:00
Michael Niedermayer
a9f9b7f5c7 avcodec/movtextdec: Call mov_text_cleanup() on close
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>
2017-03-06 16:47:17 +01:00
Michael Niedermayer
e248522d1b avcodec/movtextdec: Fix decode_styl() cleanup
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>
2017-02-06 11:19:05 +01:00
Michael Niedermayer
0eb3198005 avcodec/movtextdec: Add error message for tsmb_size check
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-11-15 15:08:20 +01:00
Michael Niedermayer
a609905723 avcodec/movtextdec: Fix tsmb_size check==0 check
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>
2016-11-15 15:08:20 +01:00
Michael Niedermayer
6ea2715768 avcodec/movtextdec: Fix potential integer overflow
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2016-11-15 15:08:20 +01:00
Sasi Inguva
7e9e1b7070 lavc/movtextdec.c: Avoid infinite loop on invalid data.
Signed-off-by: Sasi Inguva <isasi@google.com>
2016-09-27 19:49:02 -07:00
Clément Bœsch
30e7685360 lavc/options: add ass_ro_flush_noop to flags2 2016-02-26 21:53:32 +01:00
Clément Bœsch
2941282124 lavc: allow subtitle text format to be ASS without timing 2016-02-26 21:49:34 +01:00
Clément Bœsch
6d32628bf3 lavc/ccaption_dec: improve default style
Use monospaced font, and a black box outline.
2016-01-10 16:28:14 +01:00
Michael Niedermayer
a047ccbb9f avcodec/movtextdec: Free ftab_temp
Fixes memleak
Fixes: efe937780e95574250dabe07151bdc23/unknown_unknown_351_849_cov_3187578556_shellymanne.mov

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-08-31 23:44:39 +02:00
Michael Niedermayer
a1a32fdb0e avcodec/movtextdec: Make tx3g_ptr unsigned
Fixes integer overflow
Fixes: efe937780e95574250dabe07151bdc23/unknown_unknown_351_849_cov_3187578556_shellymanne.mov

Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-08-31 23:44:39 +02:00
Niklesh
a604289b85 movtextdec: Add support for automatic text wrapping
The value of wrap_flag in the Text Wrap Box specifies if the text is to
be wrapped or not. Uses 'end of line wrap' amongst the wrap styles
supported by ASS if the text is to be wrapped, i.e; fill as much text
in a line as possible, then break to next line.

The 3GPP spec has no provision for smart wrapping.

Signed-off-by: Niklesh <niklesh.lalwani@iitb.ac.in>
2015-08-14 19:35:26 -07:00
Niklesh
1bf8f54274 movtextdec: Use default style information from movtext header
As suggested, posting the combined patch with the fate changes.
The patch sets the default style in ASS from the default style
information present in the movtext header.

Signed-off-by: Niklesh <niklesh.lalwani@iitb.ac.in>
2015-08-12 14:43:19 -07:00
Michael Niedermayer
0eb896b38d Revert "movtextdec: Use default style information from movtext header"
The commit broke  sub-movtext and sub-subripenc
fate output differs between mips ad x86 so updating fate ref is not
possible

This reverts commit d670848d4c.
2015-08-10 02:09:14 +02:00
Niklesh
d670848d4c movtextdec: Use default style information from movtext header
Signed-off-by: Niklesh <niklesh.lalwani@iitb.ac.in>
2015-08-09 15:12:15 -07:00
Niklesh
ecc806a224 movtextdec: Fix memory leaks by freeing mem allocs correctly
Initialize m->count_f to 0 at the correct place to free memory allocs properly.

Signed-off-by: Niklesh <niklesh.lalwani@iitb.ac.in>
2015-08-07 16:33:31 -07:00
Michael Niedermayer
ae413a48e6 avcodec/movtextdec: check that ftab has been allocated before dereferencing it
Fixes potential null pointer dereference on deallocation

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
2015-08-06 23:38:55 +02:00
Niklesh
2e7a684e72 movtextdec.c: Add support for font names
Signed-off-by: Niklesh <niklesh.lalwani@iitb.ac.in>
2015-08-06 08:42:09 -07:00
Niklesh
f21fcf60ec movtextdec.c: Add support for fontsize
Add support for fontsize in style records. The patch uses reset to
directly change back to default style instead of using closing tags,
since we are not handling the default styles right now.

Signed-off-by: Niklesh <niklesh.lalwani@iitb.ac.in>
2015-07-26 09:35:20 -07:00
Niklesh
a927aacbe6 movtextdec.c: Correct the highlight tags
Signed-off-by: Niklesh <niklesh.lalwani@iitb.ac.in>
2015-07-20 08:16:19 -07:00
Niklesh
774ceee17e movtextdec.c: Add support for highlight and hilightcolor box
Signed-off-by: Niklesh <niklesh.lalwani@iitb.ac.in>
2015-07-12 10:24:17 -07:00
Niklesh
813b2f0da3 movtextdec.c: Improve upon dynarrays and text_to_ass
Signed-off-by: Niklesh <niklesh.lalwani@iitb.ac.in>
2015-06-22 22:19:35 -07:00
Niklesh
9aabc926ca Improve upon dynamic arrays- movtext subtitles
Signed-off-by: Niklesh <niklesh.lalwani@iitb.ac.in>
2015-05-25 11:39:29 -07:00
Niklesh
337aa17e61 avcodec/movtextdec: Add support for large boxes(>32 bit)
Signed-off-by: Niklesh <niklesh.lalwani@iitb.ac.in>
2015-05-22 08:32:20 -07:00