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

thread 'rustc' panicked at 'index out of bounds: [...] src/libcollections/vec.rs:1047 #28217

Closed
Mange opened this issue Sep 3, 2015 · 5 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@Mange
Copy link

Mange commented Sep 3, 2015

I can't use the json! macro on latest master (2015-09-03).

I tried this code:

src/main.rs

#![feature(plugin)]
#![plugin(json_macros)]
extern crate rustc_serialize;

fn main() {
    let payload = json!({"test": "1"});
    println!(payload.to_string());
}

Cargo.toml:

[package]

name = "rust-bug"
version = "0.0.1"
authors = [ "Magnus Bergmark <[email protected]>" ]

[dependencies]
json_macros = "0.2.5"
rustc-serialize = "*"
cargo run

I expected to see this happen: {"test":"1"}

Instead, this happened: note: the compiler unexpectedly panicked. this is a bug.

Meta

rustc --version --verbose:

rustc 1.4.0-nightly (9e9c83b89 2015-09-03)
binary: rustc
commit-hash: 9e9c83b8994fab4f69fc75838c8c856b57caa5d1
commit-date: 2015-09-03
host: x86_64-apple-darwin
release: 1.4.0-nightly

cargo --version:

cargo 0.5.0 (7ea8265 2015-09-03)

Backtrace:

› RUST_BACKTRACE=1 cargo run --verbose
       Fresh rustc-serialize v0.3.16
       Fresh json_macros v0.2.5
   Compiling rust-bug v0.0.1 (file:///Users/mange/Desktop/rust-bug)
     Running `rustc src/main.rs --crate-name rust_bug --crate-type bin -g --out-dir /Users/mange/Desktop/rust-bug/target/debug --emit=dep-info,link -L dependency=/Users/mange/Desktop/rust-bug/target/debug -L dependency=/Users/mange/Desktop/rust-bug/target/debug/deps --extern json_macros=/Users/mange/Desktop/rust-bug/target/debug/deps/libjson_macros-588fa665176505c5.dylib --extern rustc_serialize=/Users/mange/Desktop/rust-bug/target/debug/deps/librustc_serialize-7ff5bfc027146194.rlib`
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
thread 'rustc' panicked at 'index out of bounds: the len is 60 but the index is 67', src/libcollections/vec.rs:1047
stack backtrace:
   1:        0x111149940 - sys::backtrace::tracing::imp::write::hd0176e40ebe71d28Vks
   2:        0x11115191b - panicking::on_panic::h929e7e75bc4f2c31NXw
   3:        0x111113c12 - rt::unwind::begin_unwind_inner::h9d2d49cde66c0c4b0sw
   4:        0x11111499d - rt::unwind::begin_unwind_fmt::h30d162ea92169f156rw
   5:        0x111151527 - rust_begin_unwind
   6:        0x1111925b0 - panicking::panic_fmt::ha85fd08dcab4df5d8PE
   7:        0x11118c710 - panicking::panic_bounds_check::h74acb99379ef18f4ePE
   8:        0x117aba24b - parse::token::InternedString::new_from_name::hf3d5b4c0153b6a85EiT
   9:        0x117bb7014 - parse::parser::Parser<'a>::parse_optional_str::hcbe96d5b0fc32f68b5M
  10:        0x117bb7183 - parse::parser::Parser<'a>::parse_str::h9f9ed6f8c5ab3308o6M
  11:        0x112a0fdfc - plugin::parse_json::closure.10831
  12:        0x112a0f3bd - parse::parser::Parser<'a>::parse_seq_to_before_end::h13189328464236698498
  13:        0x112a0ee2c - parse::parser::Parser<'a>::parse_seq_to_end::h14254503023922733831
  14:        0x1129d35a6 - plugin::parse_json::hfd1a1f8297018b85lba
  15:        0x1129d307e - plugin::expand::h6ee2acb00f38e3fauaa
  16:        0x1157258e9 - ext::base::F.TTMacroExpander::expand::h14210021944373090710
  17:        0x10eee9137 - ext::expand::expand_expr::closure.68004
  18:        0x10eee5f45 - ext::expand::expand_expr::h4484ab514eace144rqb
  19:        0x10ef0ea40 - ext::expand::expand_non_macro_stmt::closure.68390
  20:        0x10ef0e1f0 - ext::expand::expand_non_macro_stmt::closure.68388
  21:        0x10ef0b5a3 - ext::expand::expand_stmt::hbe43f4150453a1b4t7b
  22:        0x10ef3085e - ext::expand::expand_block_elts::closure.68722
  23:        0x10ef305ba - iter::FlatMap<I, U, F>.Iterator::next::h5626001629407774195
  24:        0x10ef2fc77 - vec::Vec<T>.FromIterator<T>::from_iter::h5081602814983063810
  25:        0x10ef2f86f - ext::expand::expand_block_elts::closure.68715
  26:        0x10eef6794 - ext::expand::expand_block_elts::h46bebebd90c7c5fdnic
  27:        0x10ef2f4bd - ext::expand::expand_block::h0a7e72090e4cf398Ihc
  28:        0x10eef6293 - ext::expand::expand_and_rename_fn_decl_and_block::h384c6a1c45a18003wGc
  29:        0x10eefc539 - ext::expand::expand_item_underscore::h8b5990810bd9fc6e4Vb
  30:        0x10ef50f0a - fold::noop_fold_item_simple::h10230394405410749093
  31:        0x10ef50a79 - fold::noop_fold_item::h6703425555223222517
  32:        0x10eefa32a - ext::expand::expand_annotatable::h707bae4d90aeefc9Bsc
  33:        0x10eef6938 - ext::expand::expand_item::h8d338912a8cd204dtVb
  34:        0x10ef02985 - iter::FlatMap<I, U, F>.Iterator::next::h12350997629097857049
  35:        0x10ef0249c - vec::Vec<T>.FromIterator<T>::from_iter::h7763438502537858767
  36:        0x10ef021ca - fold::noop_fold_mod::h6321912319619061707
  37:        0x10eefcdc9 - ext::expand::expand_item_underscore::h8b5990810bd9fc6e4Vb
  38:        0x10ef50f0a - fold::noop_fold_item_simple::h10230394405410749093
  39:        0x10ef50a79 - fold::noop_fold_item::h6703425555223222517
  40:        0x10eefb34e - ext::expand::expand_annotatable::h707bae4d90aeefc9Bsc
  41:        0x10eef6938 - ext::expand::expand_item::h8d338912a8cd204dtVb
  42:        0x10ef5a6b0 - ext::expand::expand_crate::hd42c32144acafe9dkRc
  43:        0x10d62a56a - driver::phase_2_configure_and_expand::closure.27279
  44:        0x10d5bd270 - driver::phase_2_configure_and_expand::h9a043ebdf303a32b3ta
  45:        0x10d5ad050 - driver::compile_input::h277a8ae423a5a9f3Yba
  46:        0x10d711e50 - run_compiler::h9482972dfd518dccbqc
  47:        0x10d70f749 - boxed::F.FnBox<A>::call_box::h12200329393199643738
  48:        0x10d70f142 - rt::unwind::try::try_fn::h12741742821322866078
  49:        0x1111514d8 - __rust_try
  50:        0x11113dcb0 - rt::unwind::try::inner_try::h03cd26bf8e2ee1ceTow
  51:        0x10d70f2f2 - boxed::F.FnBox<A>::call_box::h16465870040843100935
  52:        0x11115084d - sys::thread::Thread::new::thread_start::he62641fb2961f41aBNv
  53:     0x7fff8608f267 - _pthread_body
  54:     0x7fff8608f1e4 - _pthread_start
Could not compile `rust-bug`.

Caused by:
  Process didn't exit successfully: `rustc src/main.rs --crate-name rust_bug --crate-type bin -g --out-dir /Users/mange/Desktop/rust-bug/target/debug --emit=dep-info,link -L dependency=/Users/mange/Desktop/rust-bug/target/debug -L dependency=/Users/mange/Desktop/rust-bug/target/debug/deps --extern json_macros=/Users/mange/Desktop/rust-bug/target/debug/deps/libjson_macros-588fa665176505c5.dylib --extern rustc_serialize=/Users/mange/Desktop/rust-bug/target/debug/deps/librustc_serialize-7ff5bfc027146194.rlib` (exit code: 101)

(I broke the output into three so it's more obvious where the backtrace begins and ends.)


Let me know if there's anything else I can add or try.

@alexcrichton
Copy link
Member

Looking at the backtrace this looks like it's a bug in the json plugin, not the compiler?

@alexispurslane
Copy link
Contributor

Looking at libcollections/vec.rs:1047, I noticed that the indexing doesn't seem to be checked. So you could access an index out of bounds, and it would crash (I think):

#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Index<usize> for Vec<T> {
    type Output = T;

    #[inline]
    fn index(&self, index: usize) -> &T {
        // NB built-in indexing via `&[T]`
        &(**self)[index]
    }
}

@steveklabnik steveklabnik added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Sep 4, 2015
@steveklabnik
Copy link
Member

While this is a bug in the library, it shouldnt be possible for a library to cause an ICE

@Manishearth
Copy link
Member

@steveklabnik Panics from plugins (either if the plugin panics or calls an internal function incorrectly, causing a panic), are reported as ICEs by the compiler. So it is possible for a library to cause an ICE, though in this case I suspect that this is a "true" ICE.

@alexcrichton I don't think there are any cases where InternedString::new_from_string should cause a panic; so this is indeed an ICE, even if triggered by an external plugin.

I do recall seeing an error in InternedString recently (in the same function), but I completely forgot how it was caused.

@steveklabnik
Copy link
Member

This no longer works on current nightlies because the syntax extensions have changed since the bug was filed. As such, I'm going to give it a close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

5 participants