Skip to content

fix: Fix undefined behavior in BinarySection bitmask constants caused by signed left shift#303

Merged
lxy-9602 merged 1 commit into
alibaba:mainfrom
lxy-9602:fix-binary-section
May 26, 2026
Merged

fix: Fix undefined behavior in BinarySection bitmask constants caused by signed left shift#303
lxy-9602 merged 1 commit into
alibaba:mainfrom
lxy-9602:fix-binary-section

Conversation

@lxy-9602
Copy link
Copy Markdown
Collaborator

@lxy-9602 lxy-9602 commented May 26, 2026

Purpose

No Linked issue.

What is the problem?

In BinarySection, the bitmask constants HIGHEST_FIRST_BIT and HIGHEST_SECOND_TO_EIGHTH_BIT are defined using signed left shift:

static constexpr int64_t HIGHEST_FIRST_BIT = 0x80L << 56;
static constexpr int64_t HIGHEST_SECOND_TO_EIGHTH_BIT = 0x7FL << 56;

0x80L is a signed long with value 128. Left-shifting it by 56 bits overflows into the sign bit of a 64-bit signed integer, which is undefined behavior (UB) per the C++ standard (before C++20, and still implementation-defined in C++20).

What is the fix?

Use unsigned literals (0x80ULL, 0x7FULL) for the shift operation to ensure defined behavior, then static_cast back to int64_t:

static constexpr int64_t HIGHEST_FIRST_BIT = static_cast<int64_t>(0x80ULL << 56);
static constexpr int64_t HIGHEST_SECOND_TO_EIGHTH_BIT = static_cast<int64_t>(0x7FULL << 56);

Tests

API and Format

Documentation

Generative AI tooling

@lxy-9602 lxy-9602 merged commit c8978da into alibaba:main May 26, 2026
8 checks passed
lxy-9602 added a commit to lxy-9602/paimon-cpp that referenced this pull request May 28, 2026
lxy-9602 added a commit that referenced this pull request May 28, 2026
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.

2 participants