@@ -1180,31 +1180,34 @@ Status CheckAligned(const FileBlock& block) {
11801180 return Status::OK ();
11811181}
11821182
1183+ template <typename MessagePtr>
1184+ Result<MessagePtr> CheckBodyLength (MessagePtr message, int64_t body_length) {
1185+ if (message->body_length () != body_length) {
1186+ return Status::Invalid (
1187+ " Mismatching body length for IPC message "
1188+ " (Block.bodyLength: " ,
1189+ body_length, " vs. Message.bodyLength: " , message->body_length (), " )" );
1190+ }
1191+ return message;
1192+ }
1193+
11831194Result<std::unique_ptr<Message>> ReadMessageFromBlock (
11841195 const FileBlock& block, io::RandomAccessFile* file,
11851196 const FieldsLoaderFunction& fields_loader) {
11861197 RETURN_NOT_OK (CheckAligned (block));
1187- // TODO(wesm): this breaks integration tests, see ARROW-3256
1188- // DCHECK_EQ((*out)->body_length(), block.body_length);
1189-
11901198 ARROW_ASSIGN_OR_RAISE (auto message, ReadMessage (block.offset , block.metadata_length ,
11911199 file, fields_loader));
1192- return message;
1200+ return CheckBodyLength ( std::move ( message), block. body_length ) ;
11931201}
11941202
11951203Future<std::shared_ptr<Message>> ReadMessageFromBlockAsync (
11961204 const FileBlock& block, io::RandomAccessFile* file, const io::IOContext& io_context) {
1197- if (!bit_util::IsMultipleOf8 (block.offset ) ||
1198- !bit_util::IsMultipleOf8 (block.metadata_length ) ||
1199- !bit_util::IsMultipleOf8 (block.body_length )) {
1200- return Status::Invalid (" Unaligned block in IPC file" );
1201- }
1202-
1203- // TODO(wesm): this breaks integration tests, see ARROW-3256
1204- // DCHECK_EQ((*out)->body_length(), block.body_length);
1205-
1205+ RETURN_NOT_OK (CheckAligned (block));
12061206 return ReadMessageAsync (block.offset , block.metadata_length , block.body_length , file,
1207- io_context);
1207+ io_context)
1208+ .Then ([block](std::shared_ptr<Message> message) {
1209+ return CheckBodyLength (message, block.body_length );
1210+ });
12081211}
12091212
12101213class RecordBatchFileReaderImpl ;
0 commit comments