Skip to content

fix bits::copyBits coredump caused by negative leafNullsSize_#529

Merged
guhaiyan0221 merged 2 commits into
bytedance:mainfrom
guhaiyan0221:fix_copybits_coredump
May 13, 2026
Merged

fix bits::copyBits coredump caused by negative leafNullsSize_#529
guhaiyan0221 merged 2 commits into
bytedance:mainfrom
guhaiyan0221:fix_copybits_coredump

Conversation

@guhaiyan0221
Copy link
Copy Markdown
Collaborator

Issue Number: close #528

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 🚀 Performance improvement (optimization)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)
  • 🔨 Refactoring (no logic changes)
  • 🔧 Build/CI or Infrastructure changes
  • 📝 Documentation only

Description

Fix bits::copyBits coredump caused by leafNullsSize_ overflow. This PR upgrades the type of leafNullsSize_ from int32_t to int64_t to eliminate integer overflow risks.

Performance Impact

  • No Impact: This change does not affect the critical path (e.g., build system, doc, error handling).

  • Positive Impact: I have run benchmarks.

    Click to view Benchmark Results
    Paste your google-benchmark or TPC-H results here.
    Before: 10.5s
    After:   8.2s  (+20%)
    
  • Negative Impact: Explained below (e.g., trade-off for correctness).

Release Note

Please describe the changes in this PR

Release Note:

Release Note:
- Fixed a crash in `substr` when input is null.
- optimized `group by` performance by 20%.

Checklist (For Author)

  • I have added/updated unit tests (ctest).
  • I have verified the code with local build (Release/Debug).
  • I have run clang-format / linters.
  • (Optional) I have run Sanitizers (ASAN/TSAN) locally for complex C++ changes.
  • No need to test or manual test.

Breaking Changes

  • No

  • Yes (Description: ...)

    Click to view Breaking Changes
    Breaking Changes:
    - Description of the breaking change.
    - Possible solutions or workarounds.
    - Any other relevant information.
    

Comment thread bolt/dwio/parquet/reader/PageReader.cpp Outdated
leafNulls_.data(),
0);
numRowsInPage_ = leafNullsSize_;
numRowsInPage_ = checkedInt64ToInt32(leafNullsSize_, "leafNullsSize_");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why can't numRowsInPage_ be int64?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

or be uint32?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

as defined in parquet.thrift
image

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why not put checkedInt64ToInt32 in getLengthsAndNulls for specific code path, not narrow int type outside.

Comment thread bolt/dwio/parquet/reader/RepeatedColumnReader.cpp Outdated
Comment thread bolt/dwio/parquet/reader/PageReader.h Outdated
@guhaiyan0221 guhaiyan0221 requested a review from fzhedu May 11, 2026 09:36
@guhaiyan0221 guhaiyan0221 enabled auto-merge May 11, 2026 11:32
@guhaiyan0221 guhaiyan0221 force-pushed the fix_copybits_coredump branch from b62c140 to 11d371a Compare May 12, 2026 11:19
Comment on lines 284 to +293
@@ -290,13 +290,14 @@ void PageReader::readPageDefLevels() {
nullptr,
leafNulls_.data(),
0);
numRowsInPage_ = leafNullsSize_;
leafNullsSize_ = numRowsInPage_;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why change the position of them?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

getLengthsAndNulls is int32_t, leafNullsSize_ is int64_t, no need to cast

void PageReader::updateRowInfoAfterPageSkipped() {
rowOfPage_ += numRowsInPage_;
if (hasChunkRepDefs_) {
BOLT_CHECK_GE(rowOfPage_, 0);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

use __builtin_add_overflow for rowOfPage_ ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

A compiler-specific builtin does not seem necessary here, since it would not provide much practical benefit for this case.

@guhaiyan0221 guhaiyan0221 force-pushed the fix_copybits_coredump branch from 11d371a to 10b62e5 Compare May 12, 2026 15:04
Copy link
Copy Markdown
Collaborator

@fzhedu fzhedu left a comment

Choose a reason for hiding this comment

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

LGTM

@guhaiyan0221 guhaiyan0221 added this pull request to the merge queue May 13, 2026
Merged via the queue into bytedance:main with commit cdd5038 May 13, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] bits::copyBits coredump

2 participants