Jefffrey commented on code in PR #11012:
URL: https://github.com/apache/arrow-rs/pull/11012#discussion_r3954353532
##########
arrow-ipc/src/reader.rs:
##########
@@ -947,11 +945,37 @@ fn get_dictionary_values(
/// Read the data for a given block
fn read_block<R: Read + Seek>(mut reader: R, block: &Block) -> Result<Buffer,
ArrowError> {
- reader.seek(SeekFrom::Start(block.offset() as u64))?;
- let body_len = block.bodyLength().to_usize().unwrap();
- let metadata_len = block.metaDataLength().to_usize().unwrap();
- let total_len = body_len.checked_add(metadata_len).unwrap();
+ let offset = u64::try_from(block.offset())
+ .map_err(|_| ArrowError::ParseError(format!("Invalid block offset:
{}", block.offset())))?;
+ let body_len = usize::try_from(block.bodyLength()).map_err(|_| {
+ ArrowError::ParseError(format!("Invalid block body length: {}",
block.bodyLength()))
+ })?;
+ let metadata_len = usize::try_from(block.metaDataLength()).map_err(|_| {
+ ArrowError::ParseError(format!(
+ "Invalid block metadata length: {}",
+ block.metaDataLength()
+ ))
+ })?;
+ let total_len = body_len.checked_add(metadata_len).ok_or_else(|| {
+ ArrowError::ParseError("Block body length + metadata length overflowed
usize".to_string())
+ })?;
+ let file_len = reader.seek(SeekFrom::End(0))?;
Review Comment:
we probably should pass in the file length to the function, instead of
re-seeking for every block read
--
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]