-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Safely truncate over-length string attributes #3156
Safely truncate over-length string attributes #3156
Conversation
This needs at least one more test. ;) |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #3156 +/- ##
=====================================
Coverage 76.3% 76.3%
=====================================
Files 180 180
Lines 11992 12009 +17
=====================================
+ Hits 9153 9169 +16
- Misses 2597 2598 +1
Partials 242 242
|
PTAL. I had to rewrite the fallback case; when there is invalid UTF-8 it calls strings.ToValidUTF8 and then re-applies the same (safe) truncation logic. |
The costly operation in this call is the ToValidUTF8, because it has to iterate over the entire string. So this means how you have it now we iterate over the string once, try to apply the limit, and iterate a second time. I think an alternative but still valid interpretation would be to apply the limit, and then filter bad unicode. This would mean that if there bad points in the beginning of the string they would count toward the limit, even if they aren't in the output string. |
The way the code is organized, |
Co-authored-by: Tyler Yahn <MrAlias@users.noreply.github.com>
…o jmacd/safe_truncation
…y-go into jmacd/safe_truncation
Personally, I consider this an urgent matter and I would be willing to waive our ordinary wait period for PRs to merge after approvals. I suggest this because it's been about 4 weeks since the last release, and if we don't include this fix there will be immediate pressure to make another release. @open-telemetry/go-maintainers what do you think? |
I'm fine merging this early. That said, @MadVikingGod has decided to hold off the release until Monday to make sure this is included. |
This fixes invalid UTF-8 introduced by our truncation logic.
This does not address the problem of invalid UTF-8 being passed in by users, but it does at least ensure the SDK is not responsible for invalid UTF-8 itself.
Fixes #3021