mbdavid / LiteDB

LiteDB - A .NET NoSQL Document Store in a single data file
http://www.litedb.org
MIT License
8.35k stars 1.22k forks source link

[QUESTION] LiteDB Opens Non-Database Files and Throws Exception on Large Invalid Content #2501

Open PanWuming opened 2 weeks ago

PanWuming commented 2 weeks ago

Description

LiteDB can open non-database files as if they were database files. When the content of a text file is just "Invalid content," LiteDB will open it as a normal database file and write data to it. However, if the "Invalid content" is repeated many times, making the file size reach 16K, LiteDB will throw an unhandled exception when writing data.

Steps to Reproduce

  1. Create a text file with the content "Invalid content."
  2. Attempt to open the file with LiteDB and write data to it. Notice that LiteDB treats it as a valid database file.
  3. Modify the text file by repeating "Invalid content" until the file size reaches 16K.
  4. Attempt to write data to the file using LiteDB. An unhandled exception will be thrown.

Expected Behavior

LiteDB should not treat non-database files as valid database files. It should properly validate the file content and structure before opening and writing data. If the file content is invalid, LiteDB should throw an appropriate exception indicating the issue.

Environment

JKamsker commented 2 weeks ago

Could you please write an unit test in a pr for that and reference it here?