Skip to content

fix(gconv): prevent panic when binding array type (uuid.UUID) parameters (#4786) - #4820

Open
waterWang wants to merge 1 commit into
gogf:masterfrom
waterWang:fix/gconv-array-isnil-panic
Open

fix(gconv): prevent panic when binding array type (uuid.UUID) parameters (#4786)#4820
waterWang wants to merge 1 commit into
gogf:masterfrom
waterWang:fix/gconv-array-isnil-panic

Conversation

@waterWang

Copy link
Copy Markdown
Contributor

Fixes #4786

Problem

reflect.Value.IsNil panics when called on an array value. uuid.UUID is [16]byte (a fixed-size array), so when a struct field like:

type XXXReq struct {
   IDs []uuid.UUID \`json:"ids"\`
}

is bound via HTTP request, the converter enters the reflect.Slice/Array/Pointer/Interface case and calls IsNil on the array element, causing a panic:

reflect: call of reflect.Value.IsNil on array Value

Fix

Skip the IsNil check when the reflect.Kind is reflect.Array, since arrays can never be nil in Go.

Verification

  • reflect.Array values are never nil, so the IsNil() guard is unnecessary for arrays
  • The ISet interface check is still reached for array types that implement it (though no standard library array type does)
  • All existing behavior for slices, pointers, and interfaces is unchanged

reflect.Value.IsNil panics when called on an array value.
uuid.UUID is [16]byte (a fixed-size array), so when a struct field
like  is bound via HTTP request, the converter
enters the reflect.Slice/Array/Pointer/Interface case and calls
IsNil on the array element, causing a panic.

Fix: skip the IsNil check when the kind is reflect.Array, since
arrays can never be nil in Go.

Fixes gogf#4786
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

net/http: 无法将 UUID slice 作为参数传入到 HTTP 服务

1 participant