tensorflow / tensorflow/tensorflow

tf.data.FixedLengthRecordDataset aborts with std::bad_alloc on oversized buffer_size instead of raising an error

Open
#113,159 2 comments 0 reactions 1 assignee View on GitHub

@Venkat6871 is already working on this.

Since Mar 24, 2026.

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

Description

Issue type

Bug

Have you reproduced the bug with TensorFlow Nightly?

Yes

Source

source

TensorFlow version

tf 2.21.0

Custom code

Yes

OS platform and distribution

Ubuntu 24.04.3 LTS x86_64

Mobile device

No response

Python version

3.10.20

Bazel version

No response

GCC/compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

4 x NVIDIA GeForce RTX 2080 Ti, 11264 MiB each

Current behavior?

Current behavior

I re-ran this reproducer locally and confirmed the failure.

tf.data.FixedLengthRecordDataset aborts the entire process when given an extremely large buffer_size, instead of returning a normal Python/TensorFlow exception.

Observed failure:

terminate called after throwing an instance of 'std::bad_alloc'

The process exits with:

Aborted (core dumped)

This is important because it is a hard process abort, not a normal recoverable error. Even if the requested buffer_size is invalid or too large to satisfy, TensorFlow should fail gracefully rather than terminating the interpreter.

Expected behavior

tf.data.FixedLengthRecordDataset should reject oversized buffer_size values with a regular TensorFlow/Python exception such as InvalidArgumentError or ResourceExhaustedError, instead of aborting the process with std::bad_alloc.

Minimal reproducer

import tensorflow as tf
import numpy as np
import sys

filename = "data.bin"
with open(filename, "wb") as f:
    for _ in range(10):
        f.write(np.random.bytes(8))

record_size = 8
buffer_size = sys.maxsize - record_size

dataset = tf.data.FixedLengthRecordDataset(
    filenames=[filename],
    record_bytes=record_size,
    buffer_size=buffer_size,
)

for record in dataset:
    print(record.numpy())

### Standalone code to reproduce the issue

```shell
Environment requirements
Ubuntu 24.04.3 LTS x86_64
Python 3.10
TensorFlow 2.21.0
NumPy 2.2.6
Reproduced in local conda environment: tf_test

conda create -n tf_test python=3.10 -y
conda activate tf_test
pip install tensorflow==2.21.0 numpy==2.2.6

conda run --no-capture-output -n tf_test python repro.py
Relevant log output
(tf_test) user@user-Standard-PC-Q35-ICH9-2009:/home/lhj$ python /home/lhj/callChainBuild/src_tensorflow/gen_program/validation_results_rerun/crashes/2898.py
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
I0000 00:00:1774352579.308728 3821583 port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
I0000 00:00:1774352579.514177 3821583 cpu_feature_guard.cc:227] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX512F AVX512_VNNI FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
WARNING: All log messages before absl::InitializeLog() is called are written to STDERR
I0000 00:00:1774352580.980667 3821583 port.cc:153] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
I0000 00:00:1774352582.523852 3821583 gpu_device.cc:2043] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 9606 MB memory:  -> device: 0, name: NVIDIA GeForce RTX 2080 Ti, pci bus id: 0000:01:00.0, compute capability: 7.5
I0000 00:00:1774352582.525411 3821583 gpu_device.cc:2043] Created device /job:localhost/replica:0/task:0/device:GPU:1 with 9606 MB memory:  -> device: 1, name: NVIDIA GeForce RTX 2080 Ti, pci bus id: 0000:02:00.0, compute capability: 7.5
I0000 00:00:1774352582.526956 3821583 gpu_device.cc:2043] Created device /job:localhost/replica:0/task:0/device:GPU:2 with 9606 MB memory:  -> device: 2, name: NVIDIA GeForce RTX 2080 Ti, pci bus id: 0000:03:00.0, compute capability: 7.5
I0000 00:00:1774352582.528326 3821583 gpu_device.cc:2043] Created device /job:localhost/replica:0/task:0/device:GPU:3 with 9606 MB memory:  -> device: 3, name: NVIDIA GeForce RTX 2080 Ti, pci bus id: 0000:04:00.0, compute capability: 7.5
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted (core dumped)

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.