jameslittle230 / stork

🔎 Impossibly fast web search, made for static sites.
https://stork-search.net
Apache License 2.0
2.73k stars 56 forks source link

Panic in `fill_containers.rs:116` when indexing URL in markdown content #227

Closed deining closed 2 years ago

deining commented 2 years ago

I'm trying to index some markdown-files, and stork is crashing during index generation:

Stacktrace:

    Finished dev [unoptimized + debuginfo] target(s) in 0.33s
     Running `target\debug\stork-cli.exe build --input ..\content\stork-config.toml --output stork.st`
thread 'main' panicked at 'attempt to subtract with overflow', stork-index-v3\src\build\fill_containers.rs:116:24
stack backtrace:
   0:     0x7ff69dec843f - std::backtrace_rs::backtrace::dbghelp::trace
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\..\..\backtrace\src\backtrace\dbghelp.rs:98
   1:     0x7ff69dec843f - std::backtrace_rs::backtrace::trace_unsynchronized
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\..\..\backtrace\src\backtrace\mod.rs:66
   2:     0x7ff69dec843f - std::sys_common::backtrace::_print_fmt
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\sys_common\backtrace.rs:67
   3:     0x7ff69dec843f - std::sys_common::backtrace::_print::impl$0::fmt
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\sys_common\backtrace.rs:46
   4:     0x7ff69dedf6da - core::fmt::write
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\core\src\fmt\mod.rs:1163
   5:     0x7ff69dec4518 - std::io::Write::write_fmt<std::sys::windows::stdio::Stderr>
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\io\mod.rs:1696
   6:     0x7ff69deca9e6 - std::sys_common::backtrace::_print
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\sys_common\backtrace.rs:49
   7:     0x7ff69deca9e6 - std::sys_common::backtrace::print
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\sys_common\backtrace.rs:36
   8:     0x7ff69deca9e6 - std::panicking::default_hook::closure$1
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\panicking.rs:210
   9:     0x7ff69deca3e7 - std::panicking::default_hook
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\panicking.rs:227
  10:     0x7ff69decb045 - std::panicking::rust_panic_with_hook
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\panicking.rs:624
  11:     0x7ff69decabff - std::panicking::begin_panic_handler::closure$0
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\panicking.rs:519
  12:     0x7ff69dec8d67 - std::sys_common::backtrace::__rust_end_short_backtrace<std::panicking::begin_panic_handler::closure$0,never$>
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\sys_common\backtrace.rs:139
  13:     0x7ff69decab89 - std::panicking::begin_panic_handler
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\panicking.rs:517
  14:     0x7ff69dee7700 - core::panicking::panic_fmt
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\core\src\panicking.rs:100
  15:     0x7ff69dee764c - core::panicking::panic
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\core\src\panicking.rs:50
  16:     0x7ff69d7747b5 - stork_index_v3::build::fill_containers::fill_other_containers_alias_maps_with_prefixes
                               at C:\Users\Andreas\Documents\stork\stork-index-v3\src\build\fill_containers.rs:116
  17:     0x7ff69d7740f0 - stork_index_v3::build::fill_containers::fill_containers
                               at C:\Users\Andreas\Documents\stork\stork-index-v3\src\build\fill_containers.rs:47
  18:     0x7ff69d749909 - stork_index_v3::build::build
                               at C:\Users\Andreas\Documents\stork\stork-index-v3\src\build\mod.rs:62
  19:     0x7ff69d722109 - stork_lib::build_index
                               at C:\Users\Andreas\Documents\stork\stork-lib\src\lib.rs:158
  20:     0x7ff69d707a1d - stork_cli::build_handler
                               at C:\Users\Andreas\Documents\stork\stork-cli\src\main.rs:91
  21:     0x7ff69d706d42 - stork_cli::main
                               at C:\Users\Andreas\Documents\stork\stork-cli\src\main.rs:29
  22:     0x7ff69d6f199b - core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\core\src\ops\function.rs:227
  23:     0x7ff69d70d10b - std::sys_common::backtrace::__rust_begin_short_backtrace<void (*)(),tuple$<> >
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\std\src\sys_common\backtrace.rs:123
  24:     0x7ff69d709831 - std::rt::lang_start::closure$0<tuple$<> >
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\std\src\rt.rs:146
  25:     0x7ff69dec7f2b - core::ops::function::impls::impl$2::call_once
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\core\src\ops\function.rs:259
  26:     0x7ff69dec7f2b - std::panicking::try::do_call
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\panicking.rs:403
  27:     0x7ff69dec7f2b - std::panicking::try
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\panicking.rs:367
  28:     0x7ff69dec7f2b - std::panic::catch_unwind
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\panic.rs:133
  29:     0x7ff69dec7f2b - std::rt::lang_start_internal::closure$2
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\rt.rs:128
  30:     0x7ff69dec7f2b - std::panicking::try::do_call
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\panicking.rs:403
  31:     0x7ff69dec7f2b - std::panicking::try
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\panicking.rs:367
  32:     0x7ff69dec7f2b - std::panic::catch_unwind
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\panic.rs:133
  33:     0x7ff69dec7f2b - std::rt::lang_start_internal
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\/library\std\src\rt.rs:128
  34:     0x7ff69d7097ff - std::rt::lang_start<tuple$<> >
                               at /rustc/f1edd0429582dd29cccacaf50fd134b05593bd9c\library\std\src\rt.rs:145
  35:     0x7ff69d7097c6 - main
  36:     0x7ff69dee5bf0 - invoke_main
                               at d:\a01\_work\6\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
  37:     0x7ff69dee5bf0 - __scrt_common_main_seh
                               at d:\a01\_work\6\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
  38:     0x7ffee10e7034 - BaseThreadInitThunk
  39:     0x7ffee2242651 - RtlUserThreadStart
error: process didn't exit successfully: `target\debug\stork-cli.exe build --input ..\content\stork-config.toml --output stork.st` (exit code: 101)

My environment:

jameslittle230 commented 2 years ago

Sorry that you're experiencing this crash!

I'm looking at the panicking line, and it might be one single word in one single file causing the crash. Could you send the markdown file that's causing the issue to me, either here or to my email stork@jameslittle.me?

deining commented 2 years ago

Thanks for your quick response!

Sorry that you're experiencing this crash!

Don't worry!

I'm looking at the panicking line, and it might be one single word in one single file causing the crash.

Bingo. I could track it down, and the offending line/word inside my markdown file is an URL:

https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+bash+c+csharp+cpp+go+java+markdown+python+scss+sql+toml+yaml&plugins=toolbar+copy-to-clipboard
jameslittle230 commented 2 years ago

Nice, thanks for tracking that down. I'll get started on a PR to fix this.

Just so I know where to focus - is the URL "bare" within the text, or is it within a link? In other words, does the document look like this:

yadda yadda yadda your blog post talks about Prism, which you can read more about at https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+bash+c+csharp+cpp+go+java+markdown+python+scss+sql+toml+yaml&plugins=toolbar+copy-to-clipboard and I like using Prism because of these reasons

or is it like this:

yadda yadda yadda your blog post talks about [Prism](https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+bash+c+csharp+cpp+go+java+markdown+python+scss+sql+toml+yaml&plugins=toolbar+copy-to-clipboard) and I like using Prism because of these reasons
deining commented 2 years ago

Nice, thanks for tracking that down. I'll get started on a PR to fix this.

Thanks for your commitment!

Just so I know where to focus - is the URL "bare" within the text

Yes. The URL is inside a fenced code block:

* Prism download link:

```none
    https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+bash+c+csharp+cpp+go+java+markdown+python+scss+sql+toml+yaml&plugins=toolbar+copy-to-clipboard


However, currently `stork` crashes on the URL on a single line (without fenced code block, as given in my [previous comment](https://github.com/jameslittle230/stork/issues/227#issuecomment-1003765913)), too. 
jameslittle230 commented 2 years ago

This is now fixed in master, and will be part of the next minor release, 1.4.0! Thanks again for the report :)