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 checkptr in AddString64 #13

Closed
wants to merge 1 commit into from
Closed

Fix checkptr in AddString64 #13

wants to merge 1 commit into from

Conversation

somnusfish
Copy link

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
Copy link
Contributor

yerden commented Jan 6, 2023

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
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