Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 30, 2026

  • Understand the issue: Integer overflow in IListWrapper.BinarySearch when calculating mid = (lo + hi) / 2 with large indices
  • Find the correct fix pattern: Use lo + ((hi - lo) >> 1) as done in Array.GetMedian
  • Run baseline build (clr+libs -rc release)
  • Make the fix to ArrayList.cs line 774
  • Add a unit test to validate the fix
  • Run tests to verify the fix works
  • Run code review and codeql checker
Original prompt

This section details on the original issue you should resolve

<issue_title>ArrayList IListWrapper integer overflow in BinarySearch</issue_title>
<issue_description>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.</issue_description>

<agent_instructions>ArrayList is in corelib, so after doing a full build, for any subsequent changes you make, you'll need to rebuild corelib with clr.corlib+clr.nativecorelib+libs.pretest.</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vcsjones
Copy link
Member

@stephentoub I had a Copilot session going here (unfortunately the way I initiated it resulted in it not being assigned to Copilot) #123806

@stephentoub stephentoub deleted the copilot/fix-integer-overflow-binarysearch branch January 30, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ArrayList IListWrapper integer overflow in BinarySearch

3 participants