Skip to content

GH-50699: [C++] Fix ComputeLogicalNullCount crash for null-typed dictionaries - #50770

Open
goel-skd wants to merge 1 commit into
apache:mainfrom
goel-skd:gh-50699-dict-logical-null-count-null-values
Open

goel-skd wants to merge 1 commit into
apache:mainfrom
goel-skd:gh-50699-dict-logical-null-count-null-values

Conversation

@goel-skd

@goel-skd goel-skd commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

The dictionary of a dictionary(..., null()) array is a NullArray, which reports null_count == length but has no validity bitmap. dict_util::LogicalNullCount only skipped its per-index scan when the dictionary's null count was 0, so for these arrays the scan read through a null bitmap pointer and crashed.

What changes are included in this PR?

Return the array's length when the dictionary has nulls but no validity bitmap. Every value in such a dictionary is null, so there is nothing to scan.

Are these changes tested?

Yes, in TestArray.TestNullCount for all index types, and in TestArray.TestSlicePreservesAllNullCount for a slice. Two of the new cases crash without the fix.

Are there any user-facing changes?

ComputeLogicalNullCount() no longer crashes on these arrays, and neither does the count kernel, which calls it.

This PR contains a "Critical Fix". It fixes a crash on valid input.

@goel-skd

Copy link
Copy Markdown
Contributor Author

@pitrou - Ready for review when you get a chance :)

@pitrou pitrou left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, just a minor suggestion

if (!dictionary_span.HasValidityBitmap()) {
// The dictionary has nulls but no validity bitmap to inspect, which means all
// of its values are null (a null-typed dictionary). Every index, valid or not,
// is then logically null.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Perhaps DCHECK that the dictionary's type is Type::NA?

@github-actions github-actions Bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Aug 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants