Skip to content

Fix checkptr in AddString64#13

Closed
somnusfish wants to merge 1 commit into
segmentio:masterfrom
somnusfish:fix-checkptr
Closed

Fix checkptr in AddString64#13
somnusfish wants to merge 1 commit into
segmentio:masterfrom
somnusfish:fix-checkptr

Conversation

@somnusfish

Copy link
Copy Markdown

Related issue : #12

Root cause:

According to https://pkg.go.dev/unsafe#Pointer, Unlike in C, it is not valid to advance a pointer just beyond the end of its original allocation:

// INVALID: end points outside allocated space.
var s thing
end = unsafe.Pointer(uintptr(unsafe.Pointer(&s)) + unsafe.Sizeof(s))

// INVALID: end points outside allocated space.
b := make([]byte, n)
end = unsafe.Pointer(uintptr(unsafe.Pointer(&b[0])) + uintptr(n))

The original logic hit the edge case when the length of the string could be divided by 8.

Solution

Handle the edge case using if condition, please refer the code for details.

Testing

Local fuzz test.

@yerden

yerden commented Jan 6, 2023

Copy link
Copy Markdown
Contributor

hi @somnusfish thanks for a fix. I managed to slightly improve readability if you don't mind. You could take over my code in #14 or @achille-roussel may green light it as it is.

@somnusfish

Copy link
Copy Markdown
Author

Hi @yerden , thanks for the feedback. I took over your code since it is much faster and better readable.

@somnusfish somnusfish closed this by deleting the head repository Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants