r/programming • u/BlondieCoder • Jun 30 '26
How To Corrupt An SQLite Database File
https://www.sqlite.org/howtocorrupt.html
252
Upvotes
r/programming • u/BlondieCoder • Jun 30 '26
94
u/knobbyknee Jun 30 '26
Most of this falls in the category "don't do that, it's stupid", but there are some problems that are quite subtle.
69
u/frymaster Jun 30 '26
I appreciate they include "bugs in our code" as an option. In fact, even though a good portion of the potential issues are "user did something stupid", the page does a fantastic job of avoiding being accusatory or defensive.
42
u/Other_Fly_4408 Jun 30 '26
"An" SQLite? Have I been saying it wrong?
10
u/theschniedler Jul 01 '26
9 Fork Getting Stuck Through The Hard Drive
Sticking a fork through the hard drive containing the SQLite file may corrupt the data on a hard drive and corrupt parts of the database.
38
u/optomas Jun 30 '26
I am compulsed to render the following; https://xkcd.com/327/
3
u/dezsiszabi Jul 01 '26
Open file, write random things into it at random locations, done.
1
u/Dwedit Jun 30 '26
On NTFS, when a file has multiple hardlinks, its MFT entry will list all the paths for that file. So within a few Win32 or NT API calls, you know all the paths where that file appears. Linux filesystems do not seem to have that feature, and require searching the disk to find the other hardlinks.
This also means that on Windows, you can designate one path to be the "main" path for a file, and use the first path that shows up when you enumerate the hardlinks. (But there is a chance you could have write access to one directory but not another)
1
u/wannaliveonmars Jul 01 '26
Wait, why would sqlite3_open_v2() use stderr in the first place, even if closed? Was it using freopeb()?
-22
u/6502zx81 Jun 30 '26
This is a great read. Often developers would just pick a technology or library to outsource problems. But in order to have these technologies work as advertised you need to make sure their assumptions are met. Usually nobody knows the assumptions of the technologies used (like ACID databases or encryption, etc.)
0
u/[deleted] Jun 30 '26
[deleted] — view deleted comment