fix(sql): segfault when using touch() on a table with a new empty column#6561
fix(sql): segfault when using touch() on a table with a new empty column#6561bluestreak01 merged 3 commits intomasterfrom
touch() on a table with a new empty column#6561Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughAdded defensive null-checks in the touch table function to skip processing empty memory regions with zero base addresses, preventing segmentation faults when cached query plans are reused after table schema modifications. Includes a corresponding test case validating the fix. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
core/src/main/java/io/questdb/griffin/engine/functions/table/TouchTableFunctionFactory.java (1)
173-177: Critical segfault fix - null-check prevents crash.This null-check correctly addresses the reported segfault that occurred when touch() was called after adding an empty column to a table. The defensive guard prevents
Unsafe.getBytefrom accessing invalid memory at address 0.Consider using
LOG.debug()instead ofLOG.info()if empty columns are a common scenario in normal operations, to reduce log verbosity.core/src/test/java/io/questdb/test/griffin/engine/functions/TouchTableFunctionTest.java (1)
45-81: Test correctly validates the segfault fix.This test reproduces the exact crash scenario from issue #6560: creating a table, running touch(), altering to add a column, then running touch() again. The test validates:
- No segfault occurs when touching after
ALTER TABLE ADD COLUMN- Touch results remain consistent when the new column is empty (lines 73-74)
- Touch results update correctly after populating the new column (line 79)
Consider adding a test case for indexed columns with empty data to validate the index-specific null-checks at lines 187-190 and 196-199 of TouchTableFunctionFactory.java.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
core/src/main/java/io/questdb/griffin/engine/functions/table/TouchTableFunctionFactory.java(2 hunks)core/src/test/java/io/questdb/test/griffin/engine/functions/TouchTableFunctionTest.java(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (36)
- GitHub Check: New pull request (SelfHosted Running tests with cover on linux-other)
- GitHub Check: New pull request (SelfHosted Running tests with cover on linux-pgwire)
- GitHub Check: New pull request (SelfHosted Running tests with cover on linux-cairo-sub)
- GitHub Check: New pull request (SelfHosted Running tests with cover on linux-cairo-root)
- GitHub Check: New pull request (SelfHosted Running tests with cover on linux-fuzz2)
- GitHub Check: New pull request (SelfHosted Running tests with cover on linux-fuzz1)
- GitHub Check: New pull request (SelfHosted Running tests with cover on linux-griffin-sub)
- GitHub Check: New pull request (SelfHosted Running tests with cover on linux-griffin-root)
- GitHub Check: New pull request (Rust Test and Lint on linux-jdk17)
- GitHub Check: New pull request (Trigger Enterprise CI Trigger Enterprise Pipeline)
- GitHub Check: New pull request (SelfHosted Other tests on linux-x64-zfs)
- GitHub Check: New pull request (SelfHosted Other tests on linux-x86-graal)
- GitHub Check: New pull request (SelfHosted Griffin tests on linux-x86-graal)
- GitHub Check: New pull request (SelfHosted Other tests on linux-arm64)
- GitHub Check: New pull request (SelfHosted Cairo tests on linux-x64-zfs)
- GitHub Check: New pull request (SelfHosted Cairo tests on linux-x86-graal)
- GitHub Check: New pull request (SelfHosted Griffin tests on linux-x64-zfs)
- GitHub Check: New pull request (SelfHosted Cairo tests on linux-arm64)
- GitHub Check: New pull request (SelfHosted Griffin tests on linux-arm64)
- GitHub Check: New pull request (Hosted Running tests on windows-other-2)
- GitHub Check: New pull request (Hosted Running tests on windows-other-1)
- GitHub Check: New pull request (Hosted Running tests on windows-pgwire)
- GitHub Check: New pull request (Hosted Running tests on windows-cairo-2)
- GitHub Check: New pull request (Hosted Running tests on windows-cairo-1)
- GitHub Check: New pull request (Hosted Running tests on windows-fuzz2)
- GitHub Check: New pull request (Hosted Running tests on windows-fuzz1)
- GitHub Check: New pull request (Hosted Running tests on windows-griffin-sub)
- GitHub Check: New pull request (Hosted Running tests on windows-griffin-base)
- GitHub Check: New pull request (Hosted Running tests on mac-other)
- GitHub Check: New pull request (Hosted Running tests on mac-pgwire)
- GitHub Check: New pull request (Hosted Running tests on mac-cairo-fuzz)
- GitHub Check: New pull request (Hosted Running tests on mac-cairo)
- GitHub Check: New pull request (Hosted Running tests on mac-griffin)
- GitHub Check: New pull request (Check Changes Check changes)
- GitHub Check: build
- GitHub Check: build
🔇 Additional comments (2)
core/src/main/java/io/questdb/griffin/engine/functions/table/TouchTableFunctionFactory.java (2)
187-190: Indexed column key protection - consistent with data column check.The null-check for empty index key memory is correctly placed and prevents segfaults when touching indexed columns with no key data.
196-199: Indexed column value protection completes the defensive coverage.This third null-check ensures all memory access points in the touch operation are protected from null pointer dereferences. The fix comprehensively addresses the segfault risk.
- Single point of validation instead of 3 separate checks - Remove noisy INFO-level logging for normal operation - All callers automatically protected 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
[PR Coverage check]😍 pass : 2 / 2 (100.00%) file detail
|
Fixes #6560
When a new column is added to a table, it is initially empty. When you call
frame.getPageAddressto get the column's base memory address, this empty column is uninitialised, and therefore returns an address of 0.Unfortunately, touch() did not check this possibility, so would use the nullptr.
Additionally added checks for indexes. We do not have a repro for this, and theoretically the prior issue should hit before the index is tried, but makes sense to add these for safety.