Skip to content

cipher_integrity_check reports HMAC failures on pages a VFS preallocated #634

Open

Description

@LucaCappelletti94

Expected Behavior

PRAGMA cipher_integrity_check returns no rows for an intact database, whatever chunk size or preallocation the VFS applies.

Actual Behavior

With SQLITE_FCNTL_CHUNK_SIZE set, the unix VFS rounds the file up to the chunk, and cipher_integrity_check reports every zero block past the end of the database as HMAC verification failed. The loop in sqlcipher_codec_ctx_integrity_check runs up to sqlite3OsFileSize, so it checks blocks that were never database pages. The browser opfs-sahpool VFS does the same on every SQLITE_FCNTL_SIZE_HINT.

Steps to Reproduce

On Linux with gcc, make, tcl and the OpenSSL headers installed:

git clone --depth 1 https://github.com/sqlcipher/sqlcipher && cd sqlcipher
./configure --with-tempstore=yes CFLAGS="-DSQLITE_HAS_CODEC -DSQLITE_EXTRA_INIT=sqlcipher_extra_init -DSQLITE_EXTRA_SHUTDOWN=sqlcipher_extra_shutdown" LDFLAGS="-lcrypto"
make sqlite3
rm -f ic.db
printf "PRAGMA key='test';\n.filectrl chunk_size 65536\nCREATE TABLE t(a); INSERT INTO t VALUES(1);\n" | ./sqlite3 ic.db
wc -c < ic.db
./sqlite3 ic.db "PRAGMA key='test';" "PRAGMA page_count;" "PRAGMA integrity_check;" "PRAGMA cipher_integrity_check;" "PRAGMA cipher_version;"

Output:

ok
65536
ok
2
ok
HMAC verification failed for page 3
HMAC verification failed for page 4
HMAC verification failed for page 5
HMAC verification failed for page 6
HMAC verification failed for page 7
HMAC verification failed for page 8
HMAC verification failed for page 9
HMAC verification failed for page 10
HMAC verification failed for page 11
HMAC verification failed for page 12
HMAC verification failed for page 13
HMAC verification failed for page 14
HMAC verification failed for page 15
HMAC verification failed for page 16
4.20.0 community

The file is 65536 bytes, the database has 2 pages and PRAGMA integrity_check passes, yet pages 3 to 16 fail. The same loop is on beta.

SQLCipher version: 4.20.0 community (master 355d4db, SQLite 3.54.1)

Activity

  1. sjlombardo commented on Nov 10, 2026

    @sjlombardo
    Member

    @LucaCappelletti94 thanks for the report, investigating.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions