Closed mannol closed 7 years ago
I thought about adding per-page checksum to fail gracefully when the file is corrupted, but I never implemented it. In this case, the number of elements to read is part of the file, and the code assume it is correct, so if the file is corrupted then it will fail as stated.
Without a checksum, it is too cumbersome to validate each value. Adding checksum is possible, but I don't think I'll do that in the short term.
So how would I know if the file is corrupt and is it possible to handle that case?
I'm sorry I cannot provide a good answer. The attached file looks corrupt as I cannot find any sha1 in it.
Is it possible to deal with this heap overflow so it at least doesn't crash?
EDIT: I just checked, running any command causes the same issue. So, if it didn't crash but rather failed gracefully, I could run a basic command and know if the database is still valid. In example:
rliteCommand(db, "SET x y"); // would return NULL
The main key tree looks broken, so any command that uses a key will fail this way. I cannot figure out how to fail gracefully in this situation without checksums.
I'm sorry, I'm not very familiar with rlite internals and such, is there a way to know if the main key tree is broken?
EDIT: Basically, It's a real-life scenario where database files might get corrupted. It's a deal-breaker if the whole process crashes in this case. Are you saying there is no way this can be detected in any way?
There is no way to know if the file is corrupted, no.
A process crash should not corrupt the file as before writing any change it is written in a separated wal file and then into the main file. If the process crashes before fully writing the wal file, the transaction is aborted; if the process crashes after writing the wal file, the transaction is recovered from the wal file.
I understand this is a deal-breaker.
Oh, okay. So, basically, a process crash is no reason the file would be corrupted, no? In that case it's fine. Thank you for your time.
In short: my app crashed once on unrelated place, don't know what happened with the database file, but ever since then It crashes while reading a certain key.
Steps to reproduce:
1) Use the attached file (uncompressed :) dynamic.db.zip
2) Use the following code:
The ASAN output: