Skip to content

Potential for integer overflow and crash in SortingRendererClass::Flush_Sorting_Pool #2007

Description

@Caball009

With an insane number of units or effects, it's possible to get the polygon count to overflow a 16 bit limit and subsequently crash the game. This needs fixing, but the scenario is somewhat contrived because the game is so slow it's completely unplayable by the time it overflows and crashes. There's an assertion that'll get triggered in debug mode.

unsigned polygonAllocCount = overlapping_polygon_count;
if ((unsigned)(DynamicIBAccessClass::Get_Default_Index_Count()/3) < DEFAULT_SORTING_POLY_COUNT)
polygonAllocCount = DEFAULT_SORTING_POLY_COUNT; //make sure that we force the DX8 index buffer to maximum size
if (overlapping_polygon_count > polygonAllocCount)
polygonAllocCount = overlapping_polygon_count;
WWASSERT(DEFAULT_SORTING_POLY_COUNT <= 1 || polygonAllocCount <= DEFAULT_SORTING_POLY_COUNT);
DynamicIBAccessClass dyn_ib_access(BUFFER_TYPE_DYNAMIC_DX8,polygonAllocCount*3);
{
DynamicIBAccessClass::WriteLockClass lock(&dyn_ib_access);
ShortVectorIStruct* sorted_polygon_index_array=(ShortVectorIStruct*)lock.Get_Index_Array();
for (unsigned a=0;a<overlapping_polygon_count;++a) {
sorted_polygon_index_array[a]=tis[a].tri;
}
}

A couple of issues here:

  1. polygonAllocCount*3 (L534) is cast to an unsigned short by DynamicIBAccessClass's constructor, so it must below 2 ^ 16 considering it's used later for the iteration.
  2. a<overlapping_polygon_count (L539) should be a<polygonAllocCount.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething is not working right, typically is user facingCrashThis is a crash, very badMajorSeverity: Minor < Major < Critical < Blocker

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions