scovich commented on code in PR #7752:
URL: https://github.com/apache/arrow-rs/pull/7752#discussion_r2164914843
##########
parquet-variant/src/decoder.rs:
##########
@@ -262,21 +265,19 @@ pub(crate) fn decode_timestampntz_micros(data: &[u8]) ->
Result<NaiveDateTime, A
/// Decodes a Binary from the value section of a variant.
pub(crate) fn decode_binary(data: &[u8]) -> Result<&[u8], ArrowError> {
let len = u32::from_le_bytes(array_from_slice(data, 0)?) as usize;
- let value = slice_from_slice(data, 4..4 + len)?;
- Ok(value)
+ slice_from_slice_at_offset(data, 4, 0..len)
}
/// Decodes a long string from the value section of a variant.
pub(crate) fn decode_long_string(data: &[u8]) -> Result<&str, ArrowError> {
let len = u32::from_le_bytes(array_from_slice(data, 0)?) as usize;
- let string = string_from_slice(data, 4..4 + len)?;
- Ok(string)
+ string_from_slice(data, 4, 0..len)
}
/// Decodes a short string from the value section of a variant.
pub(crate) fn decode_short_string(metadata: u8, data: &[u8]) ->
Result<ShortString, ArrowError> {
let len = (metadata >> 2) as usize;
- let string = string_from_slice(data, 0..len)?;
+ let string = string_from_slice(data, 0, 0..len)?;
Review Comment:
Small correction -- all these cases work with `&str` not `String`.
The helper has two other call sites:
```rust
string_from_slice(data, 4, 0..len)
```
and
```rust
string_from_slice(self.bytes, self.dictionary_key_start_byte, byte_range)
```
Those cases would become more complex, e.g.
`str::from_utf8(data.get(...)).map_err(...)`.
Also, without the helper it's easy to do the wrong thing (overflow-wise) by
passing `offset..offset+len` to that `get` call.
--
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]