tustvold commented on code in PR #2048:
URL: https://github.com/apache/arrow-rs/pull/2048#discussion_r928123907
##########
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 think you can remove `values_str.is_char_boundary(range.end)`, as the end
offset is the start offset of the next string slice and will therefore be
checked by that. We do not need to check the final offset as if the end of the
string is not a valid char boundary, the string as a whole would fail
validation.
--
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]