From: stephan Date: Mon, 24 Nov 2025 18:08:25 +0000 (+0000) Subject: Have kvvfs enforce ASCII-only names to avoid truncating multibyte characters in kvvfs... X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c340a0f71786d8444a8d4df1735ec5241a6f38a6;p=thirdparty%2Fsqlite.git Have kvvfs enforce ASCII-only names to avoid truncating multibyte characters in kvvfs's key buffer. FossilOrigin-Name: 03cb2a13c7f9081132390b5169cf22ffeced6ebdc5f01654360f951720310916 --- diff --git a/ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js index 376dcf6ac2..f0a0dda6d2 100644 --- a/ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js @@ -31,7 +31,7 @@ objects as storage. It uses a bespoke ASCII encoding to store each db page as a - separate record and stores some metadata, like the db's encoded + separate record and stores some metadata, like the db's unencoded size and its journal, as individual records. kvvfs is significantly less efficient than a plain in-memory db but @@ -605,18 +605,27 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ xOpen: function(pProtoVfs,zName,pProtoFile,flags,pOutFlags){ try{ //cache.zReadBuf ??= wasm.malloc(kvvfsMethods.$nBufferSize); + if( !zName ){ + zName = (cache.zEmpty ??= wasm.allocCString("")); + } const n = wasm.cstrlen(zName); if( n > kvvfsMethods.$nKeySize - 8 /*"-journal"*/ - 1 ){ warn("file name is too long:", wasm.cstrToJs(zName)); return capi.SQLITE_RANGE; } - //wasm.poke32(pOutFlags, flags | sqlite3.SQLITE_OPEN_CREATE); + const jzClass = wasm.cstrToJs(zName); + if( jzClass?.length != n ){ + warn("kvvfs file name must be ASCII-only"); + /* This limitation is to avoide any issues with + truncating multi-byte characters in kvvfs's key-size + limit. */ + return capi.SQLITE_RANGE; + } const rc = originalMethods.vfs.xOpen(pProtoVfs, zName, pProtoFile, flags, pOutFlags); if( rc ) return rc; const f = new KVVfsFile(pProtoFile); util.assert(f.$zClass, "Missing f.$zClass"); - const jzClass = wasm.cstrToJs(zName); let s = storageForZClass(jzClass); //debug("xOpen", jzClass, s); if( s ){ @@ -627,7 +636,9 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ around forever so that future xOpen()s get the same Storage-ish objects. We can accomplish that by simply increasing the refcount once more. */ + wasm.poke32(pOutFlags, flags | sqlite3.SQLITE_OPEN_CREATE); util.assert( !f.$isJournal, "Opening a journal before its db? "+jzClass ); + /* Map both zName and zName-journal to the same storage. */ const other = f.$isJournal ? jzClass.replace(cache.rxJournalSuffix,'') : jzClass + '-journal'; @@ -1014,7 +1025,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ s.setItem(keyPrefix+'sz', exp.size); if( exp.journal ) s.setItem(keyPrefix+'jrnl', exp.journal); exp.pages.forEach((v,ndx)=>s.setItem(keyPrefix+(ndx+1), v)); - s.getItem("")/*kludge: for KVVfsStorage to reset its keys*/; + //s.getItem("")/*kludge: for KVVfsStorage to reset its keys*/; }catch(e){ capi.sqlite3_js_kvvfs_clear(exp.name); throw e; diff --git a/manifest b/manifest index dcb77e2730..aecc31e667 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Get\skvvfs\sv2\sstorage\simport\sworking\sby\sdisallowing\sit\swhen\sthere\sare\sopened\sdb/journal\shandles.\sMove\simport/export\sout\sof\sthe\sJsStorageDb\sclass\sand\sinto\ssqlite3_js_kvvfs_import/export_storage(). -D 2025-11-24T15:17:52.331 +C Have\skvvfs\senforce\sASCII-only\snames\sto\savoid\struncating\smultibyte\scharacters\sin\skvvfs's\skey\sbuffer. +D 2025-11-24T18:08:25.957 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -600,7 +600,7 @@ F ext/wasm/api/sqlite3-api-worker1.c-pp.js 1041dd645e8e821c082b628cd8d9acf70c667 F ext/wasm/api/sqlite3-license-version-header.js 0c807a421f0187e778dc1078f10d2994b915123c1223fe752b60afdcd1263f89 F ext/wasm/api/sqlite3-opfs-async-proxy.js 9654b565b346dc609b75d15337f20acfa7af7d9d558da1afeb9b6d8eaa404966 F ext/wasm/api/sqlite3-vfs-helper.c-pp.js 3f828cc66758acb40e9c5b4dcfd87fd478a14c8fb7f0630264e6c7fa0e57515d -F ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js efe13bc4196b02a87d6a472c7c7826c335c82cd5a844381f017813d4f78e1397 +F ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js 71e9e242c52ae883cb01513dee99f8cfa4b5baab938006dc36e0dfade37107c7 F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js 26cb41d5a62f46a106b6371eb00fef02de3cdbfaa51338ba087a45f53028e0d0 F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 88ce2078267a2d1af57525a32d896295f4a8db7664de0e17e82dc9ff006ed8d3 F ext/wasm/api/sqlite3-vtab-helper.c-pp.js 9097074724172e31e56ce20ccd7482259cf72a76124213cbc9469d757676da86 @@ -2178,8 +2178,8 @@ F tool/version-info.c 33d0390ef484b3b1cb685d59362be891ea162123cea181cb8e6d2cf6dd F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7 F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f -P 4857c9d2fe428c19319244bf0589eaf93c124f020a633d6b7d40d35aaf969d24 -R f6b4509896384b2525280dbe96143648 +P c9e0b32278290baf987b5a46bd47358439e3d0f190b2879a965d6e4262ea7baf +R 1c382103cfb0141648b7dd4e5588803c U stephan -Z 5db1ea489dc4ed416d893c241ae0c76d +Z 4eeb1eaa667084f54349e0f6be023c0d # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 7030fae573..499e23b91e 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c9e0b32278290baf987b5a46bd47358439e3d0f190b2879a965d6e4262ea7baf +03cb2a13c7f9081132390b5169cf22ffeced6ebdc5f01654360f951720310916