From: stephan Date: Mon, 1 Dec 2025 15:49:31 +0000 (+0000) Subject: Teach kvvfs to handle a NULL db file name by generating a random name, and to honor... X-Git-Tag: artiphishell~117^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8f8d021c907eb8eb12845d516dd692794152e08;p=thirdparty%2Fsqlite.git Teach kvvfs to handle a NULL db file name by generating a random name, and to honor the SQLITE_OPEN_CREATE flag. FossilOrigin-Name: 104291469169bef0c2ec5aee9c1cc505447541801bc822e6d5fe5360aef6a2e4 --- diff --git a/ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js b/ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js index a578a4c4e1..f96374d31c 100644 --- a/ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js +++ b/ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js @@ -378,7 +378,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ const other = cache.rxJournalSuffix.test(store.jzClass) ? store.jzClass.replace(cache.rxJournalSuffix,'') : store.jzClass+'-journal'; - //debug("cleaning up storage handles [", store.jzClass, other,"]",store); + debug("cleaning up storage handles [", store.jzClass, other,"]",store); delete cache.storagePool[store.jzClass]; delete cache.storagePool[other]; if( !sqlite3.__isUnderTest ){ @@ -762,9 +762,12 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ /* sqlite3_kvvfs_methods::pVfs's methods */ xOpen: function(pProtoVfs,zName,pProtoFile,flags,pOutFlags){ cache.popError(); + let zToFree /* alloc()'d memory for temp db name */; try{ if( !zName ){ - zName = (cache.zEmpty ??= wasm.allocCString("")); + zToFree = wasm.allocCString(""+pProtoFile+"." + +(Math.random() * 100000 | 0)); + zName = zToFree; } const jzClass = wasm.cstrToJs(zName); //debug("xOpen",jzClass); @@ -778,10 +781,14 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ toss3(capi.SQLITE_ERROR, "DB files may not have a '-journal' suffix."); } + let s = storageForZClass(jzClass); + if( !s && !(flags & capi.SQLITE_OPEN_CREATE) ){ + toss3(capi.SQLITE_ERROR, "Storage not found:", jzClass); + } const rc = originalMethods.vfs.xOpen(pProtoVfs, zName, pProtoFile, flags, pOutFlags); if( rc ) return rc; - let deleteAt0 = false; + let deleteAt0 = !!(capi.SQLITE_OPEN_DELETEONCLOSE & flags); if(wasm.isPtr(arguments[1]/*original zName*/)){ if(capi.sqlite3_uri_boolean(zName, "delete-on-close", 0)){ deleteAt0 = true; @@ -789,22 +796,23 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ } const f = new KVVfsFile(pProtoFile); util.assert(f.$zClass, "Missing f.$zClass"); - let s = storageForZClass(jzClass); + f.addOnDispose(zToFree); + zToFree = undefined; //debug("xOpen", jzClass, s); if( s ){ ++s.refc; //no if( true===deleteAt0 ) s.deleteAtRefc0 = true; s.files.push(f); }else{ - wasm.poke32(pOutFlags, flags | sqlite3.SQLITE_OPEN_CREATE); + wasm.poke32(pOutFlags, flags | capi.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 nm = jzClass.replace(cache.rxJournalSuffix,''); s = newStorageObj(nm); installStorageAndJournal(s); s.files.push(f); - s.deleteAtRefc0 = deleteAt0 || !!(capi.SQLITE_OPEN_DELETEONCLOSE & flags); - //debug("xOpen installed storage handle [",nm, nm+"-journal","]", s); + s.deleteAtRefc0 = deleteAt0; + debug("xOpen installed storage handle [",nm, nm+"-journal","]", s); } pFileHandles.set(pProtoFile, {store: s, file: f, jzClass}); s.listeners && notifyListeners('open', s, s.files.length); @@ -812,6 +820,8 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ }catch(e){ warn("xOpen:",e); return cache.setError(e); + }finally{ + zToFree && wasm.dealloc(zToFree); } }/*xOpen()*/, @@ -1649,6 +1659,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ capi.sqlite3_js_kvvfs_clear = (which="")=>sqlite3_js_kvvfs_clear(which); } +//#if not omit-oo1 if(sqlite3.oo1?.DB){ /** Functionally equivalent to DB(storageName,'c','kvvfs') except @@ -1672,8 +1683,11 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ ){ const opt = DB.dbCtorHelper.normalizeArgs(...arguments); opt.vfs = 'kvvfs'; - if( opt.flags ) opt.flags = 'cw'+opt.flags; - else opt.flags = 'cw'; + if( 0 ){ + // Current tests rely on these, but that's arguably a bug + if( opt.flags ) opt.flags = 'cw'+opt.flags; + else opt.flags = 'cw'; + } switch( opt.filename ){ /* sqlite3_open(), in these builds, recognizes the names below and performs some magic which we want to bypass @@ -1708,6 +1722,7 @@ globalThis.sqlite3ApiBootstrap.initializers.push(function(sqlite3){ return jdb.storageSize(this.affirmOpen().filename, true); }; }/*sqlite3.oo1.JsStorageDb*/ +//#endif not omit-oo1 if( sqlite3.__isUnderTest && sqlite3.vtab ){ /** diff --git a/ext/wasm/tester1.c-pp.js b/ext/wasm/tester1.c-pp.js index 3b4a7bee77..c6db797237 100644 --- a/ext/wasm/tester1.c-pp.js +++ b/ext/wasm/tester1.c-pp.js @@ -3262,13 +3262,14 @@ globalThis.sqlite3InitModule = sqlite3InitModule; const sqlSelectSchema = "select * from sqlite_schema"; const counts = Object.create(null); const incr = (key)=>counts[key] = 1 + (counts[key] ?? 0); - const pglog = Object.create(null); - pglog.pages = []; - pglog.jrnl = undefined; - pglog.size = undefined; - pglog.includeJournal = false; - pglog.decodePages = true; - pglog.exception = new Error("Testing that exceptions from listeners do not interfere"); + const pglog = Object.assign(Object.create(null),{ + pages: [], + jrnl: undefined, + size: undefined, + includeJournal: false, + decodePages: true, + exception: new Error("Testing that exceptions from listeners do not interfere") + }); const toss = ()=>{ if( pglog.exception ){ const e = pglog.exception; diff --git a/manifest b/manifest index 2f6d1175a6..c5667f3aa0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sfiltering\sof\sthe\s64-bit\sspeedtest1\swasm\stest\spages\sto\sagain\sload\sthe\s64-bit\swasm\sfiles. -D 2025-11-30T18:59:44.604 +C Teach\skvvfs\sto\shandle\sa\sNULL\sdb\sfile\sname\sby\sgenerating\sa\srandom\sname,\sand\sto\shonor\sthe\sSQLITE_OPEN_CREATE\sflag. +D 2025-12-01T15:49:31.794 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 bc83c21b2211f1bcaa2b200a08411d86962426284987a39477543bc45bd64260 +F ext/wasm/api/sqlite3-vfs-kvvfs.c-pp.js 82e29781ab83805c7c82ddfe3b5c8fdbc65a914f1433bf966fd7f0f08c7c7c8b F ext/wasm/api/sqlite3-vfs-opfs-sahpool.c-pp.js a2eea6442556867b589e04107796c6e1d04a472219529eeb45b7cd221d7d048b F ext/wasm/api/sqlite3-vfs-opfs.c-pp.js 88ce2078267a2d1af57525a32d896295f4a8db7664de0e17e82dc9ff006ed8d3 F ext/wasm/api/sqlite3-vtab-helper.c-pp.js 366596d8ff73d4cefb938bbe95bc839d503c3fab6c8335ce4bf52f0d8a7dee81 @@ -647,7 +647,7 @@ F ext/wasm/test-opfs-vfs.html 1f2d672f3f3fce810dfd48a8d56914aba22e45c6834e262555 F ext/wasm/test-opfs-vfs.js 1618670e466f424aa289859fe0ec8ded223e42e9e69b5c851f809baaaca1a00c F ext/wasm/tester1-worker.c-pp.html 0e432ec2c0d99cd470484337066e8d27e7aee4641d97115338f7d962bf7b081a F ext/wasm/tester1.c-pp.html 52d88fe2c6f21a046030a36410b4839b632f4424028197a45a3d5669ea724ddb -F ext/wasm/tester1.c-pp.js d8fb2ae2b3aff305040f595be7e0be0fc14fac510fe8bbc92dbb48af9d124c98 +F ext/wasm/tester1.c-pp.js f248ff562b75ce1040c8d148d648afce7cad50683f532cac96dd82ccabcf282e F ext/wasm/tests/opfs/concurrency/index.html 657578a6e9ce1e9b8be951549ed93a6a471f4520a99e5b545928668f4285fb5e F ext/wasm/tests/opfs/concurrency/test.js d08889a5bb6e61937d0b8cbb78c9efbefbf65ad09f510589c779b7cc6a803a88 F ext/wasm/tests/opfs/concurrency/worker.js 0a8c1a3e6ebb38aabbee24f122693f1fb29d599948915c76906681bb7da1d3d2 @@ -2180,8 +2180,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 cf58e17fa2dc2e183a6ea1d41795c701efb303c9b378aa9b90953c9b568c621a -R bc38fc0c5db4dd54fec98ee4b57b00bc +P f507a8af41228d4ca332ab27e842767016ca18adda92e27a1e02e78f12c9be79 +R 3a8252cb3791bd62e996409444e292ee U stephan -Z 6428b67de3175eb95663bffa8d0e7f37 +Z 645a5580ffbb2f20e2e963ab498c53e2 # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c833256626..94c1e19371 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f507a8af41228d4ca332ab27e842767016ca18adda92e27a1e02e78f12c9be79 +104291469169bef0c2ec5aee9c1cc505447541801bc822e6d5fe5360aef6a2e4