Live data from Hacker News

How to corrupt an SQLite database file

sqlite.org

11–20 of 45 posts

Re: How to corrupt an SQLite database file

#11
> Multiple copies of SQLite linked into the same application

I had recent SQLite corruption, and I suspect it was this - I was accessing an SQLite database from the same python process using both the builtin sqlite3 package, and also the third party apsw library

Re: How to corrupt an SQLite database file

#16

Interesting that it doesn't specifically call out Anti-Virus scanning (which does occasionally result in at least one of these scenarios). I've seen many SQLite database become corrupted and the best you can do is have a backup.

if processes lock the file shouldn't AV refrain from reading or even writing it?

Re: How to corrupt an SQLite database file

#18
post #16

Interesting that it doesn't specifically call out Anti-Virus scanning (which does occasionally result in at least one of these scenarios). I've seen many SQLite database become corrupted and the best you can do is have a backup.

if processes lock the file shouldn't AV refrain from reading or even writing it?

Nope, AV hooks into the filesystem layer (the NT kernel has 'filesystem filters' for this) and intercepts all reads and writes on the system.

Re: How to corrupt an SQLite database file

#19

Interesting that it doesn't specifically call out Anti-Virus scanning (which does occasionally result in at least one of these scenarios). I've seen many SQLite database become corrupted and the best you can do is have a backup.

I had one machine on my entire client's network that could never download a LibreOffice document without it being corrupted.

Turns out it was kaspersky intercepting network calls, and deciding it was a very dangerous piece of file, and it would truncate it completely silently.

After wasting a non-billable afternoon on it, I just disabled the antivirus out of desperation and figured it out.

The solution was to generate a self signed certificate and TLS the connection and prevent the bugger to MITM us.

Since this day, even on a local network with behind a proxies and using a VPN, I still use https for all the services if I'm allowed.

Re: How to corrupt an SQLite database file

#20
> One example of this occurred circa 2013-08-30 on the canonical repository for the Fossil DVCS. In that event, file descriptor 2 (standard error) was being erroneously closed (by stunnel, we suspect) prior to sqlite3_open_v2() so that the file descriptor used for the repository database file was 2. Later, an application bug caused an assert() statement to emit an error message by invoking write(2,...). But since file descriptor 2 was now connected to a database file, the error message overwrote part of the database.

Kind of crazy that this is an issue in modern operating systems. There are just so many ways to avoid this obvious footgun of an API design. stdin/out/err should be reserved file descriptors. In fact, why reuse file descriptors at all? Just count up.

Post reply on HN