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

   ### Describe the bug, including details regarding any error messages, 
version, and platform.
   
   `ExtensionType$WrapArray()`, and so `new_extension_array()`, only checks 
that its input is an `Array`. It does not check that the array's type is the 
extension type's storage type, so an array of the wrong type is accepted and 
its buffers are then read as if they held the storage type. This reads past the 
end of the data.
   
   
https://github.com/apache/arrow/blob/8264a0d0d8980944bf8a2ff15997435d469b5a49/r/R/extension.R#L146-L149
   
   ``` r
   library(arrow)
   
   # an extension type whose storage type is fixed_size_binary(16)
   type <- new_extension_type(fixed_size_binary(16), "example.wrong_storage")
   
   # wrapping int32 storage is accepted
   array <- new_extension_array(Array$create(1:3), type)
   array$storage()$type
   #> FixedSizeBinary
   #> fixed_size_binary[16]
   
   # the 12 bytes of int32 data are read as 3 x 16 bytes
   as.vector(array)
   #> <fixed_size_binary<16>[3]>
   #> [[1]]
   #>  [1] 01 00 00 00 02 00 00 00 03 00 00 00 00 f4 00 00
   #>
   #> [[2]]
   #>  [1] 13 00 00 40 00 00 00 00 60 40 4c d9 52 5d 00 00
   #>
   #> [[3]]
   #>  [1] 08 b0 c5 dc 52 5d 00 00 c8 b0 c5 dc 52 5d 00 00
   ```
   
   Only the first 12 bytes are the data; the rest is whatever is next in memory.
   
   I expected an error saying that the storage array's type does not match the 
extension type's storage type.
   
   Seen with arrow 26.0.0 on Linux.
   
   ### Component(s)
   
   R
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to