vv9k / mobi-rs

A crate to work with MOBI format ebooks
MIT License
38 stars 10 forks source link

Opening mobi file causes high CPU / memory usage indefinitely #5

Closed philippeitis closed 4 years ago

philippeitis commented 4 years ago

When trying to open a specific mobi file to read the metadata, the program maxes out an entire core of CPU usage and the RAM usage grows continuously, by >400MB per minute (reaching 1GB+ of RAM usage for a 2MB book in about 3 minutes, and I did not see the program exit), which makes it seem like this is a decompression error. On Windows, Calibre and SumatraPDF open the book without issue.

I can send a copy of the MOBI by email (to avoid issues with uploading it to a public website).

A minimal code example needed to reproduce the issue (at least on Windows and Ubuntu in WSL):

use mobi::Mobi;

fn main() -> Result<(), ()> {
    let doc = match Mobi::from_path("books/All Systems Red - Martha Wells.mobi") {
        Err(_) => return Ok(()),
        Ok(d) => d,
    };
    Ok(())
}

The program is run with cargo run --release.

vv9k commented 4 years ago

Thanks for the report. I will be glad to look into it. My email is wojciech@wkepka.dev.

I'm pretty sure the decompression algorithm might be incorrect. I was thinking of swapping my implementation with a crate that does lz77 so might actually be worth to look into that a bit more.