-
Notifications
You must be signed in to change notification settings - Fork 18k
strings.Split method panic #56741
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
Comments
Where does the string come from? constructed with |
It looks like strings is a null |
func (s *authSessions) getClientInfo() *ClientInfo { if s.client.Layer == 0 || s.client.Langpack == "" || s.client.AppVersion == "" { v, err := gCacheAuthManager.GetAuthSession(s.authKeyId) if err != nil { log.Warnf("authSessions - GetAuthSession: %v", err) } if v != nil { client := &ClientInfo{ ApiId: v.ApiId, DeviceModel: v.DeviceModel, AppVersion: v.AppVersion, SystemVersion: v.SystemVersion, SystemLangcode: v.SystemLangCode, Langpack: v.LangPack, Langcode: v.LangCode, Layer: v.Layer, } s.setClientInfo(client, false) } } s.clientLocker.RLock() defer s.clientLocker.RUnlock() client := &ClientInfo{} copyClientInfo(client, &s.client) return client } func (s *authSessions) setClientInfo(v *ClientInfo, upload bool) { s.clientLocker.Lock() defer s.clientLocker.Unlock() var changed bool if v.Layer != 0 && s.client.Layer != v.Layer { s.client.Layer = v.Layer changed = true } if v.ClientIP != "" && s.client.ClientIP != v.ClientIP { s.client.ClientIP = v.ClientIP //changed = true } if v.ApiId != 0 && s.client.ApiId != v.ApiId { s.client.ApiId = v.ApiId changed = true } if v.Langcode != "" && s.client.Langcode != v.Langcode { s.client.Langcode = v.Langcode changed = true } if v.Langpack != "" && s.client.Langpack != v.Langpack { s.client.Langpack = v.Langpack changed = true } if v.AppVersion != "" && s.client.AppVersion != v.AppVersion { s.client.AppVersion = v.AppVersion changed = true } if v.SystemVersion != "" && s.client.SystemVersion != v.SystemVersion { s.client.SystemVersion = v.SystemVersion changed = true } if v.DeviceModel != "" && s.client.DeviceModel != v.DeviceModel { s.client.DeviceModel = v.DeviceModel changed = true } if v.SystemLangcode != "" && s.client.SystemLangcode != v.SystemLangcode { s.client.SystemLangcode = v.SystemLangcode changed = true } return } func copyClientInfo(dst, src *ClientInfo) { dst.Layer = src.Layer dst.ApiId = src.ApiId dst.DeviceModel = string([]byte(src.DeviceModel)) dst.AppVersion = string([]byte(src.AppVersion)) dst.SystemVersion = string([]byte(src.SystemVersion)) dst.SystemLangcode = string([]byte(src.SystemLangcode)) dst.Langpack = string([]byte(src.Langpack)) dst.Langcode = string([]byte(src.Langcode)) dst.ClientIP = string([]byte(src.ClientIP)) dst.CountryCode = string([]byte(src.CountryCode)) } Here is my code to give initial value to ip variable |
That first string argument looks like it has a nil pointer but a non-zero length. That should never happen. Please run your code under the race detector. Racy writes are one way such an invalid string might be produced. I don't know if we're going to be able to help you more without a way to reproduce. The problem is not with |
@randall77 This may help. I think some deserialize libraries might change []byte type into string just for performance. package main
import (
"fmt"
"reflect"
"unsafe"
)
var unsafestrptr = *(*string)(unsafe.Pointer(
&reflect.StringHeader{
Data: 0,
Len: 12}))
func main() {
fmt.Println("Hello, 世界", unsafestrptr)
} |
Timed out in state WaitingForInfo. Closing. (I am just a bot, though. Please speak up if this is a mistake or you have the requested information.) |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
No
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
When calling the go strings.Split method, it sometimes panics.
What did you expect to see?
string sclice
What did you see instead?
The text was updated successfully, but these errors were encountered: