Closed ClementNerma closed 1 month ago
Ya, I considered that, but decided it was unnecessary. If you need to check
that the database is valid, you should call check_integrity()
Sent from my phone
On Sun, Oct 6, 2024, 5:11 AM Clément Nerma @.***> wrote:
Hi there!
I've encountered a problem while using redb: when reading e.g. a String value from a table, if it's not valid UTF-8 (because of e.g. db corruption), the program crashes instead of returning an error. This seems caused by the following:
image.png (view on web) https://github.com/user-attachments/assets/4a35fa62-42ba-4424-995e-7a6fc82314cf
Values (and keys) decoding is typed as infallible, meaning whenever an invalid value is encountered, redb panics. This is problematic, and makes me wonder if the API shouldn't instead allow this method to return a Result<Self::SelfType, DecodingError> or something like this?
I know this would be a breaking change but getting a panic is not a good thing in such scenario
— Reply to this email directly, view it on GitHub https://github.com/cberner/redb/issues/874, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAGNXQDNH66QGKMHG6MFXPDZ2ESILAVCNFSM6AAAAABPOIRXNSVHI2DSMVQWIX3LMV43ASLTON2WKOZSGU3DQNRSHA3TSMI . You are receiving this because you are subscribed to this thread.Message ID: @.***>
Oh check_integrity
also ensures that all tables' keys and values can be decoded according to the provided types?
If so that indeed solves the problem :)
Thanks!
Technically, it ensures that the xxh3 hash of the encoded keys and values are the same. So if you're worried about malicious inputs, you may want your own cryptographic checks on top. But yes, for ordinary corruption it should be sufficient
Oh then it's not what I thought, I'm more worried about e.g. a structure I'm putting into the database changing, resulting in a panic when I read the value from the database.
Ah. Ya, you shouldn't need to worry much about that. redb guarantees that the value you decode is the same one that you encoded, even if your OS crashes, as long as the storage media respects these assumptions: https://github.com/cberner/redb/blob/master/docs/design.md#assumptions-about-underlying-media
The tl;dr being that you won't hit a panic like that, unless you corrupt the database file with an external program, or your hard disk fails.
Hi there!
I've encountered a problem while using
redb
: when reading e.g. aString
value from a table, if it's not valid UTF-8 (because of e.g. db corruption), the program crashes instead of returning an error. This seems caused by the following:Values (and keys) decoding is typed as infallible, meaning whenever an invalid value is encountered,
redb
panics. This is problematic, and makes me wonder if the API shouldn't instead allow this method to return aResult<Self::SelfType, DecodingError>
or something like this?I know this would be a breaking change but getting a panic is not a good thing in such scenario