CurtHagenlocher commented on code in PR #526:
URL: https://github.com/apache/arrow-dotnet/pull/526#discussion_r4792110115


##########
src/Apache.Arrow/Ipc/ArrowReaderImplementation.cs:
##########
@@ -131,42 +131,67 @@ private static bool MatchEnum(Flatbuf.MessageHeader 
messageHeader, Type flatBuff
         /// Create a record batch or dictionary batch from Flatbuf.Message.
         /// </summary>
         /// <remarks>
+        /// <para>
         /// This method adds data to _dictionaryMemo and returns null when the 
message type is DictionaryBatch.
-        /// </remarks>>
+        /// </para>
+        /// <para>
+        /// Takes ownership of <paramref name="memoryOwner"/>, the message 
body: it either passes it
+        /// to the result or releases it, including when the message cannot be 
read.
+        /// </para>
+        /// </remarks>
         /// <returns>
         /// The record batch when the message type is RecordBatch.
         /// Null when the message type is not RecordBatch.
         /// </returns>
         protected RecordBatch CreateArrowObjectFromMessage(
             Flatbuf.Message message, ByteBuffer bodyByteBuffer, 
IMemoryOwner<byte> memoryOwner)
         {
-            switch (message.HeaderType)
+            bool bodyKept = false;
+            try
             {
-                case Flatbuf.MessageHeader.Schema:
-                    // TODO: Read schema and verify equality?
-                    break;
-                case Flatbuf.MessageHeader.DictionaryBatch:
-                    Flatbuf.DictionaryBatch dictionaryBatch = 
message.Header<Flatbuf.DictionaryBatch>().Value;
-                    ReadDictionaryBatch(message.Version, dictionaryBatch, 
bodyByteBuffer, memoryOwner);
-                    break;
-                case Flatbuf.MessageHeader.RecordBatch:
-                    Flatbuf.RecordBatch rb = 
message.Header<Flatbuf.RecordBatch>().Value;
-                    if (rb.Length < 0 || rb.Length > int.MaxValue)
-                    {
-                        throw new InvalidDataException(
-                            $"Cannot read batch. Message body of {rb.Length} 
rows is out of range.");
-                    }
+                switch (message.HeaderType)
+                {
+                    case Flatbuf.MessageHeader.Schema:
+                        // TODO: Read schema and verify equality?
+                        break;
+                    case Flatbuf.MessageHeader.DictionaryBatch:
+                        Flatbuf.DictionaryBatch dictionaryBatch = 
message.Header<Flatbuf.DictionaryBatch>().Value;
+                        ReadDictionaryBatch(message.Version, dictionaryBatch, 
bodyByteBuffer, memoryOwner);
+
+                        // The dictionary's arrays refer to the body, so it 
must stay alive. Nothing
+                        // owns it, so it is reclaimed only by finalization, 
as before.
+                        bodyKept = true;

Review Comment:
   We'll address as a separate issue.



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