Skip to content

Fix integer truncation and SIGSEGV in BlockLSTMGrad kernel (#104830) - #125054

Merged
copybara-service[bot] merged 2 commits into
tensorflow:masterfrom
hunterkritik-byte:fix-block-lstm-grad-shapes
Aug 24, 2026
Merged

copybara-service[bot] merged 2 commits into
tensorflow:masterfrom
hunterkritik-byte:fix-block-lstm-grad-shapes

Conversation

@hunterkritik-byte

Copy link
Copy Markdown
Contributor

Summary of Changes

Fixes #104830.

Description

When calling BlockLSTMGrad or BlockLSTMGradV2 with weight matrices w whose second dimension is not a positive multiple of 4 (e.g., shape [1, 1]), C++ integer division cell_size = w_tensor->dim_size(1) / 4 evaluated to 0. Consequently, input_size + cell_size matched w_tensor->dim_size(0) unexpectedly (1 + 0 == 1), bypassing existing shape checks and leading to out-of-bounds memory access / SIGSEGV during Eigen operations.

Fix Details

  • Added explicit validation requiring w_tensor->dim_size(1) % 4 == 0 and w_tensor->dim_size(1) > 0.
  • Invalid weight matrix shapes now cleanly raise absl::InvalidArgumentError instead of crashing.

@google-ml-butler google-ml-butler Bot added the size:XS CL Change Size: Extra Small label Aug 11, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a validation check in BlockLSTMGradOp to ensure that the number of columns in the weight tensor w is a positive multiple of 4. The feedback suggests reordering the conditions in the check to evaluate w_tensor->dim_size(1) > 0 first, which ensures proper short-circuiting and avoids modulo operations on non-positive dimensions.

Comment thread tensorflow/core/kernels/rnn/lstm_ops.cc Resolved
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@nithyak0204
nithyak0204 requested a review from a team August 11, 2026 11:07
@google-ml-butler google-ml-butler Bot added the awaiting review Pull request awaiting review label Aug 11, 2026
@nithyak0204 nithyak0204 added comp:core issues related to core part of tensorflow prtype:bugfix PR to fix a bug labels Aug 11, 2026
@github-project-automation github-project-automation Bot moved this to Assigned Reviewer in PR Queue Aug 11, 2026
@dmiltr3
dmiltr3 self-requested a review August 20, 2026 17:04
@google-ml-butler google-ml-butler Bot added kokoro:force-run Tests on submitted change ready to pull PR ready for merge process labels Aug 20, 2026
@github-project-automation github-project-automation Bot moved this from Assigned Reviewer to Approved by Reviewer in PR Queue Aug 20, 2026
@nithyak0204 nithyak0204 removed the awaiting review Pull request awaiting review label Aug 24, 2026
@copybara-service
copybara-service Bot merged commit 8547715 into tensorflow:master Aug 24, 2026
17 of 19 checks passed
@github-project-automation github-project-automation Bot moved this from Approved by Reviewer to Merged in PR Queue Aug 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:core issues related to core part of tensorflow kokoro:force-run Tests on submitted change prtype:bugfix PR to fix a bug ready to pull PR ready for merge process size:XS CL Change Size: Extra Small

Projects

Status: Merged

Development

Successfully merging this pull request may close these issues.

Segmentation fault on CPU-only VM when running TensorFlow

4 participants