diff mbox series

[FFmpeg-devel,4/8] avformat/mxfdec: Fix file position addition

Message ID 20210201223116.11378-4-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,1/8] avcodec/cbs_sei_syntax_template: Check for non negativity before setting size_t bits_left | 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

Michael Niedermayer Feb. 1, 2021, 10:31 p.m. UTC
Not sure this is the best solution, maybe a more general solution limiting the avio_tell() output to less than 63bit would be a better option
Fixes: signed integer overflow: 9223372036854775805 + 4 cannot be represented in type 'long'
Fixes: 29927/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-5579985228267520

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavformat/mxfdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Tomas Härdin Feb. 4, 2021, 6:43 p.m. UTC | #1
mån 2021-02-01 klockan 23:31 +0100 skrev Michael Niedermayer:
> Not sure this is the best solution, maybe a more general solution
> limiting the avio_tell() output to less than 63bit would be a better
> option

Probably, since this is likely to happen in more places

> Fixes: signed integer overflow: 9223372036854775805 + 4 cannot be represented in type 'long'
> Fixes: 29927/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-5579985228267520
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavformat/mxfdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
> index afff20402d..97a1b749fe 100644
> --- a/libavformat/mxfdec.c
> +++ b/libavformat/mxfdec.c
> @@ -2861,7 +2861,7 @@ static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, MXFMetadataReadF
>          return AVERROR(ENOMEM);
>      if (ctx_size)
>          mxf_metadataset_init(ctx, type);
> -    while (avio_tell(pb) + 4 < klv_end && !avio_feof(pb)) {
> +    while (avio_tell(pb) + (uint64_t)4 < klv_end && !avio_feof(pb)) {

Why not cast avio_tell() instead?

/Tomas
James Almer Feb. 4, 2021, 8:07 p.m. UTC | #2
On 2/4/2021 3:43 PM, Tomas Härdin wrote:
> mån 2021-02-01 klockan 23:31 +0100 skrev Michael Niedermayer:
>> Not sure this is the best solution, maybe a more general solution
>> limiting the avio_tell() output to less than 63bit would be a better
>> option
> 
> Probably, since this is likely to happen in more places
> 
>> Fixes: signed integer overflow: 9223372036854775805 + 4 cannot be represented in type 'long'
>> Fixes: 29927/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-5579985228267520
>>
>> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
>> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>> ---
>>   libavformat/mxfdec.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
>> index afff20402d..97a1b749fe 100644
>> --- a/libavformat/mxfdec.c
>> +++ b/libavformat/mxfdec.c
>> @@ -2861,7 +2861,7 @@ static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, MXFMetadataReadF
>>           return AVERROR(ENOMEM);
>>       if (ctx_size)
>>           mxf_metadataset_init(ctx, type);
>> -    while (avio_tell(pb) + 4 < klv_end && !avio_feof(pb)) {
>> +    while (avio_tell(pb) + (uint64_t)4 < klv_end && !avio_feof(pb)) {
> 
> Why not cast avio_tell() instead?

Or use 4ULL

> 
> /Tomas
> 
> _______________________________________________
> 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".
>
Michael Niedermayer March 15, 2021, 8:52 p.m. UTC | #3
On Thu, Feb 04, 2021 at 05:07:31PM -0300, James Almer wrote:
> On 2/4/2021 3:43 PM, Tomas Härdin wrote:
> > mån 2021-02-01 klockan 23:31 +0100 skrev Michael Niedermayer:
> > > Not sure this is the best solution, maybe a more general solution
> > > limiting the avio_tell() output to less than 63bit would be a better
> > > option
> > 
> > Probably, since this is likely to happen in more places

iam not sure how to handle this in a more general way.
Simply limiting avio_tell to something seems arbitrary 


> > 
> > > Fixes: signed integer overflow: 9223372036854775805 + 4 cannot be represented in type 'long'
> > > Fixes: 29927/clusterfuzz-testcase-minimized-ffmpeg_dem_MXF_fuzzer-5579985228267520
> > > 
> > > Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> > > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > > ---
> > >   libavformat/mxfdec.c | 2 +-
> > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
> > > index afff20402d..97a1b749fe 100644
> > > --- a/libavformat/mxfdec.c
> > > +++ b/libavformat/mxfdec.c
> > > @@ -2861,7 +2861,7 @@ static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, MXFMetadataReadF
> > >           return AVERROR(ENOMEM);
> > >       if (ctx_size)
> > >           mxf_metadataset_init(ctx, type);
> > > -    while (avio_tell(pb) + 4 < klv_end && !avio_feof(pb)) {
> > > +    while (avio_tell(pb) + (uint64_t)4 < klv_end && !avio_feof(pb)) {
> > 
> > Why not cast avio_tell() instead?
> 
> Or use 4ULL

ok

thx

[...]
diff mbox series

Patch

diff --git a/libavformat/mxfdec.c b/libavformat/mxfdec.c
index afff20402d..97a1b749fe 100644
--- a/libavformat/mxfdec.c
+++ b/libavformat/mxfdec.c
@@ -2861,7 +2861,7 @@  static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, MXFMetadataReadF
         return AVERROR(ENOMEM);
     if (ctx_size)
         mxf_metadataset_init(ctx, type);
-    while (avio_tell(pb) + 4 < klv_end && !avio_feof(pb)) {
+    while (avio_tell(pb) + (uint64_t)4 < klv_end && !avio_feof(pb)) {
         int ret;
         int tag = avio_rb16(pb);
         int size = avio_rb16(pb); /* KLV specified by 0x53 */