PT-2026-36860 · Crates.Io · Grid

Publicado

2026-04-24

·

Atualizado

2026-04-24

CVSS v3.1

6.2

Média

VetorAV:L/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:H

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

rust
#![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

Correção

Integer Overflow

Encontrou algum problema na descrição? Tem algo a acrescentar? Fique à vontade para nos escrever 👾

Enumeração de Fraquezas

Identificadores relacionados

GHSA-38C5-483C-4QQP

Produtos afetados

Grid