Skip to content

unchecked signed accumulation in size calculation functions #1204

Description

@anaef

While reviewing an H3 binding, I noticed unchecked signed accumulation in two size calculation functions:

  • uncompactCellsSize: numOut += childrenSize
  • maxPolygonToCellsSize: totalVerts += geoPolygon->holes[i].numVerts

For uncompactCellsSize, a concrete boundary case is 1,942,760 copies of a valid non-pentagon resolution-0 cell expanded to resolution 15. Each contributes 7^15 = 4,747,561,509,943 cells, so the mathematical total exceeds INT64_MAX. The example uses duplicates; if those are considered invalid input, they are not rejected before the addition.

For maxPolygonToCellsSize, the vertex counts are accumulated in an int. An overflow can be demonstrated with a three-vertex exterior and one hole reporting INT_MAX vertices. This deliberately uses inconsistent polygon metadata; a structurally consistent case would require more than INT_MAX coordinates and therefore an exceptionally large input.

While triggering these conditions appears to require adversarial inputs unlikely to arise in ordinary use, I wanted to report them because the affected size calculations may directly determine downstream memory allocations and could therefore have security implications.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions