SQLite Forum

Usable size bugs in dbdata.c and showdb.c
Login

Usable size bugs in dbdata.c and showdb.c

(1.1) By hardisk0 on 2021-04-03 16:14:49 edited from 1.0 [source]

#Dear Mr. D. Richard Hipp and developers, We found some bugs in dbdata.c and showdb.c, we create a new db and set 48 reserved bytes as follow:

sqlite> .filectrl reserve_bytes 48
48
sqlite> create table test(id INTEGER PRIMARY KEY, data TEXT);
sqlite> insert into test values(100, hex(zeroblob(2028)));
sqlite> .recover
PRAGMA foreign_keys=OFF;
BEGIN;
PRAGMA writable_schema = on;
CREATE TABLE IF NOT EXISTS  test(id INTEGER PRIMARY KEY, data TEXT);
PRAGMA writable_schema = off;
COMMIT;
sqlite>
We can see that the data lost, same probleam in showdb.c with this db file:
C:\zhd\sqlite-tools-win32-x86-3350400>showdb.exe a48.db ptrmap
Pagesize: 4096
Available pages: 1..4
    1: root of sqlite_schema
    2: PTRMAP page covering 3..811
    3: b-tree root page, parent=0
    4: first page of overflow, parent=3
We can see that page 4 is the overflow page belong to page 3, but when we show page 3, it says that all data in it, no overflow page:
C:\zhd\sqlite-tools-win32-x86-3350400>showdb.exe a48.db 3bc
Pagesize: 4096
Available pages: 1..4
Header on btree page 3:
 000: 0d                    13  table leaf
 001: 00 00                  0  Offset to first freeblock
 003: 00 01                  1  Number of cells on this page
 005: 0d e6               3558  Offset to cell content area
 007: 00                     0  Fragmented byte count
 key: lx=left-child n=payload-size r=rowid
 de6: cell[0] n: 4060 r: 100 *,txt(4056)

#We found that in dbdata.c and showdb.c, page size was used as usable size directly when parse the cell data.

#Thank you!