Skip to content

ArrayList IListWrapper integer overflow in BinarySearch #123804

@vcsjones

Description

@vcsjones

Consider the following program:

using System;
using System.Collections;

static class Foo
{    
    static void Main()
    {
        IList l = new byte[int.MaxValue / 2 + 2];
        ArrayList al = ArrayList.Adapter(l);
        int result = al.BinarySearch((byte)1);
        Console.WriteLine(result);
    }
}

This will overflow here:

I would instead expect this to return a value indicating it could not be found.

The GetMedian method on Array is likely the "right" implementation to use for calculating mid.

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions