Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for NULL offset for caggs built on top of caggs (#7272) #7290

Merged
merged 1 commit into from
Sep 26, 2024

Conversation

zilder
Copy link
Contributor

@zilder zilder commented Sep 23, 2024

The check was missing causing instance crash due to null pointer dereference in cases when one cagg was built on top of another and either of them had non-NULL offset and the other had NULL offset. See #7272 for an example.

Closes #7272

Copy link

codecov bot commented Sep 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 92.31%. Comparing base (59f50f2) to head (299d5b2).
Report is 362 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #7290       +/-   ##
===========================================
+ Coverage   80.06%   92.31%   +12.25%     
===========================================
  Files         190      205       +15     
  Lines       37181    38597     +1416     
  Branches     9450    10001      +551     
===========================================
+ Hits        29770    35632     +5862     
+ Misses       2997     2961       -36     
+ Partials     4414        4     -4410     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zilder zilder marked this pull request as ready for review September 23, 2024 14:50
@zilder zilder self-assigned this Sep 23, 2024
Copy link
Contributor

@erimatnor erimatnor left a comment

Choose a reason for hiding this comment

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

Approving since this change seems to work, but I have some suggestions for possible improvements for clarity.

@@ -1060,9 +1060,14 @@ cagg_validate_query(const Query *query, const bool finalized, const char *cagg_s

if (!both_buckets_are_equal)
{
char *offset = DatumGetCString(DirectFunctionCall1(interval_out, offset_datum));
char *offset =
Copy link
Contributor

Choose a reason for hiding this comment

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

While this probably works, I am wondering if we shouldn't check this further up around line 1044.

It seems one of the bucket_time_offsets is NULL, so I think we should have NULL check on the original C pointer before trying to convert to a Datum. We should probably not call IntervalPGetDatum() on a NULL pointer to begin with and check the bucket_time_offset_pointer instead. One alternative is to also use a NullableDatum to pass this info down.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review, @erimatnor!

I think using NullableDatum would make sense for datums stored by value. Interval is stored as a pointer so we can just compare it with NULL directly. And IntervalPGetDatum just converts the pointer type to datum, doesn't dereference it.

#define IntervalPGetDatum(X) PointerGetDatum(X)

So while I could implement what you are suggesting, I'm not sure it is really needed here.

@fabriziomello
Copy link
Contributor

@zilder please add a changelog entry in the .unreleased folder and add @snyrkill to the thanks session since he reported the bug.

…7272)

The check was missing causing instance crash due to null pointer
dereference in cases when one cagg was built on top of another and
either of them had non-NULL offset and the other had NULL offset.
@zilder zilder merged commit 7c5dbbb into timescale:main Sep 26, 2024
39 checks passed
@timescale-automation
Copy link

Automated backport to 2.16.x not done: cherry-pick failed.

Git status

HEAD detached at origin/2.16.x
You are currently cherry-picking commit 7c5dbbbd0.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   .unreleased/pr_7290
	modified:   tsl/src/continuous_aggs/common.c

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	both modified:   tsl/test/expected/cagg_query.out
	deleted by us:   tsl/test/expected/cagg_query_using_merge.out
	deleted by us:   tsl/test/sql/include/cagg_query_common.sql


Job log

@timescale-automation timescale-automation added the auto-backport-not-done Automated backport of this PR has failed non-retriably (e.g. conflicts) label Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport-not-done Automated backport of this PR has failed non-retriably (e.g. conflicts) bug continuous_aggregate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segfault when creating a CAGG with bucket offset.
5 participants