-
Notifications
You must be signed in to change notification settings - Fork 548
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: hertz panic when edit ctx.Params on HandleFunc #1150
fix: hertz panic when edit ctx.Params on HandleFunc #1150
Conversation
把 reset 里的逻辑挪到这里判断吧 https://github.com/cloudwego/hertz/blob/develop/pkg/route/engine.go#L753。这里是离使用最近的一个地方,怕还有其他的地方有一些错误使用,导致这里 panic 了。 |
改了,由于这个逻辑移动到了 |
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.
LGTM,thanks~
What type of PR is this?
fix
Check the PR title.
(Optional) Translate the PR title into Chinese.
修复因用户在 HandleFunc 中修改 ctx.Params 值导致的 panic
(Optional) More detailed description for this PR(en: English/zh: Chinese).
en: This panic is happening because
RequestContext.ResetWithoutConn
only reset the length of Params (slice), not the array itself. Therefore, if the Params is re-assigned to another array by the user, it is possible that the capacity is not enough, leading to an out of bound array index. To fix this, we need to compare the current capacity and the expected capacity inRequestContext.ResetWithoutConn
, and if they do not match, realloc Params.zh(optional):
(Optional) Which issue(s) this PR fixes:
Fixes #1149
(Optional) The PR that updates user documentation: