[FFmpeg-devel] [PATCH] avformat/concat: finalize the AVBprint buffer immediately
James Almer
jamrial at gmail.com
Tue Jul 27 05:04:10 EEST 2021
On 7/26/2021 6:49 PM, Marton Balint wrote:
>
>
> On Mon, 26 Jul 2021, James Almer wrote:
>
>> Don't attempt to read its contents in place.
>> Fixes invalid reads when run under Valgrind.
>
> As far as I remember AVBPrint buffer CAN be read in place by design,
> zero terminator is always guaranteed, not only after finalizing. So this
> should not be needed. What is causing the invalid reads exactly?
>
> Thanks,
> Marton
It happens only when you use a URI string that doesn't end with a line
break. I just noticed that after this patch some invalid reads still
happen in any case.
I think i found out the culprit, and the following seems to fix it:
> diff --git a/libavformat/concat.c b/libavformat/concat.c
> index aec1f52d8e..94917840c6 100644
> --- a/libavformat/concat.c
> +++ b/libavformat/concat.c
> @@ -251,7 +251,7 @@ static av_cold int concatf_open(URLContext *h, const char *uri, int flags)
> err = AVERROR(ENOMEM);
> break;
> }
> - cursor++;
> + if (*cursor) cursor++;
>
> if (++len == SIZE_MAX / sizeof(*nodes)) {
> av_free(node_uri);
Basically, av_get_token() returns a pointer to the terminating
character, so cursor++ for the next loop when said character was \0 was
wrong.
More information about the ffmpeg-devel
mailing list