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: resp set trailer will panic #1102

Merged
merged 2 commits into from
May 10, 2024

Conversation

wzekin
Copy link
Contributor

@wzekin wzekin commented Apr 28, 2024

What type of PR is this?

fix

Check the PR title.

  • This PR title match the format: <type>(optional scope): <description>
  • The description of this PR title is user-oriented and clear enough for others to understand.
  • Attach the PR updating the user documentation if the current PR requires user awareness at the usage level. User docs repo

(Optional) Translate the PR title into Chinese.

修复当使用 ResponseHeader.Set/Add 设置 Trailer 时,有可能会 panic 的问题

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en: ResponseHeader.Set/Add method uses bytesconv.S2b method to reduce string copying, while SetTrailer modifies data in place using utils.NormalizeHeaderKey. However, if the string used for setting the header comes from RODATA, it can cause a segmentation fault.
Solution: make a copy of the header value when calling SetTrailer, to avoid modifying the data in place.

zh(optional): ResponseHeader.Set/Add 使用了 bytesconv.S2b 方法来减少 string 的拷贝,而 SetTrailer 会使用 utils.NormalizeHeaderKey 来原地修改数据,这是如果设置 Header 使用的 string 来自 RODATA,那么会造成段错误
解决方案:在 SetTrailer 时拷贝一次 header value

(Optional) Which issue(s) this PR fixes:

(Optional) The PR that updates user documentation:

@wzekin wzekin requested review from a team as code owners April 28, 2024 09:33
Duslia
Duslia previously approved these changes Apr 28, 2024
Copy link

codecov bot commented Apr 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.81%. Comparing base (b7cbc9d) to head (7a9b04a).
Report is 13 commits behind head on develop.

❗ Current head 7a9b04a differs from pull request most recent head c41a858. Consider uploading reports for the commit c41a858 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1102      +/-   ##
===========================================
+ Coverage    82.79%   82.81%   +0.02%     
===========================================
  Files           98       98              
  Lines        10032    10033       +1     
===========================================
+ Hits          8306     8309       +3     
+ Misses        1236     1235       -1     
+ Partials       490      489       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Duslia Duslia enabled auto-merge (squash) May 10, 2024 08:02
@Duslia Duslia force-pushed the fix/resp_set_trailer_panic branch from c41a858 to a0dec71 Compare May 10, 2024 08:02
@Duslia Duslia merged commit cbd63c6 into cloudwego:develop May 10, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants