MDEV-42453 Stack-buffer-overflow write in dynamic-column backwritenum on numeric key ≥ 7 digits #6234
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
gkodinov
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.