* [FFmpeg-devel] [PATCH] avformat/mov: free the infe allocated item data on failure
@ 2024-04-27 1:01 James Almer
2024-04-27 23:17 ` [FFmpeg-devel] [PATCH v2] " James Almer
0 siblings, 1 reply; 4+ messages in thread
From: James Almer @ 2024-04-27 1:01 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/mov.c | 26 +++++++++++++++++++++-----
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/libavformat/mov.c b/libavformat/mov.c
index e52a83c82e..49dd82a4d1 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -84,6 +84,7 @@ typedef struct MOVParseTableEntry {
static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom);
static int mov_read_mfra(MOVContext *c, AVIOContext *f);
+static void mov_free_stream_context(AVFormatContext *s, AVStream *st);
static int64_t add_ctts_entry(MOVCtts** ctts_data, unsigned int* ctts_count, unsigned int* allocated_size,
int count, int duration);
@@ -8201,7 +8202,7 @@ static int mov_read_iinf(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
HEIFItem *heif_item;
int entry_count;
- int version, ret;
+ int version, ret, i;
if (c->found_iinf) {
av_log(c->fc, AV_LOG_WARNING, "Duplicate iinf box found\n");
@@ -8221,20 +8222,35 @@ static int mov_read_iinf(MOVContext *c, AVIOContext *pb, MOVAtom atom)
sizeof(*c->heif_item) * (entry_count - c->nb_heif_item));
c->nb_heif_item = FFMAX(c->nb_heif_item, entry_count);
- for (int i = 0; i < entry_count; i++) {
+ for (i = 0; i < entry_count; i++) {
MOVAtom infe;
infe.size = avio_rb32(pb) - 8;
infe.type = avio_rl32(pb);
ret = mov_read_infe(c, pb, infe, i);
if (ret < 0)
- return ret;
- if (ret)
- return 0;
+ goto fail;
+ if (ret) {
+ ret = 0;
+ goto fail;
+ }
}
c->found_iinf = 1;
return 0;
+fail:
+ for (; i >= 0; i--) {
+ HEIFItem *item = &c->heif_item[i];
+
+ av_freep(&item->name);
+ if (!item->st)
+ continue;
+
+ mov_free_stream_context(c->fc, item->st);
+ ff_remove_stream(c->fc, item->st);
+ item->st = NULL;
+ }
+ return ret;
}
static int mov_read_iref_dimg(MOVContext *c, AVIOContext *pb, int version)
--
2.44.0
_______________________________________________
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] 4+ messages in thread
* [FFmpeg-devel] [PATCH v2] avformat/mov: free the infe allocated item data on failure
2024-04-27 1:01 [FFmpeg-devel] [PATCH] avformat/mov: free the infe allocated item data on failure James Almer
@ 2024-04-27 23:17 ` James Almer
2024-04-30 21:26 ` Michael Niedermayer
0 siblings, 1 reply; 4+ messages in thread
From: James Almer @ 2024-04-27 23:17 UTC (permalink / raw)
To: ffmpeg-devel
Signed-off-by: James Almer <jamrial@gmail.com>
---
libavformat/mov.c | 30 ++++++++++++++++++++++++------
1 file changed, 24 insertions(+), 6 deletions(-)
diff --git a/libavformat/mov.c b/libavformat/mov.c
index ede25d3342..9e95c6fcc0 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -84,6 +84,7 @@ typedef struct MOVParseTableEntry {
static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom);
static int mov_read_mfra(MOVContext *c, AVIOContext *f);
+static void mov_free_stream_context(AVFormatContext *s, AVStream *st);
static int64_t add_ctts_entry(MOVCtts** ctts_data, unsigned int* ctts_count, unsigned int* allocated_size,
int count, int duration);
@@ -8181,7 +8182,7 @@ static int mov_read_iinf(MOVContext *c, AVIOContext *pb, MOVAtom atom)
{
HEIFItem *heif_item;
int entry_count;
- int version, ret;
+ int version, got_stream = 0, ret, i;
if (c->found_iinf) {
av_log(c->fc, AV_LOG_WARNING, "Duplicate iinf box found\n");
@@ -8201,20 +8202,33 @@ static int mov_read_iinf(MOVContext *c, AVIOContext *pb, MOVAtom atom)
sizeof(*c->heif_item) * (entry_count - c->nb_heif_item));
c->nb_heif_item = FFMAX(c->nb_heif_item, entry_count);
- for (int i = 0; i < entry_count; i++) {
+ for (i = 0; i < entry_count; i++) {
MOVAtom infe;
infe.size = avio_rb32(pb) - 8;
infe.type = avio_rl32(pb);
ret = mov_read_infe(c, pb, infe, i);
if (ret < 0)
- return ret;
- if (ret)
- return 0;
+ goto fail;
+ if (!ret)
+ got_stream = 1;
}
- c->found_iinf = 1;
+ c->found_iinf = got_stream;
return 0;
+fail:
+ for (; i >= 0; i--) {
+ HEIFItem *item = &c->heif_item[i];
+
+ av_freep(&item->name);
+ if (!item->st)
+ continue;
+
+ mov_free_stream_context(c->fc, item->st);
+ ff_remove_stream(c->fc, item->st);
+ item->st = NULL;
+ }
+ return ret;
}
static int mov_read_iref_dimg(MOVContext *c, AVIOContext *pb, int version)
@@ -9561,6 +9575,10 @@ static int mov_read_header(AVFormatContext *s)
return err;
}
}
+ // prevent iloc and iinf boxes from being parsed while reading packets.
+ // this is needed because an iinf box may have been parsed but ignored
+ // for having old infe boxes which create no streams.
+ mov->found_iloc = mov->found_iinf = 1;
if (pb->seekable & AVIO_SEEKABLE_NORMAL) {
if (mov->nb_chapter_tracks > 0 && !mov->ignore_chapters)
--
2.44.0
_______________________________________________
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] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2] avformat/mov: free the infe allocated item data on failure
2024-04-27 23:17 ` [FFmpeg-devel] [PATCH v2] " James Almer
@ 2024-04-30 21:26 ` Michael Niedermayer
2024-04-30 21:30 ` James Almer
0 siblings, 1 reply; 4+ messages in thread
From: Michael Niedermayer @ 2024-04-30 21:26 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 514 bytes --]
On Sat, Apr 27, 2024 at 08:17:37PM -0300, James Almer wrote:
> Signed-off-by: James Almer <jamrial@gmail.com>
> ---
> libavformat/mov.c | 30 ++++++++++++++++++++++++------
> 1 file changed, 24 insertions(+), 6 deletions(-)
fixes 68212/clusterfuzz-testcase-minimized-ffmpeg_dem_MOV_fuzzer-4963488540721152
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Asymptotically faster algorithms should always be preferred if you have
asymptotical amounts of data
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
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] 4+ messages in thread
* Re: [FFmpeg-devel] [PATCH v2] avformat/mov: free the infe allocated item data on failure
2024-04-30 21:26 ` Michael Niedermayer
@ 2024-04-30 21:30 ` James Almer
0 siblings, 0 replies; 4+ messages in thread
From: James Almer @ 2024-04-30 21:30 UTC (permalink / raw)
To: ffmpeg-devel
On 4/30/2024 6:26 PM, Michael Niedermayer wrote:
> On Sat, Apr 27, 2024 at 08:17:37PM -0300, James Almer wrote:
>> Signed-off-by: James Almer <jamrial@gmail.com>
>> ---
>> libavformat/mov.c | 30 ++++++++++++++++++++++++------
>> 1 file changed, 24 insertions(+), 6 deletions(-)
>
> fixes 68212/clusterfuzz-testcase-minimized-ffmpeg_dem_MOV_fuzzer-4963488540721152
Applied, thanks.
_______________________________________________
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] 4+ messages in thread
end of thread, other threads:[~2024-04-30 21:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-27 1:01 [FFmpeg-devel] [PATCH] avformat/mov: free the infe allocated item data on failure James Almer
2024-04-27 23:17 ` [FFmpeg-devel] [PATCH v2] " James Almer
2024-04-30 21:26 ` Michael Niedermayer
2024-04-30 21:30 ` 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