← Back to Pull requests

MDEV-42453 Stack-buffer-overflow write in dynamic-column backwritenum on numeric key ≥ 7 digits #6234

Open
unknown opened this pull request with 234 lines diff across 2 files
View on GitHub
unknown unknown commented on Nov 26, 2026 04:13 UTC
Author

MDEV-42453 Stack-buffer-overflow write in dynamic-column backwritenum on numeric key ≥ 7 digits

find_column() renders a numeric lookup key into
nmkeybuff[DYNCOL_NUM_CHAR] with backwritenum(), which writes decimal
digits backward from the end of the buffer without a terminator.
DYNCOL_NUM_CHAR is 6, so a lookup key with 7 or more digits writes
before the start of the buffer: a stack-buffer-overflow WRITE
reachable through COLUMN_GET on a string-format dynamic column.

Limit numeric column keys to DYNCOL_NUM_KEY_MAX (65535, the largest
stored 2-byte key) consistently across all layers. The macro lives
in ma_dyncol.h; find_column() reports not-found (DYN_COL_NULL) for
larger numeric keys before calling backwritenum(), so the buffer
stays at DYNCOL_NUM_CHAR. Names above the limit remain reachable by
string key.

The SQL layer had inconsistent checks: get_dyn_value() accepted
keys up to INT_MAX and Item_func_dyncol_exists::val_bool() up to
UINT_MAX16. Replace both with a shared dyncol_get_offset_arg()
helper that rejects NULL, negative and out-of-range keys, so
COLUMN_GET and COLUMN_EXISTS enforce the same uint16 limit.

Add test_mdev_42453() to the ma_dyncol-t unit test (reproduces the
overflow under ASan before this change, then checks the boundary
and string-key access to larger names) and SQL regression cases to
main.dyncol.

---

Any user who can run a SELECT can trigger the crash:

SELECT COLUMN_GET(COLUMN_CREATE('a',1), 1000000 AS INT);

Verified with AddressSanitizer on main and 10.11: ma_dyncol-t aborts
with the stack-buffer-overflow WRITE in backwritenum() before this
change and passes cleanly after; main.dyncol passes with the new
result file.

This contribution is licensed under the 3-clause BSD license (the MCA
can be accepted instead).

Targeting 10.11 as the oldest affected maintained LTS branch; happy to
retarget on request.

Diff: 234 lines (+175 / -59) across 2 files Reviewer: gkodinov Review duration: 7323m
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.37) × (1 − Review Confidence (0.43)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.37 · 234 lines diff across 2 files
0.37
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
42%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth shallow_review_depth
0.344
Diff Size diff_size
0.327
Real PR Conversation Timeline
1 comments
"Review active on #6234"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 43.0% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 37.1% (MEDIUM) · Higher = larger blast radius
37.1%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 43.0% · Lower = rushed or shallow review
43.0%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 21.2% · Safe to merge
21.2%
Repository