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

rustdoc --theme-checker panics when given an empty file #61145

Closed
lambda-fairy opened this issue May 25, 2019 · 3 comments · Fixed by #61181
Closed

rustdoc --theme-checker panics when given an empty file #61145

lambda-fairy opened this issue May 25, 2019 · 3 comments · Fixed by #61181
Assignees
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@lambda-fairy
Copy link
Contributor

When I run the following commands:

touch empty-file.css
RUST_BACKTRACE=1 rustdoc -Z unstable-options --theme-checker empty-file.css

Rustdoc outputs the following:

rustdoc: [theme-checker] Starting tests!
thread '<unnamed>' panicked at 'index out of bounds: the len is 0 but the index is 0', src/librustdoc/theme.rs:114:15
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:59
             at src/libstd/panicking.rs:197
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:211
   4: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:474
   5: std::panicking::continue_panic_fmt
             at src/libstd/panicking.rs:381
   6: rust_begin_unwind
             at src/libstd/panicking.rs:308
   7: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
   8: core::panicking::panic_bounds_check
             at src/libcore/panicking.rs:61
   9: rustdoc::theme::load_css_paths
  10: rustdoc::theme::test_theme_against
  11: rustdoc::config::Options::from_matches
  12: rustdoc::main_args
 - Checking "empty-file.css"...

I would have expected it to output a list of missing rules, without panicking.

Meta

rustc --version --verbose:

rustc 1.36.0-nightly (dec4c5201 2019-05-24)
binary: rustc
commit-hash: dec4c5201f88efbc3020b04ba96a5ee2c3b6cfcd
commit-date: 2019-05-24
host: x86_64-unknown-linux-gnu
release: 1.36.0-nightly
LLVM version: 8.0
@lambda-fairy
Copy link
Contributor Author

lambda-fairy commented May 25, 2019

load_css_paths doesn't have any indexing operations, so I suspect the error comes from inlined code in load_css_events:

while pos < v.len() - 1 {

When v is empty, v.len() is 0usize, and we can't subtract one from that.

An easy fix would be to change that - 1 to .saturating_sub(1).

@estebank estebank added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label May 25, 2019
@Lonami
Copy link
Contributor

Lonami commented May 25, 2019

Another possible fix is simply:

while pos + 1 < v.len() {

@GuillaumeGomez GuillaumeGomez added T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. and removed A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools labels May 25, 2019
@GuillaumeGomez GuillaumeGomez self-assigned this May 25, 2019
@GuillaumeGomez
Copy link
Member

Sending the fix quickly!

Centril added a commit to Centril/rust that referenced this issue Jun 21, 2019
…=kinnison

Fix theme-checker failure

Fixes rust-lang#61145.

I didn't find a way to check it without strongly depending on the output... Is there a way to check if a program fails without checking its output?

r? @QuietMisdreavus
Centril added a commit to Centril/rust that referenced this issue Jun 21, 2019
…=kinnison

Fix theme-checker failure

Fixes rust-lang#61145.

I didn't find a way to check it without strongly depending on the output... Is there a way to check if a program fails without checking its output?

r? @QuietMisdreavus
Centril added a commit to Centril/rust that referenced this issue Jun 21, 2019
…=kinnison

Fix theme-checker failure

Fixes rust-lang#61145.

I didn't find a way to check it without strongly depending on the output... Is there a way to check if a program fails without checking its output?

r? @QuietMisdreavus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants