diff mbox series

[FFmpeg-devel,7/9] avformat/rmdec: Fix potential shift outside of range of int

Message ID 20200721021215.32647-5-andreas.rheinhardt@gmail.com
State New
Headers show
Series [FFmpeg-devel,v2,1/2] avformat: Redo cleanup of demuxer upon read_header() failure | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt July 21, 2020, 2:12 a.m. UTC
The loop variable here that can be as high as UINT16_MAX - 1 gets
left-shifted by 16 bits which is outside the range of int. So use
unsigned.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavformat/rmdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

James Almer July 21, 2020, 3:58 a.m. UTC | #1
On 7/20/2020 11:12 PM, Andreas Rheinhardt wrote:
> The loop variable here that can be as high as UINT16_MAX - 1 gets
> left-shifted by 16 bits which is outside the range of int. So use
> unsigned.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavformat/rmdec.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
> index c88f41c121..e97b861dee 100644
> --- a/libavformat/rmdec.c
> +++ b/libavformat/rmdec.c
> @@ -500,7 +500,7 @@ static int rm_read_multi(AVFormatContext *s, AVIOContext *pb,
>      if (number_of_mdpr != 1) {
>          avpriv_request_sample(s, "MLTI with multiple (%d) MDPR", number_of_mdpr);

So most of the code below is untested?

Also, AVStream->id is an int, so maybe just ensure number_of_mdpr is
equal or less than INT16_MAX, and perhaps also that st->id is equal or
less than UINT16_MAX before doing the addition, and abort otherwise
instead of changing the type for i.

>      }
> -    for (i = 0; i < number_of_mdpr; i++) {
> +    for (unsigned i = 0; i < number_of_mdpr; i++) {
>          AVStream *st2;
>          if (i > 0) {
>              st2 = avformat_new_stream(s, NULL);
>
diff mbox series

Patch

diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c
index c88f41c121..e97b861dee 100644
--- a/libavformat/rmdec.c
+++ b/libavformat/rmdec.c
@@ -500,7 +500,7 @@  static int rm_read_multi(AVFormatContext *s, AVIOContext *pb,
     if (number_of_mdpr != 1) {
         avpriv_request_sample(s, "MLTI with multiple (%d) MDPR", number_of_mdpr);
     }
-    for (i = 0; i < number_of_mdpr; i++) {
+    for (unsigned i = 0; i < number_of_mdpr; i++) {
         AVStream *st2;
         if (i > 0) {
             st2 = avformat_new_stream(s, NULL);