Fix missing null check and wrong cast in TimestampType comparisons#883
Open
Chessing234 wants to merge 1 commit intocmu-db:masterfrom
Open
Fix missing null check and wrong cast in TimestampType comparisons#883Chessing234 wants to merge 1 commit intocmu-db:masterfrom
Chessing234 wants to merge 1 commit intocmu-db:masterfrom
Conversation
1. CompareNotEquals: missing left.IsNull() check. Only right.IsNull() is checked, so comparing a NULL left timestamp against a non-NULL right returns CmpTrue/CmpFalse instead of CmpNull, violating SQL null semantics. Every other Compare* method checks both sides. 2. CompareGreaterThan: uses int64_t instead of uint64_t. Timestamps are stored as uint64_t; signed comparison causes large timestamp values (bit 63 set) to be treated as negative, inverting the ordering. Every other Compare* method uses uint64_t. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two correctness bugs in
timestamp_type.cpp:1.
CompareNotEqualsmissingleft.IsNull()check (line 34)Only
right.IsNull()is checked. Ifleftis NULL andrightis not, the function reads the NULL value's bit pattern and returnsCmpTrue/CmpFalseinstead ofCmpNull. This violates SQL null semantics (NULL != xmust beNULL). Every otherCompare*method in this file checksleft.IsNull() || right.IsNull().2.
CompareGreaterThanusesint64_tinstead ofuint64_t(line 61)Timestamps are stored as
uint64_t. Signed comparison viaint64_tcauses values with bit 63 set to be interpreted as negative, inverting the ordering for large timestamps. Every otherCompare*method usesuint64_t.Test plan
uint64_tstorage (value_.timestamp_, SerializeTo, DeserializeFrom)