keemobile / kotpass

The library offers reading and writing support for KeePass (KDBX) files in Kotlin
MIT License
17 stars 0 forks source link

Crash during file decoding #8

Closed aivanovski closed 11 months ago

aivanovski commented 12 months ago

Unfortunately I can't provide the database file itself as crash happens not on my device, but maybe it can be fixed.

kotpass version 0.6.0

Original issue

 java.lang.IndexOutOfBoundsException: Collection doesn't contain element at index 19.
    at kotlin.collections.CollectionsKt___CollectionsKt$elementAt$1.invoke(_Collections.kt:87)
    at kotlin.collections.CollectionsKt___CollectionsKt$elementAt$1.invoke(_Collections.kt:87)
    at kotlin.collections.CollectionsKt___CollectionsKt.elementAtOrElse(_Collections.kt:117)
    at kotlin.collections.CollectionsKt___CollectionsKt.elementAt(_Collections.kt:87)
    at app.keemobile.kotpass.xml.BinaryReferenceKt.unmarshalBinaryReference(BinaryReference.kt:22)
    at app.keemobile.kotpass.xml.EntryKt.unmarshalEntry(Entry.kt:64)
    at app.keemobile.kotpass.xml.GroupKt.unmarshalGroup(Group.kt:72)
    at app.keemobile.kotpass.xml.GroupKt.unmarshalGroup(Group.kt:69)
    at app.keemobile.kotpass.xml.GroupKt.unmarshalGroup(Group.kt:69)
    at app.keemobile.kotpass.xml.GroupKt.unmarshalGroup(Group.kt:69)
    at app.keemobile.kotpass.xml.DefaultXmlContentParser.unmarshalContent(DefaultXmlContentParser.kt:38)
    at app.keemobile.kotpass.database.DecoderKt.decode(Decoder.kt:96)
    at app.keemobile.kotpass.database.DecoderKt.decode$default(Decoder.kt:25)
    at com.ivanovsky.passnotes.data.repository.keepass.kotpass.KotpassDatabase$Companion.open(KotpassDatabase.kt:464)
    at com.ivanovsky.passnotes.data.repository.keepass.KeepassDatabaseRepository.openDatabase(KeepassDatabaseRepository.kt:196)
    at com.ivanovsky.passnotes.data.repository.keepass.KeepassDatabaseRepository.open(KeepassDatabaseRepository.kt:61)
    at com.ivanovsky.passnotes.domain.interactor.unlock.UnlockInteractor$openDatabase$2.invokeSuspend(UnlockInteractor.kt:111)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
Anvell commented 12 months ago

Hello and thank you for reporting.

This surely can be fixed. Looks like this database contains wrong reference to attached file which was removed. Can you perhaps give a hint which KeePass client was used to save that database? It would be easier for me to reproduce this issue.

aivanovski commented 12 months ago

@aisbergde Sorry for bothering you, but that information really may help to fix this issue. Thank you!

aisbergde commented 12 months ago

@aivanovski unfortunately I don't know, how to identify entries containing attached files. Is there any idea how I could find them? I use the same file also on my Windows PC, maybe using any Windows client it would be possible to identify?

aivanovski commented 12 months ago

@aisbergde Could you name the app that you use on Windows?

For attachment identification, you may try KeePassXC.

Anvell commented 11 months ago

I've reproduced this issue and checked how popular KeePass clients react to this situation.

Client Behaviour
KeePass Drops invalid attachments
KeePassXC Keeps attachments as invalid references
KeeWeb Drops invalid attachments
MacPass Drops invalid attachments

I will make decoding more tolerable to such malformed content by dropping invalid references which seems to be acceptable solution for now.

aisbergde commented 11 months ago

sounds good. Because I can find entries with attached content, but even if I delete it, it will stay in the history. But I don't know what's invalid. If it would be possible to report the entry causing the error also would be helpful.

Anvell commented 11 months ago

Ideally I would like to have some logger to track such warning as well as fatal errors. But this is separate feature.

Right now this issue should be fixed in new version 0.6.1.

aivanovski commented 11 months ago

The database file was successfully opened. Issue may be closed