MCPcopy Create free account
hub / github.com/apache/arrow-rs / validate_offsets

Method validate_offsets

arrow-data/src/data.rs:1033–1079  ·  view source on GitHub ↗

Does a cheap sanity check that the `self.len` values in `buffer` are valid offsets (of type T) into some other buffer of `values_length` bytes long

(
        &self,
        values_length: usize,
    )

Source from the content-addressed store, hash-verified

1031 /// Does a cheap sanity check that the `self.len` values in `buffer` are valid
1032 /// offsets (of type T) into some other buffer of `values_length` bytes long
1033 fn validate_offsets<T: ArrowNativeType + num_traits::Num + std::fmt::Display>(
1034 &self,
1035 values_length: usize,
1036 ) -> Result<(), ArrowError> {
1037 // Justification: buffer size was validated above
1038 let offsets = self.typed_offsets::<T>()?;
1039 if offsets.is_empty() {
1040 return Ok(());
1041 }
1042
1043 let first_offset = offsets[0].to_usize().ok_or_else(|| {
1044 ArrowError::InvalidArgumentError(format!(
1045 "Error converting offset[0] ({}) to usize for {}",
1046 offsets[0], self.data_type
1047 ))
1048 })?;
1049
1050 let last_offset = offsets[self.len].to_usize().ok_or_else(|| {
1051 ArrowError::InvalidArgumentError(format!(
1052 "Error converting offset[{}] ({}) to usize for {}",
1053 self.len, offsets[self.len], self.data_type
1054 ))
1055 })?;
1056
1057 if first_offset > values_length {
1058 return Err(ArrowError::InvalidArgumentError(format!(
1059 "First offset {} of {} is larger than values length {}",
1060 first_offset, self.data_type, values_length,
1061 )));
1062 }
1063
1064 if last_offset > values_length {
1065 return Err(ArrowError::InvalidArgumentError(format!(
1066 "Last offset {} of {} is larger than values length {}",
1067 last_offset, self.data_type, values_length,
1068 )));
1069 }
1070
1071 if first_offset > last_offset {
1072 return Err(ArrowError::InvalidArgumentError(format!(
1073 "First offset {} in {} is smaller than last offset {}",
1074 first_offset, self.data_type, last_offset,
1075 )));
1076 }
1077
1078 Ok(())
1079 }
1080
1081 /// Does a cheap sanity check that the `self.len` values in `buffer` are valid
1082 /// offsets and sizes (of type T) into some other buffer of `values_length` bytes long

Callers

nothing calls this directly

Calls 2

to_usizeMethod · 0.80
is_emptyMethod · 0.45

Tested by

no test coverage detected