Skip to content

fix: prevent unary minus signed integer overflow - #28499

Merged
XuPeng-SH merged 21 commits into
matrixorigin:mainfrom
ck89119:issue-28491-main
Sep 11, 2026
Merged

XuPeng-SH merged 21 commits into
matrixorigin:mainfrom
ck89119:issue-28491-main

Conversation

@ck89119

@ck89119 ck89119 commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • BUG

Which issue(s) this PR fixes:

issue #28491

What this PR does / why we need it:

Prevent unary minus from silently wrapping signed integer minimum values. Narrow signed integer operands now produce an int64 result, while BIGINT minimum negation returns a range error.

@matrix-meow matrix-meow added the size/S Denotes a PR that changes [10,99] lines label Sep 9, 2026
@mergify mergify Bot added the kind/bug Something isn't working label Sep 9, 2026

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deep re-review of exact head b157baff87d9d375887ca92fb9f65a1afaeabe56 (base 2a6fe7f61358e846a20aafba3b50903a61608682). I read the complete review, inline-comment, issue-comment, reply, and thread state; both earlier threads remain unresolved and there are no author replies, so I verified the fixes from code rather than relying on thread state. I compared the increment after reviewed head 3b44ea4cd526b3ce9eada703da58c5d0977f3464 and reconciled it with the full nine-file PR diff.

The prior execution-ABI blocker is now closed in both directions: the narrow-result fallback keeps old plans executable on a new worker, and the new v60 feature detection fences widened plans at both remote encode and decode boundaries while the cluster protocol is older. The requested SQL boundary/NULL/CTAS/BIGINT-error coverage is also present. Local exact-head validation passed pkg/sql/plan/function, the unary binder tests in pkg/sql/plan, pkg/pb/plan, and TestRemoteExpressionProtocolValidation; git diff --check is clean. One blocking golden-result inconsistency remains, detailed inline.

@aptend aptend left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Deep re-review completed on exact head c6e2695e47b3174c62cd1bf115a7cde02f945b33 (base 24f2f6ce247cd677f81da0ca69f2aadccbc050f9). I read the full review and inline-comment history, checked every resolved thread against the code, compared the increment after my prior reviewed head b157baff87d9d375887ca92fb9f65a1afaeabe56, and reconciled it with the complete 11-file diff.

The remaining golden-result blocker is closed: the earlier select -c1 from t2 oracle now records BIGINT metadata, and the other existing affected result oracle was updated as well. The earlier mixed-version executor mismatch remains closed by both the legacy narrow-wrapper fallback and the v60 sender/receiver protocol fence. The full implementation still preserves selection/NULL behavior, widens TINYINT/SMALLINT/INT before negation, and returns a range error for evaluated BIGINT minimum values; the SQL regression covers boundary values, result metadata, CTAS, NULL controls, and the BIGINT error.

Exact-head validation passed:

  • TestUnaryRegisteredTypeAndSelection and TestUnaryMinusInt64Overflow in pkg/sql/plan/function
  • TestRemoteExpressionProtocolValidation in pkg/sql/compile
  • TestRefreshSessionAuthRequiresCurrentProtocolVersion in pkg/queryservice/client
  • git diff --check

The current-head CI also reports successful UT coverage and targeted standalone/compose BVT jobs. No blocking issues remain.

# Conflicts:
#	pkg/defines/const.go
#	pkg/queryservice/client/query_client_test.go

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed full current change at a1413db against base 065a675, including prior reviews and fixes. Narrow signed values widen before negation, evaluated BIGINT minimum returns a range error, and NULL/selection controls and the previously inconsistent SQL metadata goldens are addressed. The legacy narrow-result fallback also fixes old-plan execution on a new worker.

One mixed-version blocker remains in the reverse direction, detailed inline. This corrects the earlier review's assumption that the local protocol-version check alone closes both execution-ABI directions: it requires an externally maintained oldest-peer invariant that is not enforced by the new check or the default runtime initialization.

Evidence: inspected current/base registrations, result-wrapper construction, remote expression scanning and encode/decode validation, runtime version initialization/setter, and new UT/BVT controls. This follow-up is source-based; no fresh SQL, two-version cluster, UT or benchmark execution is claimed, and CI was not awaited. No additional arithmetic, shared-state, resource-lifecycle or normal-path asymptotic blocker found.

Comment thread pkg/sql/compile/remoterun.go Resolved

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Re-reviewed the full current change and prior requested changes at b52d616 (base main, 2cecab5). No remaining concrete blocker found.

The previous mixed-version physical type conflict is resolved by lowering new TINYINT/SMALLINT/INT negations to an explicit BIGINT cast and the historical BIGINT overload 3, while preserving overloads 0/1/2 for serialized legacy plans. This avoids relying on a sender-local protocol-version variable to establish peer compatibility. Reviewed the binder cast path, signed-minimum overflow detection, NULL/selection masking, float and ordinary-value controls, and unchanged unsigned/decimal paths.

The added SQL boundary/CTAS assertions and corrected existing metadata goldens address the earlier public-result oracle finding. The focused Go tests cover new dispatch, legacy result wrappers, BIGINT minimum (including constant input), NULL/masked rows, and unrelated controls. The widening adds a bounded cast/vector cost for narrow operands; no new state ownership or unbounded allocation is introduced.

Validation: exact-head source/diff and review-history inspection; no fresh native UT/BVT or mixed-version deployment was executed in this review, and CI was not awaited. Legacy workers naturally retain their old BIGINT-overflow behavior until upgraded; the serialized argument/result contract is now compatible.

@mergify

mergify Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-09-11 11:03 UTC · Rule: main · triggered by rule Automatic queue on approval for main
  • 🟠 Checks running · in-place
  • 🚫 Left the queue — 2026-09-11 11:12 UTC · at 1ce96e2f0402d67556358cb19d6e9fed9310a831

This pull request spent 9 minutes 38 seconds in the queue, with no time running CI.

Waiting for any of
  • check-neutral = CI Required
  • check-skipped = CI Required
  • check-success = CI Required
All conditions

Reason

Pull request #28499 has been dequeued

Pull request from fork cannot be queued. This pull request comes from a fork, and Mergify needs the author's permission to update its branch.

The author needs to enable "Allow edits from maintainers" on this pull request.

Hint

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.
If you do update this pull request, it will automatically be requeued once the queue conditions match again.
If you think this was a flaky issue instead, you can requeue the pull request, without updating it, by posting a @mergifyio queue comment.

Tick the box to put this pull request back in the merge queue (same as @mergifyio queue).

  • Requeue this pull request

This branch was previously deployed

1 inactive deployment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants