Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClément Bœsch <ubitux@gmail.com>2012-12-30 02:26:36 +0400
committerClément Bœsch <ubitux@gmail.com>2012-12-31 03:41:35 +0400
commit1f265f52050e967d78e29d8e115c7dc849b14c4e (patch)
treec35814a7a10c70da45ef5700bd6b401a59558ba0 /libavcodec/microdvddec.c
parentfaa94061dd7236cbaabd483e7b2df148cdbefb7f (diff)
microdvd: sanitize AVPackets.
Current MicroDVD AVPackets contain timing information and trailing line breaks. The data is now only composed of the markup data. Doing this consistently between text subtitles decoders allows to use different codec for various formats. For instance, MicroDVD markup is sometimes found in some VPlayer files. Also, generally speaking, the subtitles text decoders have no use of these timings (and they must not use them since it would break any user timing adjustment). Technically, this is a major ABI break. In practice, a mismatching lavf/lavc will now error out for MicroDVD decoding. Supporting both formats requires unnecessary complex and fragile code. FATE needs update because line breaks in the ASS file were "\n" (because that's what is used in the original file). ASS format expect "\r\n" line breaks; this commit fixes this issue. Also note that this "\r\n" trailing need to be moved at some point from the decoders to the ASS muxer.
Diffstat (limited to 'libavcodec/microdvddec.c')
-rw-r--r--libavcodec/microdvddec.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/libavcodec/microdvddec.c b/libavcodec/microdvddec.c
index e08cc312c0..f3c640f932 100644
--- a/libavcodec/microdvddec.c
+++ b/libavcodec/microdvddec.c
@@ -260,6 +260,7 @@ static int microdvd_decode_frame(AVCodecContext *avctx,
{
AVSubtitle *sub = data;
AVBPrint new_line;
+ char c;
char *decoded_sub;
char *line = avpkt->data;
char *end = avpkt->data + avpkt->size;
@@ -268,11 +269,16 @@ static int microdvd_decode_frame(AVCodecContext *avctx,
if (avpkt->size <= 0)
return avpkt->size;
- av_bprint_init(&new_line, 0, 2048);
+ /* To be removed later */
+ if (sscanf(line, "{%*d}{%*[0123456789]}%c", &c) == 1 &&
+ line[avpkt->size - 1] == '\n') {
+ av_log(avctx, AV_LOG_ERROR, "AVPacket is not clean (contains timing "
+ "information and a trailing line break). You need to upgrade "
+ "your libavformat or sanitize your packet.\n");
+ return AVERROR_INVALIDDATA;
+ }
- // skip {frame_start}{frame_end}
- line = strchr(line, '}'); if (!line) goto end; line++;
- line = strchr(line, '}'); if (!line) goto end; line++;
+ av_bprint_init(&new_line, 0, 2048);
// subtitle content
while (line < end && *line) {
@@ -294,8 +300,9 @@ static int microdvd_decode_frame(AVCodecContext *avctx,
line++;
}
}
+ if (new_line.len) {
+ av_bprintf(&new_line, "\r\n");
-end:
av_bprint_finalize(&new_line, &decoded_sub);
if (*decoded_sub) {
int64_t start = avpkt->pts;
@@ -306,6 +313,7 @@ end:
ff_ass_add_rect(sub, decoded_sub, ts_start, ts_duration, 0);
}
av_free(decoded_sub);
+ }
*got_sub_ptr = sub->num_rects > 0;
return avpkt->size;