From e7e1b49c065888a3c9cfff2eb24bc2b436fe89bb Mon Sep 17 00:00:00 2001 From: Walter Tan de Jesus Date: Fri, 7 Jun 2024 11:12:05 +0800 Subject: [PATCH 1/3] Avoid using AesStream class when opening an older version of LiteDB database --- .../Disk/StreamFactory/FileStreamFactory.cs | 6 ++++-- LiteDB/Engine/EngineSettings.cs | 4 ++-- LiteDB/Engine/FileReader/FileReaderV7.cs | 4 ++-- LiteDB/Engine/Services/RebuildService.cs | 21 ++++++++++++------- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/LiteDB/Engine/Disk/StreamFactory/FileStreamFactory.cs b/LiteDB/Engine/Disk/StreamFactory/FileStreamFactory.cs index 59b8f5064..5b6b288aa 100644 --- a/LiteDB/Engine/Disk/StreamFactory/FileStreamFactory.cs +++ b/LiteDB/Engine/Disk/StreamFactory/FileStreamFactory.cs @@ -17,13 +17,15 @@ internal class FileStreamFactory : IStreamFactory private readonly string _password; private readonly bool _readonly; private readonly bool _hidden; + private readonly bool _useAesStream; - public FileStreamFactory(string filename, string password, bool readOnly, bool hidden) + public FileStreamFactory(string filename, string password, bool readOnly, bool hidden, bool useAesStream = true) { _filename = filename; _password = password; _readonly = readOnly; _hidden = hidden; + _useAesStream = useAesStream; } /// @@ -57,7 +59,7 @@ public Stream GetStream(bool canWrite, bool sequencial) File.SetAttributes(_filename, FileAttributes.Hidden); } - return _password == null ? (Stream)stream : new AesStream(_password, stream); + return _password == null || !_useAesStream ? (Stream)stream : new AesStream(_password, stream); } /// diff --git a/LiteDB/Engine/EngineSettings.cs b/LiteDB/Engine/EngineSettings.cs index d2bb96372..dea2cd7bb 100644 --- a/LiteDB/Engine/EngineSettings.cs +++ b/LiteDB/Engine/EngineSettings.cs @@ -69,7 +69,7 @@ public class EngineSettings /// /// Create new IStreamFactory for datafile /// - internal IStreamFactory CreateDataFactory() + internal IStreamFactory CreateDataFactory(bool useAesStream = true) { if (this.DataStream != null) { @@ -85,7 +85,7 @@ internal IStreamFactory CreateDataFactory() } else if (!string.IsNullOrEmpty(this.Filename)) { - return new FileStreamFactory(this.Filename, this.Password, this.ReadOnly, false); + return new FileStreamFactory(this.Filename, this.Password, this.ReadOnly, false, useAesStream); } throw new ArgumentException("EngineSettings must have Filename or DataStream as data source"); diff --git a/LiteDB/Engine/FileReader/FileReaderV7.cs b/LiteDB/Engine/FileReader/FileReaderV7.cs index 2369e9813..ec10ddbfa 100644 --- a/LiteDB/Engine/FileReader/FileReaderV7.cs +++ b/LiteDB/Engine/FileReader/FileReaderV7.cs @@ -42,7 +42,7 @@ public FileReaderV7(EngineSettings settings) public void Open() { - var streamFactory = _settings.CreateDataFactory(); + var streamFactory = _settings.CreateDataFactory(false); // open datafile from stream factory _stream = streamFactory.GetStream(true, true); @@ -437,7 +437,7 @@ protected virtual void Dispose(bool disposing) { if (disposing) { - _stream.Dispose(); + _stream?.Dispose(); _aes?.Dispose(); } diff --git a/LiteDB/Engine/Services/RebuildService.cs b/LiteDB/Engine/Services/RebuildService.cs index 74ebb7806..9f415b2ab 100644 --- a/LiteDB/Engine/Services/RebuildService.cs +++ b/LiteDB/Engine/Services/RebuildService.cs @@ -22,14 +22,19 @@ public RebuildService(EngineSettings settings) { _settings = settings; - // open, read first 16kb, and close data file - var buffer = this.ReadFirstBytes(); + // test for prior version + var bufferV7 = this.ReadFirstBytes(false); + if (FileReaderV7.IsVersion(bufferV7)) + { + _fileVersion = 7; + return; + } - // test for valid reader to use - _fileVersion = - FileReaderV7.IsVersion(buffer) ? 7 : - FileReaderV8.IsVersion(buffer) ? 8 : throw LiteException.InvalidDatabase(); + // open, read first 16kb, and close data file + var buffer = this.ReadFirstBytes(); + // test for valid reader to use + _fileVersion = FileReaderV8.IsVersion(buffer) ? 8 : throw LiteException.InvalidDatabase(); } public long Rebuild(RebuildOptions options) @@ -109,10 +114,10 @@ public long Rebuild(RebuildOptions options) /// /// Read first 16kb (2 PAGES) in bytes /// - private byte[] ReadFirstBytes() + private byte[] ReadFirstBytes(bool useAesStream = true) { var buffer = new byte[PAGE_SIZE * 2]; - var factory = _settings.CreateDataFactory(); + var factory = _settings.CreateDataFactory(useAesStream); using (var stream = factory.GetStream(false, true)) { From 48565c3e82e47abad51a1a4c6f9111bbe743fd85 Mon Sep 17 00:00:00 2001 From: Jonas Kamsker <11245306+JKamsker@users.noreply.github.com> Date: Sat, 8 Jun 2024 00:16:38 +0200 Subject: [PATCH 2/3] Add tests to validate that encrypted dbs migrate --- LiteDB.Tests/Issues/Issue2494_Tests.cs | 50 ++++++++++++++++++ .../Resources/Issue_2494_EncryptedV4.db | Bin 0 -> 20480 bytes 2 files changed, 50 insertions(+) create mode 100644 LiteDB.Tests/Issues/Issue2494_Tests.cs create mode 100644 LiteDB.Tests/Resources/Issue_2494_EncryptedV4.db diff --git a/LiteDB.Tests/Issues/Issue2494_Tests.cs b/LiteDB.Tests/Issues/Issue2494_Tests.cs new file mode 100644 index 000000000..e57917497 --- /dev/null +++ b/LiteDB.Tests/Issues/Issue2494_Tests.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +using Xunit; + +namespace LiteDB.Tests.Issues; + +public class Issue2494_Tests +{ + [Fact] + public static void Test() + { + var original = "../../../Resources/Issue_2494_EncryptedV4.db"; + using var filename = new TempFile(original); + + var connectionString = new ConnectionString(filename) + { + Password = "pass123", + Upgrade = true, + }; + + using (var db = new LiteDatabase(connectionString)) // <= throws as of version 5.0.18 + { + var col = db.GetCollection(); + col.FindAll(); + } + } + + public class PlayerDto + { + [BsonId] + public Guid Id { get; set; } + + public string Name { get; set; } + + public PlayerDto(Guid id, string name) + { + Id = id; + Name = name; + } + + public PlayerDto() + { + } + } +} \ No newline at end of file diff --git a/LiteDB.Tests/Resources/Issue_2494_EncryptedV4.db b/LiteDB.Tests/Resources/Issue_2494_EncryptedV4.db new file mode 100644 index 0000000000000000000000000000000000000000..780d6e22f23d1a51e0f7cfaba405afa0916ee157 GIT binary patch literal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X3wwbihFp-8JWA0a49uf>R8-a^T!N6!M=Ui5UUPUov2 zN1WOv04&_f6m&4z&Krt3ID4K9zy%fD?pt&F&nKMfH!2SDLj@OO(3$bl@&=?|{#T=p zF|t=?e!js*Q~crJ@{+FMLQHP9<9#u%CPe6Q(5%(jT8u!EEu2rzU*qyjA*L;N?1(pn$w6o(r4C{%C`0FE7xr<1!G&bhGylKKSEk2{ zK!zWtGFw#b*DX2`&6D56QJ3(^oQ4uN>>Gu94 z#z%%MOMNfTv1u^BTC$R3H@-$ckmQJ=KDQ|uZ)DXyGtsio?mYryOe7mKk2v%+0#d^+ z1sbyrL?f-9r@t{U$jAgZv(jMN|7iJvf_92Z`3C zFuJ!mQYeNG>QZTqZ;MVqM}3|w`UV!iXTlsyMzOO7?{5D5{%DTw9wA?+jus( z(AZk3qFh8s7D|Ig9FsWexXt-_QBf$$1 zjyZj1Lb{6>JZ5?gBl+zR!pCW+b);BaOHC2q8}El$0|f^Cqo6+->Xu%WcNF)t`IgYN zHKUr(OA-|e!u!H&JPiI|!Rb&_$~Ku=KYT&%mVDBqLLp_K|lCR$Le0kkye>eLRWU5_a_2*`dLsAqn*Q_~%U-v`yb~JX*pcw0X&(p3|F)+CM-AN$oNM&j8R{KV%;A`%~4s s_?mN0Nez-4Nof5h&F%^)^bRc>8ZBu6JYs Date: Mon, 10 Jun 2024 10:22:01 +0800 Subject: [PATCH 3/3] Tabs to spaces on affected files --- .../Engine/Disk/StreamFactory/FileStreamFactory.cs | 4 ++-- LiteDB/Engine/Services/RebuildService.cs | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/LiteDB/Engine/Disk/StreamFactory/FileStreamFactory.cs b/LiteDB/Engine/Disk/StreamFactory/FileStreamFactory.cs index 5b6b288aa..cc3e95bb4 100644 --- a/LiteDB/Engine/Disk/StreamFactory/FileStreamFactory.cs +++ b/LiteDB/Engine/Disk/StreamFactory/FileStreamFactory.cs @@ -17,9 +17,9 @@ internal class FileStreamFactory : IStreamFactory private readonly string _password; private readonly bool _readonly; private readonly bool _hidden; - private readonly bool _useAesStream; + private readonly bool _useAesStream; - public FileStreamFactory(string filename, string password, bool readOnly, bool hidden, bool useAesStream = true) + public FileStreamFactory(string filename, string password, bool readOnly, bool hidden, bool useAesStream = true) { _filename = filename; _password = password; diff --git a/LiteDB/Engine/Services/RebuildService.cs b/LiteDB/Engine/Services/RebuildService.cs index 9f415b2ab..b4eaa155e 100644 --- a/LiteDB/Engine/Services/RebuildService.cs +++ b/LiteDB/Engine/Services/RebuildService.cs @@ -22,19 +22,19 @@ public RebuildService(EngineSettings settings) { _settings = settings; - // test for prior version - var bufferV7 = this.ReadFirstBytes(false); - if (FileReaderV7.IsVersion(bufferV7)) + // test for prior version + var bufferV7 = this.ReadFirstBytes(false); + if (FileReaderV7.IsVersion(bufferV7)) { _fileVersion = 7; return; } - // open, read first 16kb, and close data file - var buffer = this.ReadFirstBytes(); + // open, read first 16kb, and close data file + var buffer = this.ReadFirstBytes(); - // test for valid reader to use - _fileVersion = FileReaderV8.IsVersion(buffer) ? 8 : throw LiteException.InvalidDatabase(); + // test for valid reader to use + _fileVersion = FileReaderV8.IsVersion(buffer) ? 8 : throw LiteException.InvalidDatabase(); } public long Rebuild(RebuildOptions options)