yilin0518 commented on issue #9286:
URL: https://github.com/apache/arrow-rs/issues/9286#issuecomment-3819021971

   > Yes this looks like a bug; I'll push a PR fix, thanks for identifying this
   
   Related to this bug, I found that using the `struct IntervalMonthDayNano` as 
the type of BufferBuilder, will produce another scenario. Look the following 
code snippet:
   ```rust
   #![feature(allocator_api)]
   use arrow_buffer::*;
   fn main() {
       let mut v10 = <builder::BufferBuilder::<IntervalMonthDayNano> as 
std::default::Default>::default();
       let v11: &'_ mut builder::BufferBuilder::<IntervalMonthDayNano> = &mut 
v10;
       let v12 = IntervalMonthDayNano { months: 98, days: 78, nanoseconds: 117 
};
       builder::BufferBuilder::<IntervalMonthDayNano>::append(v11, v12);
       let v13: &'_ builder::BufferBuilder::<IntervalMonthDayNano> = &v10;
       let v14 = builder::BufferBuilder::<IntervalMonthDayNano>::capacity(v13);
       let v15: &'_ mut builder::BufferBuilder::<IntervalMonthDayNano> = &mut 
v10;
       builder::BufferBuilder::<IntervalMonthDayNano>::truncate(v15, v14);
       let v25: &'_ builder::BufferBuilder::<IntervalMonthDayNano> = &v10;
       let v26 = builder::BufferBuilder::<IntervalMonthDayNano>::as_slice(v25);
       println!("v26: {:?}",v26);
   }
   
   ```
   
   Despite `as_slice` or `as_slice_mut`, miri report the same error message:
   
   ```bash
   error: Undefined Behavior: reading memory at alloc230[0x10..0x14], but 
memory is uninitialized at [0x10..0x14], and this operation requires 
initialized memory
      --> 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:599:5
       |
   599 |     impl_Display!(i8, u8, i16, u16, i32, u32, i64, u64, isize, usize; 
as u64 into display_u64);
       |     
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 Undefined Behavior occurred here
       |
       = help: this indicates a bug in the program: it performed an invalid 
operation, and caused Undefined Behavior
       = help: see 
https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html 
for further information
       = note: BACKTRACE:
       = note: inside `core::fmt::num::imp::<impl std::fmt::Display for 
i32>::fmt` at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:164:45:
 164:50
       = note: inside `core::fmt::num::<impl std::fmt::Debug for i32>::fmt` at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/num.rs:91:25:
 91:51
       = note: inside closure at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/builders.rs:133:35:
 133:47
       = note: inside closure at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/builders.rs:162:17:
 162:36
       = note: inside `std::result::Result::<(), 
std::fmt::Error>::and_then::<(), {closure@std::fmt::DebugStruct<'_, 
'_>::field_with<{closure@std::fmt::DebugStruct<'_, 
'_>::field::{closure#0}}>::{closure#0}}>` at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:1493:22:
 1493:27
       = note: inside `std::fmt::DebugStruct::<'_, 
'_>::field_with::<{closure@std::fmt::DebugStruct<'_, '_>::field::{closure#0}}>` 
at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/builders.rs:145:23:
 164:11
       = note: inside `std::fmt::DebugStruct::<'_, '_>::field` at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/builders.rs:133:9:
 133:48
       = note: inside `std::fmt::Formatter::<'_>::debug_struct_field3_finish` 
at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:2496:9:
 2496:37
       = note: inside `<arrow_buffer::IntervalMonthDayNano as 
std::fmt::Debug>::fmt` at 
/home/chenyl/projects/check_UB/arrow-buffer-57.2.0/src/interval.rs:68:10: 68:15
       = note: inside `<&arrow_buffer::IntervalMonthDayNano as 
std::fmt::Debug>::fmt` at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:2865:62:
 2865:82
       = note: inside closure at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/builders.rs:741:35:
 741:47
       = note: inside closure at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/builders.rs:474:17:
 474:36
       = note: inside `std::result::Result::<(), 
std::fmt::Error>::and_then::<(), {closure@core::fmt::builders::DebugInner<'_, 
'_>::entry_with<{closure@std::fmt::DebugList<'_, 
'_>::entry::{closure#0}}>::{closure#0}}>` at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:1493:22:
 1493:27
       = note: inside `core::fmt::builders::DebugInner::<'_, 
'_>::entry_with::<{closure@std::fmt::DebugList<'_, '_>::entry::{closure#0}}>` 
at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/builders.rs:460:23:
 476:11
       = note: inside `std::fmt::DebugList::<'_, '_>::entry` at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/builders.rs:741:9:
 741:48
       = note: inside `std::fmt::DebugList::<'_, 
'_>::entries::<&arrow_buffer::IntervalMonthDayNano, std::slice::Iter<'_, 
arrow_buffer::IntervalMonthDayNano>>` at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/builders.rs:788:13:
 788:31
       = note: inside `<[arrow_buffer::IntervalMonthDayNano] as 
std::fmt::Debug>::fmt` at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:3116:9:
 3116:44
       = note: inside `<&[arrow_buffer::IntervalMonthDayNano] as 
std::fmt::Debug>::fmt` at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:2865:62:
 2865:82
       = note: inside `core::fmt::rt::Argument::<'_>::fmt` at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/rt.rs:152:76:
 152:95
       = note: inside `std::fmt::write` at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/fmt/mod.rs:1684:17:
 1686:80
       = note: inside `std::io::default_write_fmt::<std::io::StdoutLock<'_>>` 
at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/mod.rs:614:11:
 614:40
       = note: inside `<std::io::StdoutLock<'_> as std::io::Write>::write_fmt` 
at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/mod.rs:1969:13:
 1969:42
       = note: inside `<&std::io::Stdout as std::io::Write>::write_fmt` at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/stdio.rs:834:9:
 834:36
       = note: inside `<std::io::Stdout as std::io::Write>::write_fmt` at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/stdio.rs:808:9:
 808:33
       = note: inside `std::io::stdio::print_to::<std::io::Stdout>` at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/stdio.rs:1164:21:
 1164:47
       = note: inside `std::io::_print` at 
/home/chenyl/.rustup/toolchains/nightly-2025-12-06-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/stdio.rs:1275:5:
 1275:37
   note: inside `main`
      --> src/main.rs:14:5
       |
    14 |     println!("v26: {:?}",v26);
       |     ^^^^^^^^^^^^^^^^^^^^^^^^^
       = note: this error originates in the macro `impl_Display` which comes 
from the expansion of the macro `println` (in Nightly builds, run with -Z 
macro-backtrace for more info)
   
   Uninitialized memory occurred at alloc230[0x10..0x14], in this allocation:
   alloc230 (Rust heap, size: 64, align: 128) {
       0x00 │ 62 00 00 00 4e 00 00 00 75 00 00 00 00 00 00 00 │ b...N...u.......
       0x10 │ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ │ ░░░░░░░░░░░░░░░░
       0x20 │ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ │ ░░░░░░░░░░░░░░░░
       0x30 │ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ __ │ ░░░░░░░░░░░░░░░░
   }
   
   note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` 
for a verbose backtrace
   
   error: aborting due to 1 previous error
   ```
   
   Different with **pointer not dereferenceable**, I try to make this code 
shorter, but remove several lines of this snippet will not output this UB. 
Maybe it contains another potential error. Hoping you can take a view!


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