Repository navigation
fix(bigtable): truncate 0xFF in PrefixRangeEnd - #16645
Conversation
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.
There was a problem hiding this comment.
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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
Summary
Truncate trailing
0xFFbytes when computingPrefixRangeEndsoRowRange::Prefixexcludes out-of-prefix row keys, and increment viaunsigned charto avoid signedcharoverflow at0x7F.Motivation
For prefixes ending in one or more
0xFFbytes (with at least one preceding non-0xFFbyte, e.g.,"a\xFF"),PrefixRangeEndpreviously 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"inRowRange::Prefix,RowRange::Contains, andRowRange::IntersectduringReadRowsretry resumption.In addition,
result[pos]++incremented a potentially signedchardirectly, causing signed integer overflow whenresult[pos]was0x7F.Changes
keytokey.substr(0, pos + 1)and incrementresult[pos]viaunsigned charinPrefixRangeEnd.PrefixRangeEndTestand addRowRangeTest.PrefixTrailingFFExcludesOutOfPrefixKeyscovering trailing0xFFtruncation,0x7Fboundaries,Contains, andIntersect.Validation
bazel test //google/cloud/bigtable:internal_prefix_range_end_test //google/cloud/bigtable:row_range_test