SQLite

View Ticket
Login
Ticket Hash: 38a97a87a6e4e83eb1c60205441d840905374c93
Title: Inaccurate int/float comparison results in corrupt index
Status: Fixed Type: Code_Defect
Severity: Important Priority: Immediate
Subsystem: Unknown Resolution: Fixed
Last Modified: 2015-11-13 17:39:28
Version Found In: 3.9.2
User Comments:
drh added on 2015-11-06 00:36:24:

Imprecision in the comparison of integer and floating-point values can result in a corrupt index. The following SQL demonstrates:

CREATE TABLE t1(a INTEGER PRIMARY KEY, b);
CREATE INDEX t1b ON t1(b);
INSERT INTO t1(a,b) VALUES(3, 356282677878746339);
INSERT INTO t1(a,b) VALUES(2, 356282677878746339.0);
INSERT INTO t1(a,b) VALUES(1, 356282677878746340);
DELETE FROM t1 WHERE a=2;
PRAGMA integrity_check;

The integrity_check reports a row missing from the index. Examination of the binary for the resulting databases shows that the index has two rows but that the rows are out-of-order.

The above is true when compiling with gcc on linux. But using MSVC on Windows, the script works correctly.

This bug has existed in the code since before version 3.5.1 (circa 2007).