Skip to content

Commit

Permalink
fix: unmarshal string array wrong cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
muktihari committed Dec 18, 2023
1 parent 2c8b431 commit 77ada8a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions profile/typedef/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,23 @@ func Unmarshal(b []byte, bo binary.ByteOrder, ref basetype.BaseType, isArray boo
case basetype.String:
if isArray {
var size byte
last := 0
for i := range b {
if b[i] == '\x00' {
size++
if last != i { // only if not an invalid string
size++
}
last = i + 1
}
}
last := 0
last = 0
vs := make([]string, 0, size)
for i := range b {
if b[i] == '\x00' {
vs = append(vs, string(b[last:i]))
last = i + i
if last != i { // only if not an invalid string
vs = append(vs, string(b[last:i]))
}
last = i + 1
}
}
return vs, nil
Expand Down

0 comments on commit 77ada8a

Please sign in to comment.