diff mbox series

[FFmpeg-devel,2/2] avformat/mxfdec: Fix leak on error

Message ID 20210312130733.1980124-2-andreas.rheinhardt@gmail.com
State Accepted
Headers show
Series [FFmpeg-devel,1/2] avformat/mxfdec: Don't use wrong type of pointer | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Andreas Rheinhardt March 12, 2021, 1:07 p.m. UTC
It was introduced in d3d9b1fc8e2dfc8b4d66c9916ab7221062ff4660;
Fixes Coverity issue #733800.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
I have no testcase for this; but hopefully Michael can test it with the
testcase that led to d3d9b1fc8e2dfc8b4d66c9916ab7221062ff4660 in the
first place?
(And I always thought fuzzing samples were small. How does it come that
it is close to INT64_MAX?)

 libavformat/mxfdec.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Tomas Härdin March 16, 2021, 7:38 a.m. UTC | #1
fre 2021-03-12 klockan 14:07 +0100 skrev Andreas Rheinhardt:
> It was introduced in d3d9b1fc8e2dfc8b4d66c9916ab7221062ff4660;
> Fixes Coverity issue #733800.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
> I have no testcase for this; but hopefully Michael can test it with the
> testcase that led to d3d9b1fc8e2dfc8b4d66c9916ab7221062ff4660 in the
> first place?
> (And I always thought fuzzing samples were small. How does it come that
> it is close to INT64_MAX?)
> 
>  libavformat/mxfdec.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
> index d7213bda30..2e9d7d713a 100644
> --- a/libavformat/mxfdec.c
> +++ b/libavformat/mxfdec.c
> @@ -2909,8 +2909,11 @@ static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, MXFMetadataReadF
>          int size = avio_rb16(pb); /* KLV specified by 0x53 */
>          int64_t next = avio_tell(pb);
>          UID uid = {0};
> -        if (next < 0 || next > INT64_MAX - size)
> +        if (next < 0 || next > INT64_MAX - size) {
> +            if (meta)
> +                mxf_free_metadataset(&meta, 1);

{} here too of course. Looks good otherwise

/Tomas
diff mbox series

Patch

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index d7213bda30..2e9d7d713a 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -2909,8 +2909,11 @@  static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, MXFMetadataReadF
         int size = avio_rb16(pb); /* KLV specified by 0x53 */
         int64_t next = avio_tell(pb);
         UID uid = {0};
-        if (next < 0 || next > INT64_MAX - size)
+        if (next < 0 || next > INT64_MAX - size) {
+            if (meta)
+                mxf_free_metadataset(&meta, 1);
             return next < 0 ? next : AVERROR_INVALIDDATA;
+        }
         next += size;
 
         av_log(mxf->fc, AV_LOG_TRACE, "local tag %#04x size %d\n", tag, size);