Repository navigation
Fix 2-day timestamp offset and preserve unknown XML elements - #9
Open
guilherme-n-l wants to merge 1 commit into
Open
guilherme-n-l wants to merge 1 commit into
guilherme-n-l wants to merge 1 commit into
Conversation
The 3.0 rejection test wraps a typed-throws `KDBXReader.parse` call in
`do { } catch let error as KDBXReader.Error { }`. Swift 6.3.3 aborts
while compiling that pattern (SIL ownership verifier: "Found ownership
error?!", signal 6), so the whole test target fails to build.
Because `parse` throws `KDBXReader.Error`, the bound `error` in a plain
`catch` already has that type, and the cast was redundant. Use `catch`
instead. Behaviour is unchanged, and the test target builds again on
both 6.1 and 6.3.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HdzqH7rejgXYHCaGaUAzNj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This fixes two data-integrity bugs that show up when a vault is shared with other KeePass clients:
Each fix is its own commit. A third, small commit works around a Swift 6.3 compiler crash so the test target builds.
1. Proleptic Gregorian .NET epoch (
fix: use the proleptic Gregorian .NET epoch for KDBX 4 dates)Date.dotNetEpochwas built withDateComponents+Calendar(identifier: .gregorian). Foundation's Gregorian calendar uses the Julian calendar before the 1582 cutover, so the epoch came out as-62_135_769_600instead of-62_135_596_800, which is 2 days early. KDBXKit's own read and write cancelled out. Interop did not: KeePassXC dates were read 2 days early, our dates showed 2 days in the future in KeePassXC, and a 3.1 → 4.1 migration shifted every timestamp by +2 days.dotNetEpochis now the literalDate(timeIntervalSince1970: -62_135_596_800), with a doc comment explaining the cutover. It is internal (was private) so tests can check it.DotNetEpochTestschecks the constant and absolute known values in both directions: 1970-01-01, 2000-02-29T12:34:56Z and 2025-06-01.XMLDocumentReader_emptyasserted the shifted value. It now expectsCurE3w4AAAA== 2025-05-25T10:38:02Z (1_748_169_482).Checked end to end against keepassxc-cli 2.7.6. I created a vault and an entry with
kdbxat 17:58:30Z, then rankeepassxc-cli export -f csv:Createddevelop(e9b8839)2026-10-06T17:58:30Z(+2 days)2026-10-04T17:57:28Z(correct)2. Preserve unknown XML elements (
fix: preserve unknown XML elements across read and write)The reader logged unrecognized elements to
parserWarningsand discarded them. Elements written by other clients, plugins or newer format revisions were lost on the next save.KDBX.UnknownElement(Sendable,Equatable). It holds the name, the attributes, andchildrenas.element/.text.unknownElements: [KDBX.UnknownElement]onKDBX(top-levelKeePassFilechildren),Meta,Root,GroupandEntry(history entries included). The new init parameters default to[], so existing call sites compile unchanged.Meta.unknownElementsdoesn't bumpsettingsChanged.Preserved unknown element <path>.XMLDocumentWriter, so both keep them.Times,AutoType,CustomData, …) are still dropped with a warning, as before. This keeps the change focused.Protected="True"value inside an unknown element is written back as the same ciphertext. KeePass, KeePassXC and this reader skip unknown elements without consuming inner-stream keystream, so other protected values are unaffected. The interop test below covers this.docs/spec/kdbx-xml.md(section 1.2, Appendix C) andCLAUDE.mdare updated to describe the new behaviour.Tests:
UnknownElementTestscovers:KDBXWriter.writeandKDBXWriter.streamingWrite, with a protected password after the unknown subtree.KeePassXCInteropTests.ourOutput_withUnknownElements_readableByKeePassXCputs an unknown element carrying aProtected="True"value at every level ofkpxc-rich, saves, and checks thatkeepassxc-cli ls -Randshow -sstill work and decrypt the Unicode entry's password.2b. Stable mixed content (
fix: keep unknown elements stable across repeated saves)An unknown element that mixes text and child elements gained the writer's indentation on every save. When reading such an element, its text children are now trimmed and whitespace-only ones dropped, so read → write → read is stable; text-only elements are kept byte for byte.
UnknownElementStabilityTestssaves and re-reads one three times.3. Compiler-crash workaround (
test: avoid a Swift 6.3 compiler crash in StaticReaderAPITests)Swift 6.3.3 aborts compiling
StaticReaderAPITests.swift(SIL ownership verifier, "Found ownership error?!", signal 6). The trigger iscatch let error as KDBXReader.Erroraround a typed-throwsKDBXReader.parse. The cast is redundant, so the commit uses a plaincatch. Behaviour is unchanged. Drop this commit if you'd rather not carry it.Testing
swift buildandswift test. 479 tests in 75 suites passed. Baselinedevelopwith only the crash workaround: 473 tests in 73 suites. This branch adds 2 + 3 + 1 tests, and theDotNetEpochTestsvalue test is parameterized over 3 cases.KeePassXCInteropTests.cliPathat/usr/bin/keepassxc-cli. That change is not committed.swiftformat --lint(0.53.10, the Mintfile version): 0 of the 15 Swift files touched need formatting. Ondevelop,KDFProfileCompatTests.swiftalready fails lint; this PR doesn't touch it.Generated by Claude Code