tustvold commented on code in PR #2048:
URL: https://github.com/apache/arrow-rs/pull/2048#discussion_r930112449
##########
arrow/src/array/data.rs:
##########
@@ -1125,16 +1125,37 @@ impl ArrayData {
T: ArrowNativeType + TryInto<usize> + num::Num + std::fmt::Display,
{
let values_buffer = &self.buffers[1].as_slice();
-
- self.validate_each_offset::<T, _>(values_buffer.len(), |string_index,
range| {
- std::str::from_utf8(&values_buffer[range.clone()]).map_err(|e| {
- ArrowError::InvalidArgumentError(format!(
- "Invalid UTF8 sequence at string index {} ({:?}): {}",
- string_index, range, e
- ))
- })?;
- Ok(())
- })
+ if let Ok(values_str) = std::str::from_utf8(values_buffer) {
+ // Validate Offsets are correct
+ self.validate_each_offset::<T, _>(
+ values_buffer.len(),
+ |string_index, range| {
+ if !values_str.is_char_boundary(range.start)
+ || !values_str.is_char_boundary(range.end)
Review Comment:
I realized an additional subtlety with this, if the offsets buffer is
sliced, you need to validate that this slicing is at a valid boundary, which a
naive implementation of the above might miss.
Theoretically you only need to validate the range of values covered by the
offsets, which might be another possible optimisation :thinking:
--
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]