Skip to content

fix(bigtable): truncate 0xFF in PrefixRangeEnd - #16645

Merged
sushanb merged 1 commit into
googleapis:mainfrom
sushanb:fix/bigtable-prefix-range-end-truncate
Nov 10, 2026
Merged

sushanb merged 1 commit into
googleapis:mainfrom
sushanb:fix/bigtable-prefix-range-end-truncate

Conversation

@sushanb

@sushanb sushanb commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Truncate trailing 0xFF bytes when computing PrefixRangeEnd so RowRange::Prefix excludes out-of-prefix row keys, and increment via unsigned char to avoid signed char overflow at 0x7F.

Motivation

For prefixes ending in one or more 0xFF bytes (with at least one preceding non-0xFF byte, e.g., "a\xFF"), PrefixRangeEnd previously zero-filled the trailing bytes ("b\x00") instead of truncating them ("b"). Because "a\xFF" < "b" < "b\x00", the resulting half-open interval ["a\xFF", "b\x00") erroneously included the out-of-prefix row key "b" in RowRange::Prefix, RowRange::Contains, and RowRange::Intersect during ReadRows retry resumption.

In addition, result[pos]++ incremented a potentially signed char directly, causing signed integer overflow when result[pos] was 0x7F.

Changes

  • Truncate key to key.substr(0, pos + 1) and increment result[pos] via unsigned char in PrefixRangeEnd.
  • Update PrefixRangeEndTest and add RowRangeTest.PrefixTrailingFFExcludesOutOfPrefixKeys covering trailing 0xFF truncation, 0x7F boundaries, Contains, and Intersect.

Validation

  • bazel test //google/cloud/bigtable:internal_prefix_range_end_test //google/cloud/bigtable:row_range_test

Truncate trailing 0xFF bytes instead of zero-padding them when computing PrefixRangeEnd so RowRange::Prefix excludes out-of-prefix row keys, and increment the final non-0xFF byte via unsigned char to avoid signed char overflow at 0x7F.
@sushanb
sushanb requested a review from a team as a code owner November 10, 2026 03:45
@sushanb
sushanb requested a review from scotthart November 10, 2026 03:45
@product-auto-label product-auto-label Bot added the api: bigtable Issues related to the Bigtable API. label Nov 10, 2026

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

Copy link
Copy Markdown

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 refactors the PrefixRangeEnd function in prefix_range_end.cc to truncate trailing 0xFF bytes instead of replacing them with null bytes, and safely increments the last non-0xFF byte using explicit casts. It also replaces the use of auto for the string position with std::string::size_type const to adhere to the style guide. Comprehensive unit tests have been added and updated in prefix_range_end_test.cc and row_range_test.cc to verify the new truncation behavior, empty keys, and signed char boundaries. There are no review comments to address, and I have no additional feedback to provide.

@codecov

codecov Bot commented Nov 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.52%. Comparing base (b32a1f5) to head (d8a78e5).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16645      +/-   ##
==========================================
+ Coverage   92.51%   92.52%   +0.01%     
==========================================
  Files        2269     2269              
  Lines      222804   222857      +53     
==========================================
+ Hits       206126   206199      +73     
+ Misses      16678    16658      -20     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sushanb
sushanb merged commit 6aa0eb6 into googleapis:main Nov 10, 2026
67 of 68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigtable Issues related to the Bigtable API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Sponsor
SponsoredKunjungi sekarang
Promo