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

fix: fix seg fault in concat_str of empty series #11704

Merged
merged 1 commit into from
Oct 13, 2023

Conversation

reswqa
Copy link
Collaborator

@reswqa reswqa commented Oct 13, 2023

This fixes #11701.

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Oct 13, 2023
@reswqa reswqa marked this pull request as ready for review October 13, 2023 04:32
@ritchie46 ritchie46 merged commit 7134442 into pola-rs:main Oct 13, 2023
24 checks passed
@orlp
Copy link
Collaborator

orlp commented Oct 13, 2023

I don't think this fully addresses the problem. Why did a segfault occur? My implementation was entirely in safe code. Something else needs to be changed.

@reswqa
Copy link
Collaborator Author

reswqa commented Oct 13, 2023

@orlp The segment fault caused by unsafe { arr.get_unchecked(arr_idx) } where arr has length 0, and arr_idx is 0, seems that this is not meet the SAFETY requirement arr_idx < arr.len(). Maybe some other thing need to be changed 🤔 .

pub fn get(&self, idx: usize) -> Option<T::Physical<'_>> {
        let (chunk_idx, arr_idx) = self.index_to_chunked_index(idx);
        let arr = self.downcast_get(chunk_idx)?;

        // SAFETY: if index_to_chunked_index returns a valid chunk_idx, we know
        // that arr_idx < arr.len().
        unsafe { arr.get_unchecked(arr_idx) }
    }

@orlp
Copy link
Collaborator

orlp commented Oct 13, 2023

@reswqa Ah, the problem is that index_to_chunked_index has this fast-path: https://github.com/pola-rs/polars/blob/main/crates/polars-core/src/chunked_array/ops/downcast.rs#L100

        if self.chunks.len() == 1 {
            return (0, index);
        }

If the index is not found in chunk 0 it should return chunk 1, so this fast path is incorrect.

@reswqa
Copy link
Collaborator Author

reswqa commented Oct 13, 2023

@orlp, good catch, this should be the culprit. Will fix this.

@orlp
Copy link
Collaborator

orlp commented Oct 13, 2023

@reswqa I'm curious, could you then remove the check from this again? I believe it should've just worked. If it's still broken just leave the check in place.

@reswqa
Copy link
Collaborator Author

reswqa commented Oct 13, 2023

@orlp Sure, I'm on the way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segmentation fault when concatenating strings after casting with empty dataframe
3 participants