stumpapp / stump

A free and open source comics, manga and digital book server with OPDS support (WIP)
https://stumpapp.dev
MIT License
941 stars 43 forks source link

[BUG] Panic message on scan of new ebook library #259

Closed xxshade closed 7 months ago

xxshade commented 8 months ago

Describe the bug After adding a library of epubs, the scan stops and gives an error in the logs: 'thread 'tokio-runtime-worker' panicked at 'range end index 3 out of range for slice of length 0', /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/epub-1.2.4/src/xmlutils.rs:31:32'. The scan job just stays there, doing nothing forever, and any other scheduled scans never happen. When listing the epub library, only some series were scanned and have the correct number of books and thumbnails; the others only have the series name displayed with 0 books and no thumbnail.

To Reproduce Steps to reproduce the behavior:

  1. Create a new library
  2. Put name, path, library pattern -> Series Based
  3. Thumbnail -> Custom Scaled suggested size, format and quality
  4. Scan mode -> Default
  5. Create Library
  6. Some series will appear with thumbnails and the correct number of files, but the rest will only show the folder name with 0 items
  7. The panic message is displayed in the log.

Desktop (please complete the following information):

Additional context Logs with RUST_BACKTRACE=full

stump | Starting job: library_scan stump | thread 'tokio-runtime-worker' panicked at 'range end index 3 out of range for slice of length 0', /usr/local/cargo/registry/src/index.crates.io-6f17d22bba15001f/epub-1.2.4/src/xmlutils.rs:31:32 stump | stack backtrace: stump | 0: 0xaaaab7afc7d8 - std::backtrace_rs::backtrace::libunwind::trace::hc366d13e3075cfeb stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5 stump | 1: 0xaaaab7afc7d8 - std::backtrace_rs::backtrace::trace_unsynchronized::hb9a35e1f782586fe stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 stump | 2: 0xaaaab7afc7d8 - std::sys_common::backtrace::_print_fmt::hae0d6c377f414e8d stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/sys_common/backtrace.rs:65:5 stump | 3: 0xaaaab7afc7d8 - ::fmt::h0f8916ea7cac138e stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/sys_common/backtrace.rs:44:22 stump | 4: 0xaaaab7b262e4 - core::fmt::rt::Argument::fmt::hf491ec0da00c9b40 stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/fmt/rt.rs:138:9 stump | 5: 0xaaaab7b262e4 - core::fmt::write::h075f235dea7f2ae2 stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/fmt/mod.rs:1094:21 stump | 6: 0xaaaab7af87f4 - std::io::Write::write_fmt::hed461f96db027bb0 stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/io/mod.rs:1714:15 stump | 7: 0xaaaab7afc628 - std::sys_common::backtrace::_print::h9f6cc87d40ba87f7 stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/sys_common/backtrace.rs:47:5 stump | 8: 0xaaaab7afc628 - std::sys_common::backtrace::print::hc36324e2f472d029 stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/sys_common/backtrace.rs:34:9 stump | 9: 0xaaaab7afdddc - std::panicking::default_hook::{{closure}}::h8d8f8741b904046c stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/panicking.rs:269:22 stump | 10: 0xaaaab7afdb6c - std::panicking::default_hook::h6fd0090c1af86ae9 stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/panicking.rs:288:9 stump | 11: 0xaaaab7afe380 - std::panicking::rust_panic_with_hook::h25082e1f49b04873 stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/panicking.rs:705:13 stump | 12: 0xaaaab7afe248 - std::panicking::begin_panic_handler::{{closure}}::hd64c14bd1869359d stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/panicking.rs:597:13 stump | 13: 0xaaaab7afcc0c - std::sys_common::backtrace::__rust_end_short_backtrace::h8613664e493d4a0e stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/sys_common/backtrace.rs:151:18 stump | 14: 0xaaaab7afdfa4 - rust_begin_unwind stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/panicking.rs:593:5 stump | 15: 0xaaaab6076778 - core::panicking::panic_fmt::h354dad60a2e185d5 stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/panicking.rs:67:14 stump | 16: 0xaaaab6076b50 - core::slice::index::slice_end_index_len_fail_rt::h28c91a6152b26b6f stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/slice/index.rs:76:5 stump | 17: 0xaaaab6076b50 - core::slice::index::slice_end_index_len_fail::h4a3a53b80f3cb3e4 stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/core/src/slice/index.rs:68:9 stump | 18: 0xaaaab7096434 - epub::xmlutils::XMLReader::parse::h0473481b2bfbdf0c stump | 19: 0xaaaab6ae6314 - epub::doc::EpubDoc<std::io::buffered::bufreader::BufReader>::new::h4a8065724ee81567 stump | 20: 0xaaaab6dc9c0c - stump_core::filesystem::media::epub::EpubProcessor::open::hc3d0e06f0d86846e stump | 21: 0xaaaab6dc8974 - ::process::h1aac15c1bfe09bc8 stump | 22: 0xaaaab6af7f20 - stump_core::filesystem::media::process::process::hf96b9362a8a13d7d stump | 23: 0xaaaab6c3bc7c - stump_core::filesystem::media::builder::MediaBuilder::build::h4bf0f52a540f78c1 stump | 24: 0xaaaab6e075a4 - stump_core::filesystem::scanner::series_scanner::SeriesScanner::scan_series::{{closure}}::h94d3e451f6e5062b stump | 25: 0xaaaab6e19350 - ::run::{{closure}}::h416964bd8c02c2c4 stump | 26: 0xaaaab60ff938 - <tokio::future::poll_fn::PollFn as core::future::future::Future>::poll::h3cec70be0ee847b5 stump | 27: 0xaaaab65cba04 - <stump_core::job::executor::Job as stump_core::job::executor::JobExecutorTrait>::execute::{{closure}}::h6e6befdce6d76f22 stump | 28: 0xaaaab6cce074 - stump_core::job::worker::Worker::spawn::{{closure}}::{{closure}}::hc320983ccdc2b661 stump | 29: 0xaaaab6cba9e4 - tokio::runtime::task::core::Core<T,S>::poll::h5acea773f3beacc6 stump | 30: 0xaaaab6c605b4 - tokio::runtime::task::harness::Harness<T,S>::poll::h5afc54dbfcf0e40e stump | 31: 0xaaaab768f434 - tokio::runtime::scheduler::multi_thread::worker::Context::run_task::ha3303a514156e652 stump | 32: 0xaaaab768e618 - tokio::runtime::scheduler::multi_thread::worker::Context::run::hf518c4d84cf5f57f stump | 33: 0xaaaab766feac - tokio::runtime::context::scoped::Scoped::set::hb8dcbdeec97b677b stump | 34: 0xaaaab766730c - tokio::runtime::context::runtime::enter_runtime::hfe14776a52551e62 stump | 35: 0xaaaab768e434 - tokio::runtime::scheduler::multi_thread::worker::run::h6663b592adba798c stump | 36: 0xaaaab7676bd0 - <core::panic::unwind_safe::AssertUnwindSafe as core::ops::function::FnOnce<()>>::call_once::ha15401e9831020b3 stump | 37: 0xaaaab7664170 - tokio::runtime::task::harness::Harness<T,S>::poll::hbbd0f56055186bbc stump | 38: 0xaaaab76735e8 - tokio::runtime::blocking::pool::Inner::run::hc01fb4d7b4b74f95 stump | 39: 0xaaaab7667c00 - std::sys_common::backtrace::__rust_begin_short_backtrace::hc5adb0c0f84365cb stump | 40: 0xaaaab7682d24 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h5f2b50edaf1843ee stump | 41: 0xaaaab7b019c4 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce>::call_once::hd6a6c972c6220bcb stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/alloc/src/boxed.rs:1993:9 stump | 42: 0xaaaab7b019c4 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce>::call_once::h3b759ee01954e7b0 stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/alloc/src/boxed.rs:1993:9 stump | 43: 0xaaaab7b019c4 - std::sys::unix::thread::Thread::new::thread_start::hd2c1311433b59ac2 stump | at /rustc/d5c2e9c342b358556da91d61ed4133f6f50fc0c3/library/std/src/sys/unix/thread.rs:108:17 stump | 44: 0xffffbac777e4 - start_thread stump | 45: 0xffffbaaed70c - stump | 46: 0x0 -

(P.S. I tried using the code tag here, but it removed new lines on the log.)

aaronleopold commented 8 months ago

Hey, thanks for reporting this!

At a quick glance, it seems to be a bug upstream in epub-rs, and points to this file (my guess is line 45)

I'll investigate further tomorrow and try and put up a PR there to correct it. In the meantime, if you're able to bump the verbosity of Stump's logs to try and find the problematic file so I can reproduce it locally.

When listing the epub library, only some series were scanned and have the correct number of books and thumbnails; the others only have the series name displayed with 0 books and no thumbnail.

This is expected after a panic like this, unfortunately. Stump's scanner creates all new series before proceeding, and since the epub-rs library is causing a panic at a point in the middle of the scan any pending transactions won't get persisted.

xxshade commented 8 months ago

Sure, I didn't know that there was an environment for that =x For future reference: STUMP_VERBOSITY=2 -> debug STUMP_VERBOSITY=1 -> warn STUMP_VERBOSITY=0 -> default

I found the offending book: 'The Zashiki Warashi of Intellectual Village (Bonus Track): Hayabusa & Enbi’s Testimony - What Really Happened During the Glass House Case?' (I got it from the Baka-Tsuki site six years ago) Removing it makes the scan finish without problems. Downloading the ebook again solves the problem too. It seems that my copy was corrupted or something like that >.>

aaronleopold commented 8 months ago

STUMP_VERBOSITY=2 -> debug STUMP_VERBOSITY=1 -> warn STUMP_VERBOSITY=0 -> default

In case it's helpful, there's a visual breakdown of each supported level here: https://www.stumpapp.dev/guides/configuration#stump_verbosity

I found the offending book: 'The Zashiki Warashi of Intellectual Village (Bonus Track): Hayabusa & Enbi’s Testimony - What Really Happened During the Glass House Case?'

Awesome, would you mind sending it my way? That way I can more easily validate a fix. You can use something like https://wormhole.app/

xxshade commented 8 months ago

Sure: The Zashiki Warashi of Intellectual Village (Bonus Track): Hayabusa & Enbi’s Testimony - What Really Happened During the Glass House Case?

aaronleopold commented 8 months ago

Thank you!

aaronleopold commented 8 months ago

Alright, so I've narrowed it down to an empty content.opf file inside the archive. I've confirmed locally that adjusting the epub-rs logic catches that scenario and avoids the panic, so I'll make a PR upstream 👍

Edit to add that I've made the PR and it should be visible below. If it doesn't get approved and released within a week or two, I'll point Stump to use my fork for the time being. I do definitely think the file itself is corrupt, since I had to jump through some hoops to even unzip it without error, but I'm generally a fan of removing panics so 🙂

aaronleopold commented 7 months ago

Automate closed it before a fix went out lol I'll give it more time before pointing to my fork

aaronleopold commented 7 months ago

Doesn't look like it's been released yet. I'll pin Stump to use the commit instead over the weekend so the fix can go out

aaronleopold commented 7 months ago

The fix will go out on the next nightly build, and will likely be the head for 0.0.1