Fixing an invalid read & font detection

This commit is contained in:
Zoe Roux
2020-10-29 23:55:37 +01:00
parent 10cc69a261
commit 0bb45a356f
4 changed files with 8 additions and 6 deletions

View File

@@ -13,4 +13,4 @@ int open_input_context(AVFormatContext **inputContext, const char *path);
AVStream *copy_stream_to_output(AVFormatContext *out_ctx, AVStream *in_stream);
int open_output_file_for_write(AVFormatContext *out_ctx, const char *out_path, AVDictionary **options);
void process_packet(AVPacket *pkt, AVStream *in_stream, AVStream *out_stream);
type type_fromffmpeg(int type);
type type_fromffmpeg(AVStream *stream);

View File

@@ -62,9 +62,9 @@ void process_packet(AVPacket *pkt, AVStream *in_stream, AVStream *out_stream)
pkt->pos = -1;
}
type type_fromffmpeg(int type)
type type_fromffmpeg(AVStream *stream)
{
switch (type)
switch (stream->codecpar->codec_type)
{
case AVMEDIA_TYPE_VIDEO:
return video;
@@ -73,7 +73,9 @@ type type_fromffmpeg(int type)
case AVMEDIA_TYPE_SUBTITLE:
return subtitle;
case AVMEDIA_TYPE_ATTACHMENT:
return font;
if (!strcmp(avcodec_get_name(stream->codecpar->codec_id), "ttf"))
return font;
return none;
default:
return none;
}

View File

@@ -85,7 +85,7 @@ stream *extract_infos(const char *path, const char *out_path, unsigned *stream_c
if (output_list && streams) {
for (unsigned i = 0; i < *stream_count; i++) {
AVStream *stream = ctx->streams[i];
type stream_type = type_fromffmpeg(stream->codecpar->codec_type);
type stream_type = type_fromffmpeg(stream);
if (stream_type != none) {
*track_count += 1;

View File

@@ -80,7 +80,7 @@ void extract_font(stream *font, const char *out_path, AVStream *stream)
if (!filename)
return;
free(font->path);
font->path = malloc((strlen(out_path) + 7 + strlen(filename->value)) * sizeof(char));
font->path = malloc((strlen(out_path) + 8 + strlen(filename->value)) * sizeof(char));
if (!font->path)
return;
strcpy(font->path, out_path);