informationsea / bgzip-rs

bgzip support for Rust
https://crates.io/crates/bgzip
MIT License
15 stars 4 forks source link

Panic when reaching end of file. #4

Closed shahamran closed 3 years ago

shahamran commented 3 years ago

I think this is the same problem as #3, and that it's unrelated to reading across blocks. The following test fails when added to lib.rs :

#[test]
fn test_read_all() -> Result<(), BGZFError> {
    let reader =
        BGZFReader::new(fs::File::open("testfiles/common_all_20180418_half.vcf.gz")?);
    for _line in reader.lines() {}
    Ok(())
}

with the following backtrace:

thread 'test::test_read_all' panicked at 'internal error: entered unreachable code', src/read.rs:130:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/core/src/panicking.rs:92:14
   2: core::panicking::panic
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/core/src/panicking.rs:50:5
   3: <bgzip::read::BGZFReader<R> as std::io::BufRead>::fill_buf
             at ./src/read.rs:130:9
   4: std::io::read_until
             at /homes/ransh/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/mod.rs:1766:35
   5: std::io::BufRead::read_line::{{closure}}
             at /homes/ransh/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/mod.rs:2025:35
   6: std::io::append_to_string
             at /homes/ransh/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/mod.rs:333:19
   7: std::io::BufRead::read_line
             at /homes/ransh/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/mod.rs:2025:9
   8: <std::io::Lines<B> as core::iter::traits::iterator::Iterator>::next
             at /homes/ransh/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/io/mod.rs:2562:15
   9: bgzip::test::test_read_all
             at ./src/lib.rs:127:22
  10: bgzip::test::test_read_all::{{closure}}
             at ./src/lib.rs:124:5
  11: core::ops::function::FnOnce::call_once
             at /homes/ransh/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
  12: core::ops::function::FnOnce::call_once
             at /rustc/9bc8c42bb2f19e745a63f3445f1ac248fb015e53/library/core/src/ops/function.rs:227:5

As a more minimal test, generating a really small bgzip file, like:

$ printf "hello\nworld\n" | bgzip > test.gz

and using reader.read_line() on it more than twice panics.