alamb commented on code in PR #12340:
URL: https://github.com/apache/arrow-rs/pull/12340#discussion_r4635740977


##########
arrow-csv/src/reader/records.rs:
##########
@@ -84,8 +84,26 @@ impl RecordDecoder {
         }
 
         // Reserve sufficient capacity in offsets
-        self.offsets
-            .resize(self.offsets_len + to_read * self.num_columns, 0);
+        let offsets_capacity = to_read
+            .checked_mul(self.num_columns)

Review Comment:
   I wonder if we can avoid spreading this copy/pasta around the codebase a bit 
with a small helper like 
   ```rust
   trait ArrowCheckedArith {
     fn mul_or_err(&self, v: Self, msg: &'static str) -> Result<..> {
   ...
   }
   }
   ```
   
   Then callsites like this could be like
   ```rust
    let offsets_capacity = to_read
     .mul_or_err(self.num_columns, "CSV decoder capacity overflow")
     .map(|capacity| self.offsets_len.add_or_err(capacity, "CSV decoder 
capacity overflow"))?
   ```
   
   We could also drop the `msg` to keep it more concise but less nice error 
messages
   



-- 
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]

Reply via email to