realm-swift: Realm decryption failed - repeatable failure on compacted realms
How frequently does the bug occur?
Always
Description
I am trying to open a compacted and encrypted Realm in Swift-Realm, but I receive an error. The file has been created using the Android-Realm SDK (io.realm:realm-gradle-plugin:10.13.0). The file can be properly opened in Realm Studio 12.0 or with Android-Realm. I tried using uncompacted realms (still encrypted) instead and they work properly. The compacted ones do not. Using a slightly different schema does not lead to the issue, so I can only make wild assumptions for having a very weird edge-case or something?
For me, that’s a big deal, because my users can switch platforms/devices via backup and the realm files are exchanged compacted to save storage and bandwidth. Now, I have to roll out a patch to all platforms and devices to only share them non-compacted to avoid broken/unusable databases.
I can provide the file and password, but not in public.
Stacktrace & log output
NSLocalizedDescription=Unable to open a realm at path '/....': Realm file decryption failed Path:Exception backtrace:
0 Realm 0x000000010633c044 _ZN5realm15InvalidDatabaseC2ERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEES9_ + 60
1 Realm 0x00000001062e7110 _ZN5realm9SlabAlloc11attach_fileERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEERNS0_6ConfigE + 3256
2 Realm 0x000000010631e9bc _ZN5realm2DB4openERKNSt3__112basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEEbRKNS_9DBOptionsE + 1640
3 Realm 0x0000000106325b20 _ZN5realm2DB6createENSt3__110unique_ptrINS_11ReplicationENS1_14default_deleteIS3_EEEERKNS1_12basic_stringIcNS1_11char_traitsIcEENS1_9allocatorIcEEEERKNS_9DBOptionsE + 164
4 Realm 0x00000001065515ac _ZN5realm5_impl16RealmCoordinator7open_dbEv + 1016
5 Realm 0x0000000106552238 _ZN5realm5_impl16RealmCoordinator12do_get_realmENS_11RealmConfigERNSt3__110shared_ptrINS_5RealmEEENS3_8optionalINS_9VersionIDEEERNS_4util17CheckedUniqueLockE + 72
6 Realm 0x00000001065520bc _ZN5realm5_impl16RealmCoordinator9get_realmENS_11RealmConfigENSt3__18optionalINS_9VersionIDEEE + 372
7 Realm 0x00000001065dfa60 _ZN5realm5Realm16get_shared_realmENS_11RealmConfigE + 120
8 Realm 0x000000010624a5a8 +[RLMRealm realmWithConfiguration:queue:error:] + 728
9 RealmSwift 0x00000001051b6688 $sSo8RLMRealmC13configuration5queueABSo0A13ConfigurationC_So012OS_dispatch_C0CSgtKcfCTO + 128
10 RealmSwift 0x000000010525b6a0 $s10RealmSwift0A0V5queueACSo012OS_dispatch_C0CSg_tKcfC + 116
11 brushrage 0x00000001025e4d28 $s9brushrage7StorageC6getAll_5query6paramsSay5ModelQzGAA11DataWrapperCyxG_AA5QueryCSgSaySSGSgtSo16RealmSwiftObjectCRbzAA02DbG0RzlFZ + 380
12 brushrage 0x00000001023ab7fc $s9brushrage7LibraryC14loadCategories33_F15A9C9A19EBB745E05E9F5C484B9774LLSDySiAA11ProductInfoCGyFZ + 140
13 brushrage 0x00000001023a9f28 $s9brushrage7LibraryC10categoriesSDySiAA11ProductInfoCGvgZ + 1172
14 brushrage 0x0000000102127930 $s9brushrage22TrackingViewControllerC10reloadData33_B717444B32E4031AA48693EEE6BC3E5DLLyyFyycfU5_ + 56
15 brushrage 0x000000010212102c $sIeg_ytytIegnr_TR + 20
16 Async 0x0000000103527250 $s5Async0A5BlockV5chain33_E687294E1917D2F98ED787A27C7576C6LL5after5block5queueACyq_qd__GSdSg_qd__q_cAA3GCDAELLOtlFyycfU_ + 632
17 Async 0x0000000103525fe4 $sIeg_IeyB_TR + 48
18 libdispatch.dylib 0x0000000104e7329c _dispatch_block_async_invoke2 + 104
19 libdispatch.dylib 0x0000000104e61d5c _dispatch_client_callout + 16
20 libdispatch.dylib 0x0000000104e76ae8 _dispatch_root_queue_drain + 1012
21 libdispatch.dylib 0x0000000104e7753c _dispatch_worker_thread2 + 248
22 libsystem_pthread.dylib 0x00000001b0598b04 _pthread_wqthread + 224
23 libsystem_pthread.dylib 0x00000001b0597904 start_wqthread + 8.}
Can you reproduce the bug?
Always
Reproduction Steps
Compact my schema with a given password on Android. Try to open the file in Realm-Swift.
Version
10.33.0 - 10.34.1
What Atlas Services are you using?
Local Database only
Are you using encryption?
Yes
Platform OS and version(s)
iOS 16.2 and MacOS 12.6
Build environment
ProductName: macOS
ProductVersion: 12.6
BuildVersion: 21G115
/Applications/Xcode.app/Contents/Developer
Xcode 14.2
Build version 14C18
/opt/homebrew/bin/pod
1.11.3
Realm (10.34.1)
RealmSwift (10.34.1)
RealmSwift (= 10.34.1)
/bin/bash
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin21)
(not in use here)
/usr/local/bin/git
git version 2.26.0
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 21
@finnschiermer we don’t postpone the opening of the realm. We open the realm when the user calls
try Realm().@finnschiermer According to me stepping through the code, the problem was caused in the line I wrote above. Now when re-checking, it’s at the try Realm() line again. That’s odd. Or maybe I’m just tired after work, dunno.
Edit: Oh yes, it was me being sloppy. The write-transaction doesn’t help at all, because the exception comes first. It was just me using the wrong file which “made it work” in write-transactions.
@finnschiermer No, I’m trying to open them in just the regular read/write mode and typically, I also want to write to them.
Yes, the files confirms our suspicion of what is wrong. I’ll be validating a fix.