scovich commented on code in PR #7752:
URL: https://github.com/apache/arrow-rs/pull/7752#discussion_r2162372338
##########
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)
Review Comment:
`4 + len` could overflow a 32-bit `usize`, given a malicious value of `len`
such as `0xffffffff`
##########
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:
NOTE: This is the only call site for `string_from_slice` that doesn't have
an offset (after recent changes removed the leading header byte from the
slice).
We have to pass `0..len` instead of `..len` because `string_from_slice` and
`slice_from_slice_with_offset` must take `Range<usize>` instead of `impl
SliceIndex<[u8]>` -- the latter doesn't provide a uniform way to add an offset.
##########
parquet-variant/src/variant.rs:
##########
@@ -76,13 +76,13 @@ impl<'a> TryFrom<&'a str> for ShortString<'a> {
}
}
-impl<'a> AsRef<str> for ShortString<'a> {
+impl AsRef<str> for ShortString<'_> {
fn as_ref(&self) -> &str {
self.0
}
}
-impl<'a> Deref for ShortString<'a> {
+impl Deref for ShortString<'_> {
Review Comment:
My local clippy complained about these, so I fixed them
--
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]