fix: tracelog truncation makes output longer than original#2588
Closed
xbrxr03 wants to merge 1 commit into
Closed
Conversation
logQueryArgs used fmt.Sprintf with a verbose suffix like '(truncated N bytes)' that could make the output longer than the original value: - A 65-byte string truncated to 64 bytes + ' (truncated 1 bytes)' = 84 bytes (29 bytes longer than original) - A 65-byte slice showed 128 hex chars + suffix = 150+ chars Replace the verbose suffix with an ellipsis (…) and ensure the truncated result is always strictly shorter than the original: - []byte: show first 60 bytes as hex (120 chars) + '…' - string: truncate at a rune boundary so that len(result) < len(original) Fixes jackc#2095
Author
|
Closing this PR due to lack of maintainer engagement. I'm happy to reopen if there's interest. Thanks for the great project. |
Owner
🤷♂️ It's a non-commercial project. I maintain it on nights and weekends. So if it's not an emergency it may take a few weeks for me to take a look. As far as this particular issue though, if anything is to be done, I would see it as two changes.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
logQueryArgstruncates long strings and byte slices, but the truncation suffix makes the output longer than the original value:" (truncated 1 bytes)"= 84 bytes — 29 bytes longer than the original" (truncated 1 bytes)"= 150+ chars — much longer than the 130-char full hex encodingReported in #2095.
Fix
Replace the verbose
fmt.Sprintfsuffix with an ellipsis (…) and ensure the truncated result is always strictly shorter than the original:[]byte: Show first 60 bytes as hex (120 chars) +…= 123 chars, always shorter than the 130+ char full hexstring: Truncate at a rune boundary so thatlen(result) < len(original), usingmaxCut = len(v) - 4to account for the 3-byte ellipsisAlso fixed the off-by-one:
[]bytethreshold was< 64(excluding 64-byte slices) butstringwas> 64(excluding 65+ byte strings). Now both use<= 64/> 64consistently.Tests
Added
TestLogQueryArgsTruncationwith 5 subtests:…and are strictly shorter than the original…and are shorter than full hexFixes #2095