Repository navigation
ADFA-6635: Add sqlite-brotli, Brotli functions for sqlite3 - #5
Merged
Merged
Conversation
sqlite-brotli is a SQLite loadable extension that adds encodeBrotli(data [, dictionary [, quality [, lgwin]]]) and decodeBrotli(data [, dictionary]), to maintain documentation.db, whose content is Brotli-compressed with a raw custom dictionary. It installs $PREFIX/lib/sqlite-brotli.so, loaded with `.load sqlite-brotli`, plus its README and acceptance tests. The dictionary is the raw (LZ77 prefix) kind that `brotli -D` and brotli4j's PreparedDictionary use, so data moves freely between the extension, the brotli tool and the app. Each connection caches the prepared encoder dictionary. Invalid arguments, corrupt or truncated input, trailing data and results over SQLITE_LIMIT_LENGTH are SQL errors. A Brotli stream has no checksum or dictionary id, so decoding with a wrong dictionary of the same length can return wrong bytes with no error: 21% of documentation.db rows do with another version's dictionary. ADFA-6635 acceptance criterion 5 was amended to match, and the README says so. termux-packages has no such package, so build.sh now copies our own packages from packages/<name>/ into termux-packages/packages/ on every run, applies the com.termux rename to them, removes copies whose source is gone, and stops if a name is also an upstream package or subpackage. It reads repo.json with jq, which is now required. Tests: all 73 pass on x86_64 Linux with SQLite 3.51.2, also under ASan and UBSan, including decoding all 23,094 Brotli rows of a documentation.db. NDK r29 cross-builds for aarch64 and arm export only the extension's init function. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Register encodeBrotli and decodeBrotli as SQLITE_INNOCUOUS. The sqlite3
shell turns trusted_schema off, so views, triggers, CHECK constraints
and generated columns could not use them ("unsafe use of
decodeBrotli()"). A new test covers this, and the previous build fails
it.
- Correct the comment that said SQLite's length limit stops a
decompression bomb before memory runs out: its 1 GB default can be more
than a phone allows one process. The README now says to lower it with
.limit length before decoding untrusted data.
- build.sh writes the .cotg-own-package marker before copying a package,
so a copy cut short no longer stops every later build with a false
"upstream already has this package" error.
- build.sh and the README say that a change to one of our packages needs
a higher version or revision: build-package.sh skips a package already
built at the same version, and publishing keeps the published file.
sqlite-brotli goes to 1.0.0-1 for these changes.
- The com.termux rename is one helper, update_package_name, for upstream
and for our packages. It handles any file name and leaves binary files
alone. For the pinned termux-packages it produces the same tree as
before.
- run-tests.sh quotes file paths for SQL, dot-commands and URIs, so paths
with quotes, spaces, %, # or ? work. The package installs it
executable.
- Add tests/hello.c, the hello-world extension that acceptance criterion
1 loads, with build instructions in the README.
Tests: all 74 pass on x86_64 Linux with SQLite 3.51.2, also under ASan
and UBSan, and with every path under a directory named a b'c%d#e?f. In a
scratch copy, build.sh produces the same termux-packages tree as before
and passes the copy checks (edits, a copy cut short, spaces and binary
files, name collisions, removal). Termux's linter passes the recipe.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Answers Hal Eisen's review of PR #5. build.sh: the untracked .cotg-own-package marker outlasts a forced checkout or reset --hard of a newer termux-packages. If that commit adds a package with our name, the old check took it for ours and replaced upstream's files, and the cleanup could delete the whole package. Now git decides: a package folder git tracks in termux-packages stops the build before either rm -rf. The marker still limits the cleanup to folders build.sh made. Git variables inherited from a caller (GIT_DIR, GIT_INDEX_FILE) are dropped, and the build stops if termux-packages is not a git checkout of its own or git cannot answer. sqlite-brotli: depend on brotli (>= 1.1.0), which added the dictionary functions the extension calls. Revision 2, so the new Depends line is published. Co-Authored-By: Claude Opus 5.5 <[email protected]>
hal-eisen-adfa
approved these changes
Nov 11, 2026
davidschachterADFA
added a commit
that referenced
this pull request
Nov 17, 2026
ADFA-7081: Bring sqlite-js to main (#6 merged into #5's branch after #5 merged) What the above gibberish says is that someone (I wonder who? Stop looking at me!) merged 6 into 5 AFTER 5 had already merged to main. You can drag a dead horse to water but he's not going to drink and likewise, 6 isn't going anywhere because it's been merged to a branch that was already dead, having been merged into main. 7 is 6 with some minor changes. 6 already had Daniel's approval, so I'm merging 7 to get 6's work into main. If you understand this, give yourself a gold star.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ADFA-6635
Adds
sqlite-brotli, a SQLite loadable extension for thesqlite3shell withencodeBrotli(data [, dictionary [, quality [, lgwin]]])anddecodeBrotli(data [, dictionary]), to maintaindocumentation.db. It installs$PREFIX/lib/sqlite-brotli.so(.load sqlite-brotli), a README and its acceptance tests.brotli -Dand brotli4j'sPreparedDictionaryuse, so data moves freely between the extension, thebrotlitool and the app. Each connection caches the prepared encoder dictionary.SQLITE_LIMIT_LENGTHare SQL errors.documentation.dbrows do with another version's dictionary. Acceptance criterion 5 was amended to match, and the README says so.termux-packageshas no such package, sobuild.shnow copiespackages/<name>/intotermux-packages/packages/on every run, applies the com.termux rename, removes copies whose source is gone, and stops if a name is also an upstream package or subpackage (git says which package folders are upstream). It readsrepo.jsonwithjq, which is now required. README: new "Our own packages" section.packages.sh: addssqlite-brotlitoCOTG_PACKAGES.Tested, first commit (
2191349, version 1.0.0):packages/sqlite-brotli/tests/run-tests.shpass on x86_64 Linux with SQLite 3.51.2, also under ASan and UBSan with leak checking. They include decoding all 23,094 Brotli rows of adocumentation.dband byte-identical output tobrotli -q 11 -w 24 -D.aarch64andarm, against headers and libraries from the publishedsqlite3.51.2 andbrotli1.2.0 packages: only the init function is exported, and there are nocom.termuxstrings.build.shcopying, in a scratch copy of the repo: fresh setup, edits picked up, name collisions (an upstream package, a subpackage, anx11-packagesname), the rename, and removal of a deleted package.documentation.dbrows:aarch64), with its installedsqlite3.51.2 andbrotli1.2.0, loading the extension by name (.load sqlite-brotli,LD_LIBRARY_PATHunset);adb shellwith the publishedaarch64andarm(32-bit)sqlite3andbrotli.These used the NDK cross-builds above, copied into place by hand.
aarch6412 min 33 s,arm15 min 11 s) and published them to the stage bucket: only the twosqlite-brotli.debfiles and the index were uploaded (681 packages, up from 679). Each package has the library, README and test script, depends onbrotli, links onlylibbrotlienc,libbrotlidecandlibc, exports only the init function, and has nocom.termuxstrings.aarch64andarmlibraries pass all 73 tests fromadb shellon the same phone.aarch64package installs withdpkg -i,dpkg --verifyis clean, and its installedrun-tests.shpasses all 73 tests, loading the extension by name.Second review, commit
cb7450a(version 1.0.0-1). An independent Claude review of the final diff raised 10 findings; 8 were confirmed, 1 was half right and 1 did not reproduce.SQLITE_INNOCUOUS. Thesqlite3shell turnstrusted_schemaoff, so before this, views, triggers,CHECKconstraints and generated columns could not use them. A new test covers it, and the previous build fails it..limit lengthbefore decoding untrusted data.build.shwrites the.cotg-own-packagemarker before copying, so an interrupted copy no longer blocks later builds. Oneupdate_package_namehelper now does the com.termux rename for upstream and our packages; it handles any file name and skips binary files, and for the pinnedtermux-packagesit produces the same tree as before.build-package.shskips a same-version package, and publishing keeps the published file);build.shand the README say so, andsqlite-brotliis now 1.0.0-1.run-tests.shquotes file paths for SQL, dot-commands and URIs, and is installed executable.tests/hello.c, the extension acceptance criterion 1 loads, is added, with build instructions in the README.a b'c%d#e?f. Thebuild.shchecks pass in a scratch copy, the recipe passes Termux's linter, and NDK cross-builds for both architectures export only the init function..debfiles and the index were uploaded.run-tests.shis installed executable.dpkg -iupgrades 1.0.0 to the CI-built 1.0.0-1aarch64package,dpkg --verifyis clean, and the installedrun-tests.sh, run directly, passes all 74 tests, including AC1 withhello.sobuilt fromtests/hello.c.arm1.0.0-1 library passes all 74 tests fromadb shellon the same phone, with the published 32-bitsqlite3andbrotli.Hal Eisen's review, commit
c0d8bd4(version 1.0.0-2):build.shasks git which packages are upstream. The untracked marker can outlast a forced checkout orreset --hardof a newertermux-packages; if that commit adds a package with our name, the old check took it for ours and replaced upstream's files, and the cleanup could delete the package. Now a package folder that git tracks stops the build before eitherrm -rf, and the marker only limits the cleanup to foldersbuild.shmade. Git variables inherited from a caller (GIT_DIR,GIT_INDEX_FILE) are dropped, and the build stops iftermux-packagesis not a git checkout of its own or git fails.sqlite-brotlidepends onbrotli (>= 1.1.0), which added the four dictionary functions it calls (v1.0.9's headers have none of them). Revision 2, so the newDepends:line is published.build.shcases in scratch copies pass, including both of Hal's cases; the previousbuild.shoverwrites or deletes upstream's files in 4 of them. A normal run gives the sametermux-packagestree as before, and the recipe passes Termux's linter.aarch6411 min 46 s,arm16 min 12 s) and published it to the stage bucket. Both.debfiles sayDepends: brotli (>= 1.1.0), and their files are byte-identical to 1.0.0-1's.dpkg -iupgrades 1.0.0-1 to 1.0.0-2,dpkg --verifyis clean, and the installed tests pass 74/74. Every command in the ticket's Steps to QA gives the expected output there, andrun-tests.sh -dpasses 73/73 on the app's owndocumentation.db(23,098 Brotli rows) in 78 s.aptfrom the staging repo (stage.appdevforall.org, signed with the prod key) in CoGo's terminal: afterapt-get remove sqlite-brotli,.load sqlite-brotlifails withdlopen failed: library "sqlite-brotli.so" not found.apt-get updatefetches the signed index with no warnings,apt-get install sqlite-brotliinstalls 1.0.0-2 (the installed brotli 1.2.0 meets>= 1.1.0),dpkg --verifyis clean, and the tests pass 73/73 on the app'sdocumentation.db. apt used a temporary source list and lists folder, so the phone's apt setup is unchanged.After review: merge, publish to prod from
main(staging=false, which rebuilds), thenapt install sqlite-brotliin CoGo's terminal and the ticket's Steps to QA.🤖 Generated with Claude Code