Jefffrey opened a new issue, #12395:
URL: https://github.com/apache/arrow-rs/issues/12395

   ### Describe the bug
   
   finishing a mapbuilder relies on unsafe code to skip validation as it relies 
on builder maintaining invariants:
   
   
https://github.com/apache/arrow-rs/blob/305104fdb7d63688bab614ea45be88f5ec9c33bb/arrow-array/src/builder/map_builder.rs#L292-L293
   
   but we can break these invariants using safe code
   
   ### To Reproduce
   
   ```rust
       #[test]
       fn test123() {
           let mut builder = MapBuilder::new(None, StringBuilder::new(), 
Int32Builder::new());
           builder.keys().append_value("1");
           builder.values().append_value(42);
           builder.append(true).unwrap();
   
           // reset offsets to 0
           builder.keys().finish();
           builder.values().finish();
           builder.append(true).unwrap();
   
           builder.keys().append_value("1");
           builder.values().append_value(42);
           builder.append(true).unwrap();
   
           let map_array = builder.finish();
           // we now have invalid map array, offsets [0, 1, 0, 1]
           dbg!(map_array.offsets());
       }
   ```
   
   when run:
   
   ```bash
   running 1 test
   [arrow-array/src/builder/map_builder.rs:371:9] map_array.offsets() = 
OffsetBuffer(
       ScalarBuffer(
           [
               0,
               1,
               0,
               1,
           ],
       ),
   )
   test builder::map_builder::tests::test123 ... ok
   ```
   
   ### Expected behavior
   
   this should be caught, and either error earlier or somehow prevented from 
happening
   
   ### Additional context
   
   _No response_
   
   ### Willingness to contribute
   
   None


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