Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when trying to update an entry with Update-KeePassEntry #148

Closed
Wavelandian opened this issue Aug 3, 2018 · 22 comments
Closed
Assignees
Labels

Comments

@Wavelandian
Copy link

In some cases (most of cases, unable to identify a pattern), when trying to update an entry, by using this command:
Update-KeePassEntry -DatabaseProfileName $KPDBProfileName -MasterKey $KeePassDBPassword -KeePassEntry $entry -Title $title -KeePassEntryGroupPath $groupFullPath -force

I get the below exception:
image

---------------------------
Assertion Failed: Abort=Quit, Retry=Debug, Ignore=Continue
---------------------------
 
 
 
 
   at KeePassLib.Serialization.KdbxFile.WriteEntry(PwEntry pe, Boolean bIsHistory)
 
   at KeePassLib.Serialization.KdbxFile.WriteList(String name, PwObjectList`1 value, Boolean bIsHistory)
 
   at KeePassLib.Serialization.KdbxFile.WriteEntry(PwEntry pe, Boolean bIsHistory)
 
   at KeePassLib.Serialization.KdbxFile.<>c__DisplayClass204_0.<WriteDocument>b__1(PwEntry pe)
 
   at KeePassLib.PwGroup.PreOrderTraverseTree(GroupHandler groupHandler, EntryHandler entryHandler)
 
   at KeePassLib.PwGroup.PreOrderTraverseTree(GroupHandler groupHandler, EntryHandler entryHandler)
 
   at KeePassLib.PwGroup.PreOrderTraverseTree(GroupHandler groupHandler, EntryHandler entryHandler)
 
   at KeePassLib.PwGroup.PreOrderTraverseTree(GroupHandler groupHandler, EntryHandler entryHandler)
 
   at KeePassLib.PwGroup.PreOrderTraverseTree(GroupHandler groupHandler, EntryHandler entryHandler)
 
   at KeePassLib.PwGroup.TraverseTree(TraversalMethod tm, GroupHandler groupHandler, EntryHandler entryHandler)
 
   at KeePassLib.Serializatio......
 
<truncated>
---------------------------
Abort   Retry   Ignore   
---------------------------

Details of the machine I'm using:

Machine: VUKT10000085 (Microsoft Windows NT 6.1.7601 Service Pack 1)
Host Application: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Process ID: 7576
PSVersion: 5.1.14409.1005
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.14409.1005
BuildVersion: 10.0.14409.1005
CLRVersion: 4.0.30319.34209
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1

@jkdba
Copy link
Member

jkdba commented Aug 3, 2018

@Wavelandian thanks for reporting.

I'll take a look, think I have seen this before on the group level should be easy to fix, will see if I can release a fix by Monday.

@jkdba jkdba self-assigned this Aug 3, 2018
@jkdba jkdba added the bug label Aug 3, 2018
@Wavelandian
Copy link
Author

Wavelandian commented Aug 3, 2018 via email

@wi-fr
Copy link

wi-fr commented Aug 18, 2018

In my case I can see a clear pattern: this exception occurs whenever I update an entry that has been updated before.

@kshire
Copy link

kshire commented Aug 20, 2018

I was getting the same error this morning, but I added -Confirm:$false and no longer get the error message.

@ClaudioESSilva
Copy link

Hi @jkdba , any update on this?

In my case the problem is related with the history collection.

If I comment this line: https://github.com/PSKeePass/PoShKeePass/blob/master/internal/Set-KPEntry.ps1#L128 it saves without the error message.

Interesting that despite the error it saves the history anyway. (if I select ignore).

@wi-fr - with me is consistent. It happens every time
@kshire - for me the -Confirm:$false doesn't work, still give the error.

@SimonBrangwin
Copy link

I'm seeing the same assertion.
As the scripts are run non-interactively, this prompt isn't seen by the user and the KeePass database which is stored on a network share was left partially written and completely corrupted.
So we had to pull the database back from a recent backup.
Could the KeePass database saving method be altered to write to a temporary file first, then replace it, in case these kind of assertions occur midway through serialization?

PSES module version: 1.10.0
PSVersion: 5.1.15063.1387
PSEdition: Desktop
PSBuildVersion: 10.0.15063.1387
CLRVersion: 4.0.30319.42000
Operating system: Windows 64-bit 10.0.15063

@kdmhorn
Copy link

kdmhorn commented Jan 8, 2019

Think I found a fix for this.

I found that if you insert a $OldEntry.History.Clear() right before the $KeePassEntry.History.Add($OldEntry) referenced by @ClaudioESSilva the exception is no longer thrown on an update.

@Shaun-Harrison
Copy link

Just opened another issue with the same problem

Is this still being investigated ?

@Shaun-Harrison
Copy link

Think I found a fix for this.

I found that if you insert a $OldEntry.History.Clear() right before the $KeePassEntry.History.Add($OldEntry) referenced by @ClaudioESSilva the exception is no longer thrown on an update.

Hi

New to all of this so please bare with me,

If i download the files and make this change, how then do i load the module into powershell to be used, instead of the original?

@kdmhorn
Copy link

kdmhorn commented Feb 4, 2019

Seems the project owner hasn't been here is quite some time....the way I did the update:
installed PoshKeePass, then found where the module files (%programfiles%\windowspowershell\modules\poshkeepass\2.1.1.8), make a copy just in case then open the PoshKeePass.psm1 file add the line - somewhere around line 2896, after that had no issues with updating entries.

@wi-fr
Copy link

wi-fr commented Feb 7, 2019

Thanks, kdmhorn, your fix solved my problem

@DamionD
Copy link

DamionD commented Feb 13, 2019

Performing the fix above caused the following exception:
Exception calling "Open" with "3" argument(s): "The file header is corrupted. Data is missing at the end of the file, i.e. the file is incomplete."
I imagine that this is because I have installed the module from the PowerShell Gallery. Can anyone update the module in the absence of the maintainer, or are we out of luck?

@Shaun-Harrison
Copy link

@DamionD - The above fix wouldn't have caused that - running the command before the fix does, as when the error message appears, if you click abort it leaves your .kdbx file in a incomplete state

The fix stops this from happening

@jkdba
Copy link
Member

jkdba commented Mar 8, 2019

Hi @kdmhorn @SJHarrison1992 can anyone confirm if the history is maintained in the updated entry with the suggested fix?

@kdmhorn
Copy link

kdmhorn commented Mar 8, 2019

I believe it does, but let me check Monday morning when I have access to my test database. What the process is doing is copying the record current state to a new object, it clears the history from that copied object then adds it to the history of the original record before committing the changes made. I'm not great with code (C++ or C#) but had found the fix by tracing what KeePASS source code does with an update.

@jkdba
Copy link
Member

jkdba commented Mar 8, 2019

Just tested and commited fix, released and pushed to psgallery.

@xtremedew
Copy link

This seems to still be occurring, even after updating to 2.1.2.0.
This seems to occur when an entry has a history inside it.

I could also be doing something wrong though. Any suggestions?

@jkdba
Copy link
Member

jkdba commented Mar 10, 2019

@xtremedew lets clarify the issue we are seeing. From my testing this is what I found:

  1. create new entry - no issue
  2. update entry - no issue
  3. update entry again - issue occurs

After testing with fix this behavior was resolved for me, Can you provide a step by step of how your issue occurs so I can reproduce it.

@xtremedew
Copy link

@jkdba - I am pretty sure I resolved this on my end. I think I was running old code somewhere. I deleted everything and started again from scratch - No issues now. Sorry for causing any panic or confusion. Thanks for the help! Keep up the good work.

@jkdba
Copy link
Member

jkdba commented Mar 11, 2019

@xtremedew no worries, glad to know you found it! Just tested again as sanity and still didn't have the issue. Let me know if anything comes up.

@jkdba jkdba closed this as completed Mar 11, 2019
@Shaun-Harrison
Copy link

Can confirm history is maintained with the suggested fix

Great to see you are maintaining this great library

@jkdba
Copy link
Member

jkdba commented Mar 12, 2019

@SJHarrison1992 great! Yes not always as frequently as I would like.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants