tensorflow / tensorflow/tensorflow

`RaggedGather` int32 value-count overflow causes a heap-buffer-overflow write

Open
#126,135 1 comment 0 reactions 1 assignee View on GitHub

@Kayyuri is already working on this.

Since Sep 3, 2026.

2.21.0 awaiting PR merge comp:ops type:bug
Dominant language
C++
Stars
200k
Forks
76.9k
Avg merge
2d 3h
Merged PRs (30d)
433

Description

Environment

  • Issue type: Bug
  • Installation source: Source
  • TensorFlow: 2.21.0-dev0+selfbuilt
  • Source revision used for ASan replay: 1ba0a9868d4531a3246409296a6f1638abfe6e98
  • Current source check: 8a52b03f9de61edf83a97c6e6de8b81b73c33f66
  • OS/device: Linux x86-64, CPU
  • Sanitizer: AddressSanitizer

PoC

import tensorflow as tf

tf.raw_ops.RaggedGather(
    params_nested_splits=[tf.constant([0, 65536], tf.int32)],
    params_dense_values=tf.zeros([65536], tf.uint8),
    indices=tf.zeros([65537], tf.int32),
    OUTPUT_RAGGED_RANK=1,
)

Run with an ASan-enabled TensorFlow build:

ASAN_OPTIONS=detect_leaks=0:halt_on_error=1:abort_on_error=1 python3 repro.py

ASan result

ERROR: AddressSanitizer: heap-buffer-overflow
WRITE of size 1
0 bytes after 65536-byte region
WriteValueSlices<unsigned char, int>
tensorflow/core/kernels/ragged_gather_op.cc:47:28

The true output count is 65537 * 65536 = 2^32 + 65536, but the count is
accumulated in the selected int32 row-splits type and wraps to 65536. The
output allocation uses the wrapped count while the copy loop processes all
selected rows.

The unchecked accumulation remains on current master at
ragged_gather_op.cc:191.

Expected behavior

The value count should use checked wide arithmetic and return a recoverable
error on overflow instead of allocating an undersized output.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.