Skip to content

[BUG] gio::FileExtManual::replace_contents_future() panicking when called with "admin://" URI #1785

@aleb2000

Description

@aleb2000

I had already posted this on discourse but it seems maybe it was the wrong place as it is not garnering much attention at all, so I'll be filing an issue here as to me this seems like an actual bug of the bindings.

Bug description

I am trying to write to a file that requires elevated privilages. To do so I am using the GIO File API and prefixing the "admin://" URI to the path. My code looks like this:

let admin_uri = format!(
    "admin://{}",
    file.path()
        .expect("File does not have a path?")
        .to_string_lossy()
);
let file = gio::File::for_uri(&admin_uri);

// Mount admin volume
let res = file
    .mount_enclosing_volume_future(MountMountFlags::NONE, MountOperation::NONE)
    .await;
if let Err(e) = res {
    println!("Failed to mount admin volume: {e}");
}

println!("Writing with admin perms");
let res = file
    .replace_contents_future(
        content.clone(),
        None,
        false,
        FileCreateFlags::NONE,
    )
    .await;
println!("Finished");

if let Err((_, e)) = res {
    println!("Failed to write file with admin perms: {e}");
}

The writing succeeds, however my program panics.

Backtrace

thread 'main' panicked at /home/aleb/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/glib-0.21.1/src/gstring.rs:2054:9:
assertion failed: !ptr.is_null()
stack backtrace:
   0:     0x560ffa3414c2 - std::backtrace_rs::backtrace::libunwind::trace::h74680e970b6e0712
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/../../backtrace/src/backtrace/libunwind.rs:117:9
   1:     0x560ffa3414c2 - std::backtrace_rs::backtrace::trace_unsynchronized::ha3bf590e3565a312
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/../../backtrace/src/backtrace/mod.rs:66:14
   2:     0x560ffa3414c2 - std::sys::backtrace::_print_fmt::hcf16024cbdd6c458
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/sys/backtrace.rs:66:9
   3:     0x560ffa3414c2 - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h46a716bba2450163
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/sys/backtrace.rs:39:26
   4:     0x560ffa367fb3 - core::fmt::rt::Argument::fmt::ha695e732309707b7
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/fmt/rt.rs:181:76
   5:     0x560ffa367fb3 - core::fmt::write::h275e5980d7008551
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/fmt/mod.rs:1446:25
   6:     0x560ffa33d553 - std::io::default_write_fmt::hdc4119be3eb77042
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/io/mod.rs:639:11
   7:     0x560ffa33d553 - std::io::Write::write_fmt::h561a66a0340b6995
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/io/mod.rs:1914:13
   8:     0x560ffa341312 - std::sys::backtrace::BacktraceLock::print::hafb9d5969adc39a0
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/sys/backtrace.rs:42:9
   9:     0x560ffa342782 - std::panicking::default_hook::{{closure}}::hae2e97a5c4b2b777
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:300:22
  10:     0x560ffa342585 - std::panicking::default_hook::h3db1b505cfc4eb79
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:327:9
  11:     0x560ffa343122 - std::panicking::rust_panic_with_hook::h409da73ddef13937
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:833:13
  12:     0x560ffa342e96 - std::panicking::begin_panic_handler::{{closure}}::h159b61b27f96a9c2
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:699:13
  13:     0x560ffa3419b9 - std::sys::backtrace::__rust_end_short_backtrace::h5b56844d75e766fc
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/sys/backtrace.rs:168:18
  14:     0x560ffa342b5d - __rustc[4794b31dd7191200]::rust_begin_unwind
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:697:5
  15:     0x560ff99da650 - core::panicking::panic_fmt::hc8737e8cca20a7c8
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/panicking.rs:75:14
  16:     0x560ff99da6dc - core::panicking::panic::h4a11c031239f36a8
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/panicking.rs:145:5
  17:     0x560ffa2cf9c0 - <glib::gstring::GString as glib::translate::FromGlibPtrFull<*mut u8>>::from_glib_full::h59b7e1e9322a7d6c
                               at /home/aleb/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/glib-0.21.1/src/gstring.rs:2054:9
  18:     0x560ffa2d34e6 - glib::translate::from_glib_full::h1a7ec403c3b5d5e4
                               at /home/aleb/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/glib-0.21.1/src/translate.rs:1639:5
  19:     0x560ffa2cfa57 - <glib::gstring::GString as glib::translate::FromGlibPtrFull<*mut i8>>::from_glib_full::hf9fe6870afdcc37c
                               at /home/aleb/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/glib-0.21.1/src/gstring.rs:2070:9
  20:     0x560ffa2d34c6 - glib::translate::from_glib_full::h14184bbd635d995f
                               at /home/aleb/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/glib-0.21.1/src/translate.rs:1639:5
  21:     0x560ff9bae94e - gio::file::FileExtManual::replace_contents_async::replace_contents_async_trampoline::h4e89b77441005ec6
                               at /home/aleb/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/gio-0.21.1/src/file.rs:226:31
  22:     0x7f32fff6be7c - <unknown>
  23:     0x7f32fff71590 - <unknown>
  24:     0x7f32fff298d9 - <unknown>
  25:     0x7f32fff6be7c - <unknown>
  26:     0x7f32fff71590 - <unknown>
  27:     0x7f32fff4bed2 - <unknown>
  28:     0x7f32fff6be7c - <unknown>
  29:     0x7f32fff71590 - <unknown>
  30:     0x7f32fff4c46f - <unknown>
  31:     0x7f32fff6be7c - <unknown>
  32:     0x7f32fff71590 - <unknown>
  33:     0x7f32ec94dc84 - <unknown>
  34:     0x7f32ec94d356 - <unknown>
  35:     0x7f32ec94d4ed - <unknown>
  36:     0x7f32fff3a477 - <unknown>
  37:     0x7f32fff6be7c - <unknown>
  38:     0x7f32fff71590 - <unknown>
  39:     0x7f32fff3fff0 - <unknown>
  40:     0x7f32fff4016d - <unknown>
  41:     0x7f32ffd7e880 - <unknown>
  42:     0x7f32ffd877c8 - <unknown>
  43:     0x7f32ffd87973 - g_main_context_iteration
  44:     0x7f32fffa402d - g_application_run
  45:     0x560ff9a45dd9 - gio::application::ApplicationExtManual::run_with_args::h1ee0756279cc1afc
                               at /home/aleb/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/gio-0.21.1/src/application.rs:25:13
  46:     0x560ff9a45fa9 - gio::application::ApplicationExtManual::run::h7b215ca94c0ad66d
                               at /home/aleb/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/gio-0.21.1/src/application.rs:17:9
  47:     0x560ff99e9df8 - desktop_file_editor::main::h5c1167c6ad094ff5
                               at /home/aleb/workspace/desktop-manager/src/main.rs:34:5
  48:     0x560ff9b9a21b - core::ops::function::FnOnce::call_once::hd9372ad5f9eeb22c
                               at /home/aleb/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5
  49:     0x560ff9bb4fbe - std::sys::backtrace::__rust_begin_short_backtrace::h9157358bdc13aa96
                               at /home/aleb/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/backtrace.rs:152:18
  50:     0x560ff9b41c31 - std::rt::lang_start::{{closure}}::h60f876af9a835986
                               at /home/aleb/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:199:18
  51:     0x560ffa337c44 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hb4b7cf0559a1a53b
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/core/src/ops/function.rs:284:13
  52:     0x560ffa337c44 - std::panicking::try::do_call::h8e6004e979ada7de
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:589:40
  53:     0x560ffa337c44 - std::panicking::try::hc44a0c902e55fa8c
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:552:19
  54:     0x560ffa337c44 - std::panic::catch_unwind::h6a5f1ccd4faaed9e
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panic.rs:359:14
  55:     0x560ffa337c44 - std::rt::lang_start_internal::{{closure}}::h40fd26f9e7cfe6a7
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/rt.rs:168:24
  56:     0x560ffa337c44 - std::panicking::try::do_call::h047dd894cf3f6fd1
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:589:40
  57:     0x560ffa337c44 - std::panicking::try::h921841e1eaed56ce
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panicking.rs:552:19
  58:     0x560ffa337c44 - std::panic::catch_unwind::h108064a50ee785ec
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/panic.rs:359:14
  59:     0x560ffa337c44 - std::rt::lang_start_internal::ha8ef919ae4984948
                               at /rustc/6b00bc3880198600130e1cf62b8f8a93494488cc/library/std/src/rt.rs:164:5
  60:     0x560ff9b41c17 - std::rt::lang_start::hd50e03435b2650ce
                               at /home/aleb/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:198:5
  61:     0x560ff99e9e5e - main
  62:     0x7f32ffa36575 - __libc_start_call_main
  63:     0x7f32ffa36628 - __libc_start_main_impl
  64:     0x560ff99db1e5 - _start
  65:                0x0 - <unknown>

Note

This bug seems very similar to #93 which should however be fixed.

Looking at the code and backtrace I think the problem is at line 226 in the File bindings where it tries to create a GString from the ETag pointer without checking that it is not null. The curious aspect is that this problem does not appear when not using the admin URI: files that do not require root permissions are written without panicking with the same exact call and same exact parameters (I always put None as the ETag parameter).

I would try fixing it myself but I'm not really familiar with any of this so I'm opening this issue. I'm not sure if just an explicit null check is all it takes to fix this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions