GHSA-38C5-483C-4QQP

Vulnerability from github – Published: 2026-04-24 15:57 – Updated: 2026-04-24 15:57
VLAI?
Summary
Grid: Integer Overflow in Grid::expand_rows Leads to Safe-API Undefined Behavior
Details

Summary

An integer overflow in Grid::expand_rows() can corrupt the relationship between the grid’s logical dimensions and its backing storage. After the internal invariant is broken, the safe API get() may invoke get_unchecked() with an invalid index, resulting in Undefined Behavior.

Details

Tested Version: grid = "1.0.0"

expand_rows() computes the new backing length using unchecked arithmetic:

self.data.len() + rows * self.cols

If rows * self.cols or the subsequent addition overflows usize, the result wraps in release builds and self.data may be resized to a length much smaller than logically required.

After that, if the grid is in ColumnMajor order, the function performs in-place rotation using indices derived from:

let total_rows = self.rows + row_added;
let col_idx = i * total_rows;
self.data[col_idx..col_idx + total_rows + i].rotate_right(i);

These computations also rely on the assumption that the backing storage has been resized to the correct length. Once the earlier length computation has wrapped, this assumption no longer holds, so the function may operate on invalid ranges or otherwise enter an inconsistent state.

Finally, the function updates logical metadata with:

self.rows += rows;

As a result, the grid can end up with logical dimensions that no longer match the actual backing storage. Subsequent safe API calls such as get() may then rely on corrupted metadata and reach unsafe internal accesses, resulting in invalid unchecked access and Undefined Behavior.

PoC

#![forbid(unsafe_code)]

use grid::Grid;

fn main() {
    let mut g = Grid::from_vec(vec![1u8, 2u8], 2);

    g.expand_rows(usize::MAX / 2);

    g.get(0, 0); // triggers UB in get_unchecked
}

Impact

  • Invalid unchecked access (get_unchecked) reached via safe API
  • Confirmed by Miri (release-mode):
error: Undefined Behavior: `assume` called with `false`
   --> ..../grid-1.0.0/src/lib.rs:527:9
    |
527 |         self.data.get_unchecked(index)
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here

  • Potential crash / denial of service in release-builds (e.g., SIGSEGV, Illegal instruction)
  • Violates Rust’s safety guarantees despite using only safe code
Show details on source website

{
  "affected": [
    {
      "database_specific": {
        "last_known_affected_version_range": "\u003c= 1.0.0"
      },
      "package": {
        "ecosystem": "crates.io",
        "name": "grid"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0.17.0"
            },
            {
              "fixed": "1.0.1"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [],
  "database_specific": {
    "cwe_ids": [
      "CWE-190"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-04-24T15:57:36Z",
    "nvd_published_at": null,
    "severity": "MODERATE"
  },
  "details": "### Summary\nAn integer overflow in `Grid::expand_rows()` can corrupt the relationship between the grid\u2019s logical dimensions and its backing storage. After the internal invariant is broken, the safe API get() may invoke get_unchecked() with an invalid index, resulting in Undefined Behavior.\n\n### Details\nTested Version: grid = \"1.0.0\"\n\nexpand_rows() computes the new backing length using unchecked arithmetic:\n\n`self.data.len() + rows * self.cols\n`\n\nIf rows * self.cols or the subsequent addition overflows usize, the result wraps in release builds and self.data may be resized to a length much smaller than logically required.\n\nAfter that, if the grid is in ColumnMajor order, the function performs in-place rotation using indices derived from:\n\n```\nlet total_rows = self.rows + row_added;\nlet col_idx = i * total_rows;\nself.data[col_idx..col_idx + total_rows + i].rotate_right(i);\n```\n\nThese computations also rely on the assumption that the backing storage has been resized to the correct length. Once the earlier length computation has wrapped, this assumption no longer holds, so the function may operate on invalid ranges or otherwise enter an inconsistent state.\n\nFinally, the function updates logical metadata with:\n\n`self.rows += rows;\n`\n\nAs a result, the grid can end up with logical dimensions that no longer match the actual backing storage. Subsequent safe API calls such as get() may then rely on corrupted metadata and reach unsafe internal accesses, resulting in invalid unchecked access and Undefined Behavior.\n\n### PoC\n```rust\n#![forbid(unsafe_code)]\n\nuse grid::Grid;\n\nfn main() {\n    let mut g = Grid::from_vec(vec![1u8, 2u8], 2);\n\n    g.expand_rows(usize::MAX / 2);\n\n    g.get(0, 0); // triggers UB in get_unchecked\n}\n```\n\n### Impact\n- Invalid unchecked access (`get_unchecked`) reached via safe API\n- Confirmed by Miri (release-mode):\n\n```\nerror: Undefined Behavior: `assume` called with `false`\n   --\u003e ..../grid-1.0.0/src/lib.rs:527:9\n    |\n527 |         self.data.get_unchecked(index)\n    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Undefined Behavior occurred here\n\n```\n- Potential crash / denial of service in release-builds (e.g., SIGSEGV, Illegal instruction)\n- Violates Rust\u2019s safety guarantees despite using only safe code",
  "id": "GHSA-38c5-483c-4qqp",
  "modified": "2026-04-24T15:57:36Z",
  "published": "2026-04-24T15:57:36Z",
  "references": [
    {
      "type": "WEB",
      "url": "https://github.com/becheran/grid/security/advisories/GHSA-38c5-483c-4qqp"
    },
    {
      "type": "WEB",
      "url": "https://github.com/becheran/grid/commit/be213bd3528727148bef2d523c89e95d1fd9c072"
    },
    {
      "type": "PACKAGE",
      "url": "https://github.com/becheran/grid"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "score": "CVSS:3.1/AV:L/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H",
      "type": "CVSS_V3"
    }
  ],
  "summary": "Grid: Integer Overflow in Grid::expand_rows Leads to Safe-API Undefined Behavior"
}


Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Sightings

Author Source Type Date

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.


Loading…

Detection rules are retrieved from Rulezet.

Loading…

Loading…