You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "lidavidm (via GitHub)" <gi...@apache.org> on 2023/02/02 14:23:20 UTC

[GitHub] [arrow] lidavidm opened a new issue, #33999: [Go] array.String.Value is unsafe

lidavidm opened a new issue, #33999:
URL: https://github.com/apache/arrow/issues/33999

   ### Describe the bug, including details regarding any error messages, version, and platform.
   
   String.Value slices a backing string:
   
   ```go
   func (a *String) Value(i int) string {
   	i = i + a.array.data.offset
   	return a.values[a.offsets[i]:a.offsets[i+1]]
   }
   ```
   
   Which points directly into the buffer data:
   
   ```go
   	if vdata := data.buffers[2]; vdata != nil {
   		b := vdata.Bytes()
   		a.values = *(*string)(unsafe.Pointer(&b))
   	}
   ```
   
   This seems OK when the buffer is Go-allocated since the GC will take care of it (regardless of Release/Retain). But when the buffer is C-allocated (e.g. C Data Interface, mallocator), if the string outlives the array, we have a dangling pointer!
   
   I believe we should copy the string (and frankly, get rid of the unsafe here) to be safe (which also has the side effect that getting a single value out of an array will no longer keep the entire backing array alive). If the extra garbage is an issue, we should consider some sort of string view type.
   
   ### Component(s)
   
   Go


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [arrow] rtadepalli commented on issue #33999: [Go] array.String.Value is unsafe

Posted by "rtadepalli (via GitHub)" <gi...@apache.org>.
rtadepalli commented on issue #33999:
URL: https://github.com/apache/arrow/issues/33999#issuecomment-1454329306

   take


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org