pitrou commented on code in PR #49771:
URL: https://github.com/apache/arrow/pull/49771#discussion_r3234304108
##########
cpp/src/arrow/ipc/message.cc:
##########
@@ -563,7 +563,25 @@ Status DecodeMessage(MessageDecoder* decoder,
io::InputStream* file) {
}
auto metadata_length = decoder->next_required_size();
+
+ // "ARRO" (first 4 bytes of kArrowMagicBytes) as little-endian int32.
+ constexpr int32_t kArrowMagicPrefix = 0x4F525241;
+
+ // Did we misinterpret the metadata as a length?
+ if (metadata_length == kArrowMagicPrefix) {
+ constexpr std::string_view kRemainingMagic =
+ internal::kArrowMagicBytes.substr(sizeof(int32_t));
+ ARROW_ASSIGN_OR_RAISE(auto peek, file->Read(kRemainingMagic.size()));
+ if (peek->size() >= static_cast<int64_t>(kRemainingMagic.size()) &&
+ std::string_view(reinterpret_cast<const char*>(peek->data()),
+ kRemainingMagic.size()) == kRemainingMagic) {
Review Comment:
What happens if this check fails? Are we assuming that the file is a valid
IPC stream that happens to have a metadata size exactly 0x4F525241 bytes?
In any case, we have read `kRemainingMagic` bytes that are discarded below,
so we'll be out of sync anyway.
--
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]