etseidl commented on code in PR #12474:
URL: https://github.com/apache/arrow-rs/pull/12474#discussion_r4772087479


##########
parquet/src/parquet_thrift.rs:
##########
@@ -303,7 +303,12 @@ pub(crate) trait ThriftCompactInputProtocol<'a> {
         let mut shift = 7;
         loop {
             let byte = self.read_byte()?;
-            in_progress |= ((byte & 0x7F) as u64).wrapping_shl(shift);
+            // A u64 needs at most 10 bytes, and the 10th byte (shift == 63) 
may
+            // only contribute a single bit. Anything more is corrupt input.
+            if shift == 63 && byte > 1 {
+                return Err(ThriftProtocolError::IntegerOverflow);
+            }
+            in_progress |= ((byte & 0x7F) as u64) << shift;

Review Comment:
   I burned a lot of tokens trying to get this call both safe and fast. In the 
end this wound up being the least bad. Happy to post a report of all the things 
I've tried 😉. IIRC this wound up regressing a percent or two in a few of the 
benches, but not across the board.



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