lidavidm commented on a change in pull request #11535:
URL: https://github.com/apache/arrow/pull/11535#discussion_r740313463



##########
File path: cpp/src/arrow/ipc/reader.cc
##########
@@ -1235,19 +1243,24 @@ class RecordBatchFileReaderImpl : public 
RecordBatchFileReader {
                                    "from end of file");
           }
 
-          if (memcmp(buffer->data() + sizeof(int32_t), kArrowMagicBytes, 
magic_size)) {
+          const uint8_t* magic_start = buffer->data() + readahead;
+          if (memcmp(magic_start + sizeof(int32_t), kArrowMagicBytes, 
magic_size)) {
             return Status::Invalid("Not an Arrow file");
           }
 
-          int32_t footer_length = BitUtil::FromLittleEndian(
-              *reinterpret_cast<const int32_t*>(buffer->data()));
-
+          int32_t footer_length =
+              
BitUtil::FromLittleEndian(util::SafeLoadAs<int32_t>(magic_start));
           if (footer_length <= 0 ||
               footer_length > self->footer_offset_ - magic_size * 2 - 4) {
             return Status::Invalid("File is smaller than indicated metadata 
size");
           }
 
           // Now read the footer
+          if (footer_length <= readahead) {
+            return SliceBuffer(buffer, buffer->size() - file_end_size - 
footer_length,
+                               footer_length);
+          }
+

Review comment:
       I've updated this to just read the missing part of the footer.




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