Skip to content

rustc diverges on large dangling integer slice #63952

Closed

Description

I wanted to test our handling of slices that are "too big" (bigger than the largest possible allocation), so I wrote:

use std::usize;

#[repr(C)]
#[derive(Copy, Clone)]
struct SliceRepr {
    ptr: *const u8,
    len: usize,
}

union SliceTransmute {
    repr: SliceRepr,
    slice: &'static [u8],
}

// bad slice: length too big to even exist anywhere
const SLICE_WAY_TOO_LONG: &[u8] = unsafe { SliceTransmute { repr: SliceRepr { ptr: &42, len: usize::MAX } }.slice};

I expected an ICE or so, but I got a timeout. On nightly, here's what a stacktrace looks like:

#0  0x00007fe68caece57 in rustc_mir::interpret::visitor::ValueVisitor::walk_value () at src/librustc_mir/interpret/visitor.rs:223
#1  0x00007fe68caec7b1 in rustc_mir::interpret::visitor::ValueVisitor::visit_value () at src/librustc_mir/interpret/visitor.rs:138
#2  rustc_mir::interpret::visitor::ValueVisitor::visit_field () at src/librustc_mir/interpret/visitor.rs:170
#3  rustc_mir::interpret::visitor::ValueVisitor::walk_aggregate () at src/librustc_mir/interpret/visitor.rs:219
#4  0x00007fe68caedb0e in <rustc_mir::interpret::intern::InternVisitor as rustc_mir::interpret::visitor::ValueVisitor<rustc_mir::const_eval::CompileTimeInterpreter>>::visit_aggregate () at src/librustc_mir/interpret/intern.rs:136
#5  rustc_mir::interpret::visitor::ValueVisitor::walk_value () at src/librustc_mir/interpret/visitor.rs:326
#6  0x00007fe68c71b1de in rustc_mir::interpret::visitor::ValueVisitor::visit_value () at src/librustc_mir/interpret/visitor.rs:138
#7  rustc_mir::interpret::intern::intern_const_alloc_recursive () at src/librustc_mir/interpret/intern.rs:284
#8  0x00007fe68c5493b1 in rustc_mir::const_eval::eval_body_using_ecx () at src/librustc_mir/const_eval.rs:161
#9  rustc_mir::const_eval::const_eval_raw_provider::{{closure}} () at src/librustc_mir/const_eval.rs:658
#10 core::result::Result<T,E>::and_then () at /home/r/src/rust/rustc.2/src/libcore/result.rs:691
#11 rustc_mir::const_eval::const_eval_raw_provider () at src/librustc_mir/const_eval.rs:657

@oli-obk looks like the interning could do with a fast path for integer slices similar to what validation does? And maybe it could also check that the reference is dereferencable before walking it, that would avoid finding out later that we are going to produce an error anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-const-evalArea: Constant evaluation (MIR interpretation)E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions