From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH v7 1/5] avformat/subtitles: extend ff_subtitles_queue_insert() to support empty events
Date: Thu, 21 Mar 2024 17:22:52 +0100
Message-ID: <GV1P250MB07379ADE02BF44AEA46E63C58F322@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <20240321035207.3849560-2-marth64@proxyid.net>
Marth64:
> If ff_subtitles_queue_insert() were to given a NULL buffer
> with 0 length, it would still attempt to grow the packet
> or memcpy depending on if merge option is enabled.
>
> In this commit, consider a NULL buffer with 0 length as
> an empty event and do not attempt to modify the packet.
> This way, if a subtitle demuxer happens to pass an empty
> cue or wants to use av_get_packet() to read bytes, there
> are no unnecessary operations on the packet after it is
> allocated.
>
> Signed-off-by: Marth64 <marth64@proxyid.net>
> ---
> libavformat/subtitles.c | 4 ++++
> libavformat/subtitles.h | 2 +-
> 2 files changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/libavformat/subtitles.c b/libavformat/subtitles.c
> index 3413763c7b..38d2ffb8a9 100644
> --- a/libavformat/subtitles.c
> +++ b/libavformat/subtitles.c
> @@ -117,6 +117,8 @@ AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q,
> int old_len;
> sub = q->subs[q->nb_subs - 1];
> old_len = sub->size;
> + if (event == NULL && len == 0)
> + return sub;
Checks for NULL are typically written as !event. I'd prefer
if (!event) {
av_assert1(len == 0);
return sub;
}
as this also makes clear that !event with len > 0 must not happen and
also avoids one runtime check for ordinary users (with assert-level 0).
> if (av_grow_packet(sub, len) < 0)
> return NULL;
> memcpy(sub->data + old_len, event, len);
> @@ -140,6 +142,8 @@ AVPacket *ff_subtitles_queue_insert(FFDemuxSubtitlesQueue *q,
> subs[q->nb_subs++] = sub;
> sub->flags |= AV_PKT_FLAG_KEY;
> sub->pts = sub->dts = 0;
> + if (event == NULL && len == 0)
> + return sub;
> memcpy(sub->data, event, len);
This will allocate sub->data to a buffer of size
AV_INPUT_BUFFER_PADDING_SIZE and usable size of zero. This is not what
is intended: You should not allocate anything at all, i.e. skip
av_new_packet().
This small buffer (together with the AVBuffer and AVBufferRef allocated
for it) will leak with your current patch 2.
> }
> return sub;
> diff --git a/libavformat/subtitles.h b/libavformat/subtitles.h
> index 88665663c5..ba162fa503 100644
> --- a/libavformat/subtitles.h
> +++ b/libavformat/subtitles.h
> @@ -112,7 +112,7 @@ typedef struct {
> /**
> * Insert a new subtitle event.
> *
> - * @param event the subtitle line, may not be zero terminated
> + * @param event the subtitle line (not zero terminated), or NULL on empty event
on not yet available event
> * @param len the length of the event (in strlen() sense, so without '\0')
> * @param merge set to 1 if the current event should be concatenated with the
> * previous one instead of adding a new entry, 0 otherwise
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-03-21 16:23 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-21 3:52 [FFmpeg-devel] [PATCH v7 0/5] RCWT Closed Captions demuxer (meta) Marth64
2024-03-21 3:52 ` [FFmpeg-devel] [PATCH v7 1/5] avformat/subtitles: extend ff_subtitles_queue_insert() to support empty events Marth64
2024-03-21 3:54 ` Marth64
2024-03-21 16:22 ` Andreas Rheinhardt [this message]
2024-03-21 16:53 ` Marth64
2024-03-21 3:52 ` [FFmpeg-devel] [PATCH v7 2/5] avformat/rcwtdec: add RCWT Closed Captions demuxer Marth64
2024-03-21 4:16 ` [FFmpeg-devel] [PATCH v8] " Marth64
2024-03-21 16:12 ` [FFmpeg-devel] [PATCH v7 2/5] " Andreas Rheinhardt
2024-03-21 3:52 ` [FFmpeg-devel] [PATCH v7 3/5] avformat/rcwtenc: remove repeated documentation Marth64
2024-03-21 3:52 ` [FFmpeg-devel] [PATCH v7 4/5] doc/muxers: refresh the RCWT muxer's doc to be consistent with the demuxer Marth64
2024-03-21 3:52 ` [FFmpeg-devel] [PATCH v7 5/5] doc/indevs: update CC extraction example to use RCWT muxer Marth64
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=GV1P250MB07379ADE02BF44AEA46E63C58F322@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM \
--to=andreas.rheinhardt@outlook.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git