hive icon indicating copy to clipboard operation
hive copied to clipboard

Exception when opening encrypted box after re-initialising Hive

Open MichaelM97 opened this issue 3 years ago • 6 comments

Steps to Reproduce I updated Hive from version 2.0.0 -> 2.0.4, I performed logic which re-initialises Hive (using Hive.initFlutter) with a new subDir, I then got the following exception when attempting to open an encrypted box:

7.3.0 - [Firebase/Firestore][I-FST000001] WatchStream (2839f3918) Stream error: 'Not found: Target id not found: 64'
flutter: Recovering corrupted box.
[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: HiveError: This should not happen. Please open an issue on GitHub.
#0      BinaryReaderImpl.readFrame (package:hive/src/binary/binary_reader_impl.dart:250:7)
#1      FrameHelper.framesFromBytes (package:hive/src/binary/frame_helper.dart:21:26)
#2      FrameIoHelper.framesFromFile (package:hive/src/io/frame_io_helper.dart:42:12)
<asynchronous suspension>
#3      StorageBackendVm.initialize (package:hive/src/backend/vm/storage_backend_vm.dart:86:11)
<asynchronous suspension>
#4      HiveImpl._openBox (package:hive/src/hive_impl.dart:116:9)
<asynchronous suspension>
#5      HiveImpl.openBox (package:hive/src/hive_impl.dart:145:12)
<asynchronous suspension>
#6      loadSearchResultsFromStorage.<anonymous closure> (package:hunni/middleware/file_middleware.dart:157:30)
<asynchronous suspension>

Now whenever I open my app, when attempting to open an encrypted box I get the following exception:

[VERBOSE-2:ui_dart_state.cc(186)] Unhandled Exception: HiveError: This should not happen. Please open an issue on GitHub.
#0      BinaryReaderImpl.readFrame (package:hive/src/binary/binary_reader_impl.dart:250:7)
#1      FrameHelper.framesFromBytes (package:hive/src/binary/frame_helper.dart:21:26)
#2      FrameIoHelper.framesFromFile (package:hive/src/io/frame_io_helper.dart:42:12)
<asynchronous suspension>
#3      StorageBackendVm.initialize (package:hive/src/backend/vm/storage_backend_vm.dart:86:11)
<asynchronous suspension>
#4      HiveImpl._openBox (package:hive/src/hive_impl.dart:116:9)
<asynchronous suspension>
#5      HiveImpl.openBox (package:hive/src/hive_impl.dart:145:12)
<asynchronous suspension>

Code sample

Provide a few simple lines of code to show your problem.

Version

  • Platform: iOS
  • Flutter version: 2.0.3
  • Hive version: 2.0.4

MichaelM97 avatar May 04 '21 22:05 MichaelM97

@MichaelM97 I have the same problem. Any news?

alexeenko-frontend avatar Jul 23 '21 10:07 alexeenko-frontend

same problem

BurykinNikolay avatar Aug 07 '21 19:08 BurykinNikolay

Same problem with hive "2.0.5"

salihagic avatar Jan 20 '22 14:01 salihagic

Facing the same Issue.

hive: ^2.2.1 hive_flutter: ^1.1.0 hive_generator: ^1.1.3 image

getting this error 'Recovering corrupted box' upon **re-initialising on next run, mentioning the steps what I got on my side. It might help to figure out exact issue.

steps to reproduce :

  1. uninstall the app with hive if its installed earlier
  2. install app and make sure Hive.initFlutter() and register addapter runs and you also saved some data after that. During this session I also confirmed, the saved data I was able to read it back without any issue.
  3. close app by back press OR by doing swipe to make force close. Problem starts from here.
  4. start app again you won't find the saved data in hive in very first run after installing app same time you will see the error Recovering corrupted box in console
  5. this time you save have to save the data again into hive, data saved during this session can be retrieved successfully on all future app runs.

any news when it will get fixed please?

yakubmoris avatar Feb 01 '23 07:02 yakubmoris

@yakubmoris Could you perhaps provide a MWE for your reproduction? Could not reproduce it both in a complex app and a small MWE. (I have encountered the "Recovering corrupted box" as well, with hive 2.1.0, hive_flutter 1.1.0, flutter 3.3.5, but the origins of the problem are totally unclear and not reproducible as of now.)

jakobleck avatar Feb 03 '23 10:02 jakobleck

@yakubmoris Currently running into the same situation. In my case, the code to generate and store an EncryptionKey (using FlutterSecureStorage) is running multiple times because I provided it to multiple boxes. => The last executed generateSecureKey() is overriding existing ones. My fix was to move the generateEncryptionKey method first, before providing Boxes. Hope this helps.

RootSoft avatar Sep 19 '23 22:09 RootSoft