-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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 improper memory reuse in NewFastHTTPHandler #1860
Conversation
header.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fasthttp/fasthttpadaptor/request.go
Lines 58 to 62 in c305051
case "Transfer-Encoding": | |
r.TransferEncoding = append(r.TransferEncoding, sv) | |
default: | |
r.Header.Set(sk, sv) | |
} |
I think performing deep copying through a case branch would be more appropriate here, as the comment in Request.VisitAll mentions that key and value cannot be referenced after the function f finishes executing. Directly modifying VisitAll may affect its efficiency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree :) I have revised and made a new commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following your initial approach, it would be better to perform a deep copy only for the cookie header. The other references likely don't have any issues.If a deep copy of the value is needed here, the key should also be copied. It seems that either solution could work; it's just a trade-off between performance and memory safety.From a personal perspective. what do you think? @erikdubbelboer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense, I added a new commit to limit deep copy to the cookie case only. If there are further results on the tradeoff between performance and memory safety, I'll be happy to continue to make changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
Thanks! |
Hi Developers,
This pull request fixes the improper memory reuse in NewFastHTTPHandler reported in this issue.
If there are any further adjustments or improvements you'd like me to make, please don't hesitate to reach out :)
Best regards!