-
Notifications
You must be signed in to change notification settings - Fork 3.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
encoding: fix UnsafeConvertStringToBytes to work with large input strings #111627
encoding: fix UnsafeConvertStringToBytes to work with large input strings #111627
Conversation
@@ -913,18 +913,7 @@ func prettyPrintInvertedIndexKey(b []byte) (string, []byte, error) { | |||
// modified if the input string is expected to be used again - doing so could | |||
// violate Go semantics. | |||
func UnsafeConvertStringToBytes(s string) []byte { | |||
if len(s) == 0 { |
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.
If the go docs are to be believed I think we need to leave in the zero length check. https://pkg.go.dev/unsafe#StringData
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.
Ok, added this back.
Thanks for the quick fix! |
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @ecwall and @j82w)
pkg/util/encoding/encoding.go
line 999 at r2 (raw file):
// Next we treat the string data as a maximally sized array which we // slice. This usage is safe because the pointer value remains in the string. arg := (*[0x7fffffff]byte)(unsafe.Pointer(hdr.Data))[:len(s):len(s)]
We should fix this one too
Good catch. |
I think the test might be failing because the |
The inner
I think the test needs to be skipped under stress because of the large input. |
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @cucaroach, @ecwall, and @j82w)
-- commits
line 11 at r4:
nit: the public facing release notes should not reference an internal function name in our code base. can this be rephrased so something more high level? like "Fixed a panic that could occur if a query uses a string larger than 2^32 bytes."
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.
Reviewable status: complete! 0 of 0 LGTMs obtained (waiting on @cucaroach, @j82w, and @rafiss)
Previously, rafiss (Rafi Shamim) wrote…
nit: the public facing release notes should not reference an internal function name in our code base. can this be rephrased so something more high level? like "Fixed a panic that could occur if a query uses a string larger than 2^32 bytes."
The function name appears in the error output because of the panic so I thought it would make sense to reference it here so customers can identify if they had this problem. I don't have a strong opinion though so I will change it (also, it is 2^31-1 bytes).
…ings Fixes #111626 The previous impl assumed input string length <= math.MaxInt32. Go 1.20 added unsafe.StringData (https://pkg.go.dev/unsafe#StringData) which properly handles longer strings. This changes the impl to use unsafe.StringData and adds a unit test. Release note (bug fix): Fixed a panic that could occur if a query uses a string larger than 2^31-1 bytes.
bors r+ |
Build succeeded: |
Fixes #111626
The previous impl assumed input string length <= math.MaxInt32. Go 1.20 added unsafe.StringData (https://pkg.go.dev/unsafe#StringData) which properly handles longer strings. This changes the impl to use unsafe.StringData and adds a unit test.
Release note (bug fix): Fixed a panic that could occur if a query uses a string
larger than 2^31-1 bytes.