Uh oh!
There was an error while loading. Please reload this page.
GH-51135: [C++][Parquet] Avoid misaligned stores when reading BYTE_ARRAY decimals - #51136
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The change directly resolves the misaligned-store UB risk with a safe, already-included <cstring>-backed approach and is consistent with existing usage in the same file.
Pull request overview
Fixes undefined behavior in the Parquet BYTE_ARRAY-to-decimal conversion path by avoiding potentially misaligned uint64_t stores when initializing output buffers for Decimal32/64/128/256, aligning with the UBSan issue in #51135.
Changes:
- Replace fixed
uint64_tzeroing stores withstd::memset(out_ptr, 0, type_length)in the BYTE_ARRAY decimal converter.
File summaries
| File | Description |
|---|---|
| cpp/src/parquet/arrow/reader_internal.cc | Uses std::memset to zero decimal output slots safely regardless of alignment, preventing misaligned stores for Decimal32 BYTE_ARRAY reads. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
HuaHuaY
left a comment
There was a problem hiding this comment.
LGTM.
But I’m wondering: given that unit tests exist, why hasn't Valgrind ever detected this buffer overflow?
HuaHuaY
commented
Sep 2, 2026
It may be that |
Thanks to @wgtmac for fixing this issue. |
Rationale for this change
The BYTE_ARRAY decimal converter always clears 16 bytes through
uint64_tstores. After Decimal32/64 support was added, Decimal32 output slots can be only 4-byte aligned, causing undefined behavior.What changes are included in this PR?
Replace the fixed
uint64_tstores withstd::memset(out_ptr, 0, type_length).Are these changes tested?
Yes. The existing Decimal32/64/128/256 BYTE_ARRAY tests all pass. No new test is needed because
TestReadDecimals.Decimal32ByteArraydirectly exercises this path.Are there any user-facing changes?
No, this is a bug fix.
AI usage: OpenAI Codex was used to investigate and draft this change. The patch was reviewed and tested locally.