* [FFmpeg-devel] [PATCH] fftools/ffmpeg: avoid possible invalid reads with short -tag values
@ 2023-04-13 13:59 Anton Khirnov
2023-04-13 14:14 ` James Almer
0 siblings, 1 reply; 3+ messages in thread
From: Anton Khirnov @ 2023-04-13 13:59 UTC (permalink / raw)
To: ffmpeg-devel
Fixes #10319.
---
fftools/ffmpeg_demux.c | 8 ++++++--
fftools/ffmpeg_mux_init.c | 7 +++++--
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
index b9849d1669..d89e28b9f6 100644
--- a/fftools/ffmpeg_demux.c
+++ b/fftools/ffmpeg_demux.c
@@ -736,8 +736,12 @@ static void add_input_streams(const OptionsContext *o, Demuxer *d)
MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
if (codec_tag) {
uint32_t tag = strtol(codec_tag, &next, 0);
- if (*next)
- tag = AV_RL32(codec_tag);
+ if (*next) {
+ uint8_t buf[4] = { 0 };
+ memcpy(buf, codec_tag, FFMIN(sizeof(buf), strlen(codec_tag)));
+ tag = AV_RL32(buf);
+ }
+
st->codecpar->codec_tag = tag;
}
diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
index 62e5643a04..aab423464c 100644
--- a/fftools/ffmpeg_mux_init.c
+++ b/fftools/ffmpeg_mux_init.c
@@ -610,8 +610,11 @@ static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o,
MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
if (codec_tag) {
uint32_t tag = strtol(codec_tag, &next, 0);
- if (*next)
- tag = AV_RL32(codec_tag);
+ if (*next) {
+ uint8_t buf[4] = { 0 };
+ memcpy(buf, codec_tag, FFMIN(sizeof(buf), strlen(codec_tag)));
+ tag = AV_RL32(buf);
+ }
ost->st->codecpar->codec_tag = tag;
if (ost->enc_ctx)
ost->enc_ctx->codec_tag = tag;
--
2.39.1
_______________________________________________
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".
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg: avoid possible invalid reads with short -tag values
2023-04-13 13:59 [FFmpeg-devel] [PATCH] fftools/ffmpeg: avoid possible invalid reads with short -tag values Anton Khirnov
@ 2023-04-13 14:14 ` James Almer
2023-04-14 18:56 ` James Almer
0 siblings, 1 reply; 3+ messages in thread
From: James Almer @ 2023-04-13 14:14 UTC (permalink / raw)
To: ffmpeg-devel
On 4/13/2023 10:59 AM, Anton Khirnov wrote:
> Fixes #10319.
> ---
> fftools/ffmpeg_demux.c | 8 ++++++--
> fftools/ffmpeg_mux_init.c | 7 +++++--
> 2 files changed, 11 insertions(+), 4 deletions(-)
>
> diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
> index b9849d1669..d89e28b9f6 100644
> --- a/fftools/ffmpeg_demux.c
> +++ b/fftools/ffmpeg_demux.c
> @@ -736,8 +736,12 @@ static void add_input_streams(const OptionsContext *o, Demuxer *d)
> MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
> if (codec_tag) {
> uint32_t tag = strtol(codec_tag, &next, 0);
> - if (*next)
> - tag = AV_RL32(codec_tag);
> + if (*next) {
> + uint8_t buf[4] = { 0 };
> + memcpy(buf, codec_tag, FFMIN(sizeof(buf), strlen(codec_tag)));
> + tag = AV_RL32(buf);
> + }
> +
> st->codecpar->codec_tag = tag;
> }
>
> diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
> index 62e5643a04..aab423464c 100644
> --- a/fftools/ffmpeg_mux_init.c
> +++ b/fftools/ffmpeg_mux_init.c
> @@ -610,8 +610,11 @@ static OutputStream *new_output_stream(Muxer *mux, const OptionsContext *o,
> MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
> if (codec_tag) {
> uint32_t tag = strtol(codec_tag, &next, 0);
> - if (*next)
> - tag = AV_RL32(codec_tag);
> + if (*next) {
> + uint8_t buf[4] = { 0 };
> + memcpy(buf, codec_tag, FFMIN(sizeof(buf), strlen(codec_tag)));
> + tag = AV_RL32(buf);
> + }
> ost->st->codecpar->codec_tag = tag;
> if (ost->enc_ctx)
> ost->enc_ctx->codec_tag = tag;
LGTM.
_______________________________________________
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".
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg: avoid possible invalid reads with short -tag values
2023-04-13 14:14 ` James Almer
@ 2023-04-14 18:56 ` James Almer
0 siblings, 0 replies; 3+ messages in thread
From: James Almer @ 2023-04-14 18:56 UTC (permalink / raw)
To: ffmpeg-devel
On 4/13/2023 11:14 AM, James Almer wrote:
> On 4/13/2023 10:59 AM, Anton Khirnov wrote:
>> Fixes #10319.
Should also fix #10309 i think.
>> ---
>> fftools/ffmpeg_demux.c | 8 ++++++--
>> fftools/ffmpeg_mux_init.c | 7 +++++--
>> 2 files changed, 11 insertions(+), 4 deletions(-)
>>
>> diff --git a/fftools/ffmpeg_demux.c b/fftools/ffmpeg_demux.c
>> index b9849d1669..d89e28b9f6 100644
>> --- a/fftools/ffmpeg_demux.c
>> +++ b/fftools/ffmpeg_demux.c
>> @@ -736,8 +736,12 @@ static void add_input_streams(const
>> OptionsContext *o, Demuxer *d)
>> MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, ic, st);
>> if (codec_tag) {
>> uint32_t tag = strtol(codec_tag, &next, 0);
>> - if (*next)
>> - tag = AV_RL32(codec_tag);
>> + if (*next) {
>> + uint8_t buf[4] = { 0 };
>> + memcpy(buf, codec_tag, FFMIN(sizeof(buf),
>> strlen(codec_tag)));
>> + tag = AV_RL32(buf);
>> + }
>> +
>> st->codecpar->codec_tag = tag;
>> }
>> diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c
>> index 62e5643a04..aab423464c 100644
>> --- a/fftools/ffmpeg_mux_init.c
>> +++ b/fftools/ffmpeg_mux_init.c
>> @@ -610,8 +610,11 @@ static OutputStream *new_output_stream(Muxer
>> *mux, const OptionsContext *o,
>> MATCH_PER_STREAM_OPT(codec_tags, str, codec_tag, oc, st);
>> if (codec_tag) {
>> uint32_t tag = strtol(codec_tag, &next, 0);
>> - if (*next)
>> - tag = AV_RL32(codec_tag);
>> + if (*next) {
>> + uint8_t buf[4] = { 0 };
>> + memcpy(buf, codec_tag, FFMIN(sizeof(buf),
>> strlen(codec_tag)));
>> + tag = AV_RL32(buf);
>> + }
>> ost->st->codecpar->codec_tag = tag;
>> if (ost->enc_ctx)
>> ost->enc_ctx->codec_tag = tag;
>
> LGTM.
_______________________________________________
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".
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-04-14 18:57 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-13 13:59 [FFmpeg-devel] [PATCH] fftools/ffmpeg: avoid possible invalid reads with short -tag values Anton Khirnov
2023-04-13 14:14 ` James Almer
2023-04-14 18:56 ` James Almer
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