From: dan Date: Mon, 19 Feb 2018 16:28:42 +0000 (+0000) Subject: Add support for the ExtendedHeaderSize header field to zonefile. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cbce846ea52f8cc80755f5edbdb3649de3a762f0;p=thirdparty%2Fsqlite.git Add support for the ExtendedHeaderSize header field to zonefile. FossilOrigin-Name: 78267a091307e2c29a4fb1606fa9c79939fe010b801749614f4c48dc8715810e --- diff --git a/ext/zonefile/zonefile.c b/ext/zonefile/zonefile.c index 835a1ff09c..cb6d342c57 100644 --- a/ext/zonefile/zonefile.c +++ b/ext/zonefile/zonefile.c @@ -411,6 +411,7 @@ struct ZonefileWrite { ZonefileCompress *pCmpData; /* For compressing each frame */ int encryptionType; int maxAutoFrameSize; + int debugExtendedHeaderSize; /* Size of extended header */ }; /* @@ -569,6 +570,15 @@ static int zonefileGetParams( while( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pStmt) ){ const char *zKey = (const char*)sqlite3_column_text(pStmt, 0); int iVal = sqlite3_column_int(pStmt, 1); + if( sqlite3_stricmp("debugExtendedHeaderSize", zKey)==0 ){ + if( iVal<0 || iVal>255 ){ + zErr = sqlite3_mprintf( + "debugExtendedHeaderSize value out of range: %d", iVal + ); + rc = SQLITE_ERROR; + } + p->debugExtendedHeaderSize = iVal; + }else if( sqlite3_stricmp("maxAutoFrameSize", zKey)==0 ){ p->maxAutoFrameSize = iVal; }else @@ -720,6 +730,27 @@ static int zonefileAppendCompressed( return SQLITE_OK; } +/* +** Append nByte bytes of garbage data to the file opened with pFd. Return +** SQLITE_OK if successful, or SQLITE_ERROR if an error occurs. +** +** Parameter nByte is only ever non-zero when running tests. So it doesn't +** matter if this function is inefficient in those cases. +*/ +static int zonefilePad(FILE *pFd, int nByte){ + assert( nByte>=0 && nByte<256 ); + if( nByte ){ + int nRem = nByte; + u8 buf[16] = "0123456789ABCDEF"; + while( nRem>0 ){ + int n = MIN(nRem, sizeof(buf)); + if( zonefileFileWrite(pFd, buf, n) ) return SQLITE_ERROR; + nRem -= n; + } + } + return SQLITE_OK; +} + /* ** Function: zonefile_write(F,T[,J]) */ @@ -914,17 +945,18 @@ static void zonefileWriteFunc( aHdr[4] = sWrite.pCmpIdx->eType; aHdr[5] = sWrite.pCmpData->eType; iOff = ZONEFILE_SZ_HEADER + sFrameIdx.n + sKeyIdx.n; - zonefilePut32(&aHdr[6], sDict.n ? iOff : 0); - zonefilePut32(&aHdr[10], iOff + sDict.n); + zonefilePut32(&aHdr[6], sDict.n ? iOff+sWrite.debugExtendedHeaderSize : 0); + zonefilePut32(&aHdr[10], iOff + sWrite.debugExtendedHeaderSize + sDict.n); zonefilePut32(&aHdr[14], nFrame); zonefilePut32(&aHdr[18], nKey); aHdr[22] = sWrite.encryptionType; aHdr[23] = 0; /* Encryption key index */ aHdr[24] = 0; /* extended header version */ - aHdr[25] = 0; /* extended header size */ + aHdr[25] = sWrite.debugExtendedHeaderSize; assert( ZONEFILE_SZ_HEADER>=26 ); rc = zonefileFileWrite(pFd, aHdr, ZONEFILE_SZ_HEADER); + if( rc==SQLITE_OK ) rc = zonefilePad(pFd, sWrite.debugExtendedHeaderSize); if( rc==SQLITE_OK ) rc = zonefileFileWrite(pFd, sFrameIdx.a, sFrameIdx.n); if( rc==SQLITE_OK ) rc = zonefileFileWrite(pFd, sKeyIdx.a, sKeyIdx.n); if( rc==SQLITE_OK ) rc = zonefileFileWrite(pFd, sDict.a, sDict.n); @@ -1331,12 +1363,14 @@ static int zonefileLoadIndex( }else{ nIdx = pHdr->byteOffsetFrames - ZONEFILE_SZ_HEADER; } + nIdx -= pHdr->extendedHeaderSize; aIdx = (u8*)sqlite3_malloc(nIdx); if( aIdx==0 ){ rc = SQLITE_NOMEM; }else{ - rc = zonefileFileRead(pFd, aIdx, nIdx, ZONEFILE_SZ_HEADER); + i64 iOff = ZONEFILE_SZ_HEADER + pHdr->extendedHeaderSize; + rc = zonefileFileRead(pFd, aIdx, nIdx, iOff); } } @@ -1920,7 +1954,9 @@ static int zonefileGetValue(sqlite3_context *pCtx, ZonefileCsr *pCsr){ rc = zonefileLoadIndex(&hdr, pFd, &aFree, &nFree, &zErr); if( rc==SQLITE_OK ) aOff = &aFree[4*(iFrame-1)]; }else{ - rc = zonefileFileRead(pFd, aOff, 8, ZONEFILE_SZ_HEADER + 4 * (iFrame-1)); + rc = zonefileFileRead(pFd, aOff, 8, + ZONEFILE_SZ_HEADER + hdr.extendedHeaderSize + 4 * (iFrame-1) + ); } szFrame = zonefileGet32(&aOff[4]); if( iFrame>0 ){ diff --git a/ext/zonefile/zonefile1.test b/ext/zonefile/zonefile1.test index bdcb4540ff..3526219970 100644 --- a/ext/zonefile/zonefile1.test +++ b/ext/zonefile/zonefile1.test @@ -108,12 +108,14 @@ if {[lsearch $COMPRESSION_METHODS zstd_global_dict]>=0} { } # puts $COMPRESSION_METHODS +set extra_header 0 foreach cmp $COMPRESSION_METHODS { foreach cmpidx $COMPRESSION_METHODS { if {$cmpidx == "zstd_global_dict"} continue reset_db load_static_extension db zonefile set tn "$cmp/$cmpidx" + set extra_header [expr {$extra_header ? 0 : 100}] do_execsql_test 2.$tn.0 { CREATE TABLE zz( @@ -171,7 +173,8 @@ foreach cmp $COMPRESSION_METHODS { foreach cmpidx $COMPRESSION_METHODS { WITH p(n,v) AS ( VALUES('maxAutoFrameSize', 2000) UNION ALL VALUES('compressionTypeIndexData', $cmpidx) UNION ALL - VALUES('compressionTypeContent', $cmp) + VALUES('compressionTypeContent', $cmp) UNION ALL + VALUES('debugExtendedHeaderSize', $extra_header) ) SELECT zonefile_write($zonefile, 'zz', json_group_object(n, v)) FROM p; INSERT INTO zone_files(filename) VALUES($zonefile); diff --git a/manifest b/manifest index 62ca0de21b..859dee6f74 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Modify\sthe\szonefile\sformat\sin\sorder\sto\savoid\sdepending\son\sthe\sfilesize\sto\s\ndetermine\sthe\sextent\sof\sthe\sfinal\sframe.\sSee\sREADME.md\sfor\sdetails. -D 2018-02-19T14:27:24.815 +C Add\ssupport\sfor\sthe\sExtendedHeaderSize\sheader\sfield\sto\szonefile. +D 2018-02-19T16:28:42.025 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F Makefile.in 7a3f714b4fcf793108042b7b0a5c720b0b310ec84314d61ba7f3f49f27e550ea @@ -409,8 +409,8 @@ F ext/userauth/sqlite3userauth.h 7f3ea8c4686db8e40b0a0e7a8e0b00fac13aa7a3 F ext/userauth/user-auth.txt e6641021a9210364665fe625d067617d03f27b04 F ext/userauth/userauth.c 3410be31283abba70255d71fd24734e017a4497f F ext/zonefile/README.md 1a95a93c865e196bc6301581e5a702f449ea9ce0e307cdbdbbdfd58377f1ec7e -F ext/zonefile/zonefile.c 755903797e593dde7876438002d694e3c8cbdf589f2ebda7f646345281e81d99 -F ext/zonefile/zonefile1.test 0f84e56cd4f7b2c05443d1a2632c20ef635cc7f92de2868d92a2a6c09a9258ad +F ext/zonefile/zonefile.c f97d9816be14a7bc03341801de429cac75a713a00b0577836ecc36379953187e +F ext/zonefile/zonefile1.test 2ad39bf0423816e0c741dbb1c49dc46965a2270187f648a2fad8ae934fbdd262 F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 x F ltmain.sh 3ff0879076df340d2e23ae905484d8c15d5fdea8 F magic.txt 8273bf49ba3b0c8559cb2774495390c31fd61c60 @@ -1708,7 +1708,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3eb25b3fa5733b4418e7e2633be34b763e2c70342bb9c418a07c9f7d4b196fac -R d6252e6001118befbde12b4bc598ec3c +P 4dbe0cba3fad9a752834d795127cf35eed21fab63b18a48f75d5c1e96ca77447 +R df0bf0743cc1db7d7fb8cb2a2aaffa81 U dan -Z cbe2e5c769641b120eaa207e1d50335e +Z a68e2d7c6d62c55f7dc86940c3dba82e diff --git a/manifest.uuid b/manifest.uuid index f4e9fee9a4..76ee1088e2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4dbe0cba3fad9a752834d795127cf35eed21fab63b18a48f75d5c1e96ca77447 \ No newline at end of file +78267a091307e2c29a4fb1606fa9c79939fe010b801749614f4c48dc8715810e \ No newline at end of file