Narigo / keepass-diff

A CLI-tool to diff Keepass (.kdbx) files. Useful, if syncing with Dropbox or NextCloud and getting multiple files due to conflicts.
https://keepass-diff.narigo.dev/
MIT License
297 stars 27 forks source link

Error opening database #35

Closed Petemir closed 2 years ago

Petemir commented 3 years ago

Hello! Thanks for this very helpful tool :) . As others, I sometimes get sync(th)ing conflicts from using my database from several devices, and it's hard to know what went wrong.

When trying to check my database, I get the following error. Let me know how I can help debugging it further.

RUST_BACKTRACE=full keepass-diff NewDatabase.kdbx NewDatabase.kdbx --same-password thread 'main' panicked at 'Error opening database A: IO { e: Custom { kind: InvalidInput, error: "corrupt deflate stream" } }', /home/petemir/.cargo/registry/src/github.com-1ecc6299db9ec823/keepass-diff-1.1.1/src/main.rs:151:18 stack backtrace: 0: 0x5620e2a8e450 - std::backtrace_rs::backtrace::libunwind::trace::ha5edb8ba5c6b7a6c at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5 1: 0x5620e2a8e450 - std::backtrace_rs::backtrace::trace_unsynchronized::h0de86d320a827db2 at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 2: 0x5620e2a8e450 - std::sys_common::backtrace::_print_fmt::h97b9ad6f0a1380ff at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/sys_common/backtrace.rs:67:5 3: 0x5620e2a8e450 - ::fmt::h14be7eb08f97fe80 at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/sys_common/backtrace.rs:46:22 4: 0x5620e2aab68f - core::fmt::write::h2ca8877d3e0e52de at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/core/src/fmt/mod.rs:1094:17 5: 0x5620e2a8c315 - std::io::Write::write_fmt::h64f5987220b618f4 at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/io/mod.rs:1584:15 6: 0x5620e2a904fb - std::sys_common::backtrace::_print::h7f1a4097308f2e0a at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/sys_common/backtrace.rs:49:5 7: 0x5620e2a904fb - std::sys_common::backtrace::print::h1f799fc2ca7f5035 at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/sys_common/backtrace.rs:36:9 8: 0x5620e2a904fb - std::panicking::default_hook::{{closure}}::hf38436e8a3ce1071 at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/panicking.rs:208:50 9: 0x5620e2a8ffcd - std::panicking::default_hook::he2f8f3fae11ed1dd at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/panicking.rs:225:9 10: 0x5620e2a90b0d - std::panicking::rust_panic_with_hook::h79a18548bd90c7d4 at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/panicking.rs:591:17 11: 0x5620e2a906a7 - std::panicking::begin_panic_handler::{{closure}}::h212a72cc08e25126 at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/panicking.rs:497:13 12: 0x5620e2a8e8ec - std::sys_common::backtrace::rust_end_short_backtrace::hbd6897dd42bc0fcd at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/sys_common/backtrace.rs:141:18 13: 0x5620e2a90609 - rust_begin_unwind at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/panicking.rs:493:5 14: 0x5620e29c61c1 - core::panicking::panic_fmt::h77ecd04e9b1dd84d at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/core/src/panicking.rs:92:14 15: 0x5620e29c6253 - core::result::unwrap_failed::hcbdf25d28ce8f0ca at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/core/src/result.rs:1355:5 16: 0x5620e29d8aa9 - keepass_diff::main::h5e2b6f47066fe9ec 17: 0x5620e29d003a - std::sys_common::backtrace::rust_begin_short_backtrace::he4f613aeb728b811 18: 0x5620e29cdbf8 - std::rt::lang_start::{{closure}}::h99ff15c00735c998 19: 0x5620e2a9100a - core::ops::function::impls::<impl core::ops::function::FnOnce for &F>::call_once::hc4354216bf39217c at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/core/src/ops/function.rs:259:13 20: 0x5620e2a9100a - std::panicking::try::do_call::hb68eb312780385cf at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/panicking.rs:379:40 21: 0x5620e2a9100a - std::panicking::try::h22b8e08595060b8b at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/panicking.rs:343:19 22: 0x5620e2a9100a - std::panic::catch_unwind::hc64f1a6a0e71b1fc at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/panic.rs:431:14 23: 0x5620e2a9100a - std::rt::lang_start_internal::h4461fc58637f04f8 at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/rt.rs:34:21 24: 0x5620e29d92b2 - main 25: 0x7f33f10a6565 - __libc_start_main 26: 0x5620e29c68de - _start 27: 0x0 -

Narigo commented 3 years ago

Hi @Petemir and thanks for your report!

Is the quoted command the one you're using? RUST_BACKTRACE=full keepass-diff NewDatabase.kdbx NewDatabase.kdbx --same-password I mean that command looks like it should diff the same file with itself which wouldn't really make sense to me. I'm not sure whether opening both files at the same time could yield that issue - I'm not sure whether I ever tested that...! 🙂

If you were actually using two different files, did you check both files individually with the Keepass client you're usually using? "corrupt deflate stream" and "Error opening database A" sounds like it had trouble opening the first of the two files.

Petemir commented 3 years ago

Hi @Petemir and thanks for your report!

Hi @Narigo , thank you for answering :) .

Is the quoted command the one you're using? RUST_BACKTRACE=full keepass-diff NewDatabase.kdbx NewDatabase.kdbx --same-password I mean that command looks like it should diff the same file with itself which wouldn't really make sense to me. I'm not sure whether opening both files at the same time could yield that issue - I'm not sure whether I ever tested that...! slightly_smiling_face

Well, that's a new use case :smile: . Actually I first tested it with two different files, obviously. As I got the same error, I proceeded to test with the same file, just to see if it was a problem with either of the files.

If you were actually using two different files, did you check both files individually with the Keepass client you're usually using? "corrupt deflate stream" and "Error opening database A" sounds like it had trouble opening the first of the two files.

Yes, the file represents my current database, which I constantly and normally use everyday, across my desktop, Keepass2Android (Android) and StrongBox (iOS). Each one of them opens the file without any problems.

Let me know if I can help you debug something further.

Petemir commented 3 years ago

@Narigo I've narrowed down the problem. If an entry has a "large" attached file to it, the program will fail to open the database. With "large" I mean at least a few MB (I had problems already with 2MB files); files with a few hundred KB do not fail. I hope this helps :) .

Narigo commented 3 years ago

Thank you, that helps a lot! Do you want to create two simple reproducer files (with example passwords) so we could use this as a test? I never attached files to KeePass entries myself, so this is completely untested currently. Are smaller files being diffed already? The opening of the KeePass files is done through the underlying module from Stefan Seemayer - I will open an issue there and link it to this issue over here. /cc @sseemayer

I'll leave this issue open until using files is fixed here - thanks again for reporting this @Petemir !

Petemir commented 3 years ago

The command for testing these is keepass-diff Test-with* --passwords samplepassword .

I attach two zip files. One (Test_big_attachment.zip) contains two databases with one entry, one of them with a 2M random file attached; the other one (Test_small_attachment.zip) is the same, but with one small file instead. keepass-diff detects no difference between the databases in the latter case (i.e., they are not being diffed).

Test_big_attachment.zip Test_small_attachment.zip

Narigo commented 2 years ago

Finally came around to test the files myself. I have opened issue 47 at keepass-rs with your test file. Thanks again, I'll leave this open (with blocked label) until we can update to a newer version that allows us to open files with larger attachments.

DavidVentura commented 2 years ago

The fix was quite simple -- hopefully you can use the branch to test it

Narigo commented 2 years ago

Thanks a lot @DavidVentura! Looking forward for the new release @sseemayer 👍 Will close this issue once the new version is released and I've updated it here 🙂

Narigo commented 2 years ago

keepass-diff v1.1.4 is now available - @Petemir worked for me with the test files now. If it's still problematic, please reopen and let me know! Thanks again to everyone involved! :)

Petemir commented 2 years ago

I confirm it is working for me too in the full files :). Thank you everyone!