zeroshade opened a new issue, #1344:
URL: https://github.com/apache/arrow-go/issues/1344
### Describe the bug, including details regarding any error messages,
version, and platform.
**Problem**
`Value.Value()` builds a long-form string with `unsafe.String(&v.value[5],
sz)` (parquet/variant/variant.go:1105 on main 68c593e, :1103 in v18.8.0). For
an empty string the encoded value is only 5 bytes (header `0x40` plus a zero
4-byte length), so `&v.value[5]` is out of range and it panics.
`validatePrimitiveValue` accepts that encoding (variant.go:558-566), so
`variant.New`/`NewWithMetadata` return the value without error. The
short-string branch already guards this with `if sz > 0`
(variant.go:1124-1128). `String()` and `MarshalJSON()` go through `Value()`
(variant.go:971, :1191) and panic the same way.
The encoding is valid: VariantEncoding.md says the short-string form "may be
used as an optimization", and that an expression on a string "should behave the
same, whether it is encoded with the short string optimization, or long string
encoding." Our `Builder` writes strings of up to 63 bytes in short form, so
this only shows up with data from other writers or hand-built values.
**Reproduction**
```go
v, err := variant.New([]byte{0x01, 0x00, 0x00}, []byte{0x40, 0x00, 0x00,
0x00, 0x00})
// err == nil, v.Type() == variant.String
_ = v.Value() // panics
_ = v.String() // panics via MarshalJSON
```
On main 68c593e (go1.27.1 linux/amd64) and on v18.8.0:
```
panic: runtime error: index out of range [5] with length 5
github.com/apache/arrow-go/v18/parquet/variant.Value.Value(...)
parquet/variant/variant.go:1105
```
Expected: `Value()` returns `""`, and `String()` returns the JSON string
`""`.
**Proposed fix**
Mirror the short-string branch: return `""` when `sz == 0` (or build the
string from `v.value[5 : 5+sz]` via `unsafe.SliceData`), and add a regression
test for the 5-byte encoding.
**Related**
apache/iceberg-go reaches this through `CastVariantLiteral`, which calls
`Value()` on variant leaves during extract, residual and bounds evaluation
(variant_cast.go:60), and, once apache/iceberg-go#2088 lands, through
`VariantLiteral.To`.
### Component(s)
Parquet
--
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]