Skip to content

Off-by-one error in Strings.peel #762

@reuster986

Description

@reuster986

The inner for loops in the following code should iterate over 0..#(len-1), not 0..#len:

https://github.com/mhmerrill/arkouda/blob/5c4d04a15ca6fb150223a789bc43a70e393ac34c/src/SegmentedArray.chpl#L619-L630

Background: the peel function splits strings into left and right portions based on a delimiter. After the logic of finding the split point is all complete, this code copies the bytes of the left and right portions into their respective destination arrays. The leftLengths and rightLengths arrays are supplying the full lengths of the destination buffers, including the null byte, i.e. one greater than the actual length of the substring to be copied. Thus, when the code copies #len bytes from the source buffer, it is grabbing an extra byte from the source string and overwriting the destination's null terminator with it. This results in strings that are not null-terminated and misbehave in weird and hard-to-find ways.

As part of this issue, we should consider adding validation on the ak.Strings class that checks for null terminators, and/or a CI test that checks for null-terminators after a peel operation. I am hopeful that resolving this issue will also address the sporadic CI failures for peel/stick and allow us to move this from experimental to fully supported functionality.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions