SQLite
Artifact Content
Not logged in

Artifact a6e343197ba40f3920400825c14d8cc84bb6dcdf:

Ticket change [a6e343197b] - New ticket [6bfb98dfc0] False report of database corruption on an INSERT. by drh 2013-03-27 02:54:09.
D 2013-03-27T02:54:09.263
J foundin 3.7.16
J icomment The\sfinal\sINSERT\sin\sthe\sscript\sbelow\sreports\sthat\sthe\sdatabase\r\nis\scorrupt\s(SQLITE_CORRUPT)\sand\saborts.\s\sSubsequent\sanalysis\sshows\r\nno\sdatabase\scorruption.\r\n\r\n<blockquote><verbatim>\r\nPRAGMA\spage_size=512;\r\nCREATE\sTABLE\st1(x\sINTEGER\sPRIMARY\sKEY,\sy);\r\nINSERT\sINTO\st1\sVALUES(1,randomblob(400));\r\nINSERT\sINTO\st1\sVALUES(2,randomblob(400));\r\nINSERT\sINTO\st1\sSELECT\sx+2,\srandomblob(400)\sFROM\st1;\r\nINSERT\sINTO\st1\sSELECT\sx+4,\srandomblob(400)\sFROM\st1;\r\nINSERT\sINTO\st1\sSELECT\sx+8,\srandomblob(400)\sFROM\st1;\r\nINSERT\sINTO\st1\sSELECT\sx+16,\srandomblob(400)\sFROM\st1;\r\nINSERT\sINTO\st1\sSELECT\sx+32,\srandomblob(400)\sFROM\st1;\r\nINSERT\sINTO\st1\sSELECT\sx+64,\srandomblob(400)\sFROM\st1\sWHERE\sx<10;\r\nCREATE\sTRIGGER\sr1\sAFTER\sINSERT\sON\st1\sWHEN\snew.x=74\sBEGIN\r\n\s\sDELETE\sFROM\st1;\r\n\s\sINSERT\sINTO\st1\sVALUES(75,\srandomblob(400));\r\n\s\sINSERT\sINTO\st1\sVALUES(76,\srandomblob(400));\r\nEND;\r\nINSERT\sINTO\st1\sVALUES(74,\srandomblob(400));\r\n</verbatim></blockquote>\r\n\r\nThe\sproblem\soccurs\sbecause\sthe\sINSERT\soperation\sleaves\sits\scursor\sopen,\sthough\r\nmarked\sCURSOR_INVALID,\swhile\sholding\sa\sreference\sto\sa\ssecond-level\spage\sof\sthe\r\nbtree.\s\sWhen\sthe\strigger\sfires\sit\sdeletes\scontent\sout\sfrom\sunder\sthis\scursor,\r\nwhich\sis\snormally\sOK\ssince\sthe\scursor\sis\sinvalid.\s\sHowever,\sduring\sthe\ssecond\r\nINSERT\sinside\sthe\strigger,\swhen\sa\spage\sis\sremoved\sfrom\sthe\sfreelist\sto\shold\r\nthe\snew\scontent,\sthat\spage\sis\schecked\sto\smake\ssure\sit\sis\sunreferenced.\s\sThis\r\ncheck\sfails\ssince\sthe\sinvalid\sINSERT\scursor\sis\sstill\sholding\sa\sreference\sto\r\nthe\spage.\s\sThat\sreference\smakes\sit\sappear\sas\sif\sthe\spage\swas\son\sthe\sfreelist\r\nand\sin\sa\sbtree\sat\sthe\ssame\stime\sand\sso\san\sSQLITE_CORRUPT\serror\sis\sthrown.\r\nHowever,\sthe\spage\sis\snot\sreally\son\sthe\sbtree\ssince\sthe\scursor\sthat\sis\s\r\nreferencing\sit\sis\smarked\sCURSOR_INVALID.\r\n\r\nThis\sproblem\shas\sexisting\sin\sthe\scode\ssince\slate\s2009.\s\sIt\sis\svery\sdifficult\r\nto\shit,\showever\s(which\shelps\sto\sexplain\swhy\sit\shas\sgone\sundetected\suntil\snow).\r\nThe\sproblem\sis\svery\ssensitive\sto\sthe\sspecific\sconstants\sused\sin\sthe\sscript\r\nshown\sabove.
J login drh
J mimetype text/x-fossil-wiki
J severity Severe
J status Open
J title False\sreport\sof\sdatabase\scorruption\son\san\sINSERT
J type Code_Defect
K 6bfb98dfc0c2fee464aa23707ba50be946b49f1c
U drh
Z 343d82e115e21b8e859dee79c6b9c9b7