Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustc diverges on large dangling integer slice #63952

Closed
RalfJung opened this issue Aug 27, 2019 · 1 comment · Fixed by #69192
Closed

rustc diverges on large dangling integer slice #63952

RalfJung opened this issue Aug 27, 2019 · 1 comment · Fixed by #69192
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@RalfJung
Copy link
Member

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.

@jonas-schievink jonas-schievink added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) C-bug Category: This is a bug. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 27, 2019
@oli-obk
Copy link
Contributor

oli-obk commented Jan 17, 2020

@oli-obk oli-obk closed this as completed Jan 17, 2020
@oli-obk oli-obk reopened this Jan 17, 2020
@oli-obk oli-obk added E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed C-bug Category: This is a bug. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 17, 2020
Centril added a commit to Centril/rust that referenced this issue Feb 17, 2020
@bors bors closed this as completed in d1f175b Feb 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants