Skip to content

Commit

Permalink
Prepare release of version 1.5.4
Browse files Browse the repository at this point in the history
- Based on SQLite version 3.40.0
  • Loading branch information
utelle committed Nov 19, 2022
1 parent a8c9e93 commit e623ed2
Show file tree
Hide file tree
Showing 16 changed files with 10,802 additions and 4,196 deletions.
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dnl Copyright (C) 2019-2022 Ulrich Telle <ulrich@telle-online.de>
dnl
dnl This file is covered by the same licence as the entire SQLite3 Multiple Ciphers package.

AC_INIT([sqlite3mc], [1.5.3], [ulrich@telle-online.de])
AC_INIT([sqlite3mc], [1.5.4], [ulrich@telle-online.de])

dnl This is the version tested with, might work with earlier ones.
AC_PREREQ([2.69])
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ The code was mainly developed under Windows, but was tested under Linux as well.

## Version history

* 1.5.4 - *November 2022*
- Based on SQLite version 3.40.0
* 1.5.3 - *September 2022*
- Based on SQLite version 3.39.4
* 1.5.2 - *September 2022*
Expand Down
21 changes: 11 additions & 10 deletions src/chacha20poly1305.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,26 @@
static void chacha20_block(uint32_t x[16])
{
int i;
#define QR(x, a, b, c, d) \
/* Macro renamed from QR to CC20QR to avoid name clashes. */
#define CC20QR(x, a, b, c, d) \
x[a] += x[b]; x[d] ^= x[a]; x[d] = ROL32(x[d], 16); \
x[c] += x[d]; x[b] ^= x[c]; x[b] = ROL32(x[b], 12); \
x[a] += x[b]; x[d] ^= x[a]; x[d] = ROL32(x[d], 8); \
x[c] += x[d]; x[b] ^= x[c]; x[b] = ROL32(x[b], 7);
for (i = 0; i < 10; i++)
{
/* Column round */
QR(x, 0, 4, 8, 12)
QR(x, 1, 5, 9, 13)
QR(x, 2, 6, 10, 14)
QR(x, 3, 7, 11, 15)
CC20QR(x, 0, 4, 8, 12)
CC20QR(x, 1, 5, 9, 13)
CC20QR(x, 2, 6, 10, 14)
CC20QR(x, 3, 7, 11, 15)
/* Diagonal round */
QR(x, 0, 5, 10, 15)
QR(x, 1, 6, 11, 12)
QR(x, 2, 7, 8, 13)
QR(x, 3, 4, 9, 14)
CC20QR(x, 0, 5, 10, 15)
CC20QR(x, 1, 6, 11, 12)
CC20QR(x, 2, 7, 8, 13)
CC20QR(x, 3, 4, 9, 14)
}
#undef QR
#undef CC20QR
}

void chacha20_xor(void* buffer, size_t n, const uint8_t key[32],
Expand Down
9 changes: 8 additions & 1 deletion src/csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ static char *csv_read_one_field(CsvReader *p){
}
p->cTerm = (char)c;
}
assert( p->z==0 || p->n<p->nAlloc );
if( p->z ) p->z[p->n] = 0;
p->bNotFirst = 1;
return p->z;
Expand Down Expand Up @@ -750,7 +751,7 @@ static int csvtabNext(sqlite3_vtab_cursor *cur){
i++;
}
}while( pCur->rdr.cTerm==',' );
if( z==0 || (pCur->rdr.cTerm==EOF && i<pTab->nCol) ){
if( z==0 && i==0 ){
pCur->iRowid = -1;
}else{
pCur->iRowid++;
Expand Down Expand Up @@ -811,6 +812,12 @@ static int csvtabFilter(
CsvCursor *pCur = (CsvCursor*)pVtabCursor;
CsvTable *pTab = (CsvTable*)pVtabCursor->pVtab;
pCur->iRowid = 0;

/* Ensure the field buffer is always allocated. Otherwise, if the
** first field is zero bytes in size, this may be mistaken for an OOM
** error in csvtabNext(). */
if( csv_append(&pCur->rdr, 0) ) return SQLITE_NOMEM;

if( pCur->rdr.in==0 ){
assert( pCur->rdr.zIn==pTab->zData );
assert( pTab->iStart>=0 );
Expand Down
125 changes: 116 additions & 9 deletions src/regexp.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ SQLITE_EXTENSION_INIT1

/* The end-of-input character */
#define RE_EOF 0 /* End of input */
#define RE_START 0xfffffff /* Start of input - larger than an UTF-8 */

/* The NFA is implemented as sequence of opcodes taken from the following
** set. Each opcode has a single integer argument.
Expand All @@ -93,6 +94,33 @@ SQLITE_EXTENSION_INIT1
#define RE_OP_SPACE 15 /* space: [ \t\n\r\v\f] */
#define RE_OP_NOTSPACE 16 /* Not a digit */
#define RE_OP_BOUNDARY 17 /* Boundary between word and non-word */
#define RE_OP_ATSTART 18 /* Currently at the start of the string */

#if defined(SQLITE_DEBUG)
/* Opcode names used for symbolic debugging */
static const char *ReOpName[] = {
"EOF",
"MATCH",
"ANY",
"ANYSTAR",
"FORK",
"GOTO",
"ACCEPT",
"CC_INC",
"CC_EXC",
"CC_VALUE",
"CC_RANGE",
"WORD",
"NOTWORD",
"DIGIT",
"NOTDIGIT",
"SPACE",
"NOTSPACE",
"BOUNDARY",
"ATSTART",
};
#endif /* SQLITE_DEBUG */


/* Each opcode is a "state" in the NFA */
typedef unsigned short ReStateNumber;
Expand Down Expand Up @@ -127,7 +155,7 @@ struct ReCompiled {
int *aArg; /* Arguments to each operator */
unsigned (*xNextChar)(ReInput*); /* Next character function */
unsigned char zInit[12]; /* Initial text to match */
int nInit; /* Number of characters in zInit */
int nInit; /* Number of bytes in zInit */
unsigned nState; /* Number of entries in aOp[] and aArg[] */
unsigned nAlloc; /* Slots allocated for aOp[] and aArg[] */
};
Expand Down Expand Up @@ -200,7 +228,7 @@ static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
ReStateNumber *pToFree;
unsigned int i = 0;
unsigned int iSwap = 0;
int c = RE_EOF+1;
int c = RE_START;
int cPrev = 0;
int rc = 0;
ReInput in;
Expand All @@ -219,6 +247,7 @@ static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
in.i++;
}
if( in.i+pRe->nInit>in.mx ) return 0;
c = RE_START-1;
}

if( pRe->nState<=(sizeof(aSpace)/(sizeof(aSpace[0])*2)) ){
Expand Down Expand Up @@ -247,6 +276,10 @@ static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
if( pRe->aArg[x]==c ) re_add_state(pNext, x+1);
break;
}
case RE_OP_ATSTART: {
if( cPrev==RE_START ) re_add_state(pThis, x+1);
break;
}
case RE_OP_ANY: {
if( c!=0 ) re_add_state(pNext, x+1);
break;
Expand Down Expand Up @@ -328,7 +361,9 @@ static int re_match(ReCompiled *pRe, const unsigned char *zIn, int nIn){
}
}
for(i=0; i<pNext->nState; i++){
if( pRe->aOp[pNext->aState[i]]==RE_OP_ACCEPT ){ rc = 1; break; }
int x = pNext->aState[i];
while( pRe->aOp[x]==RE_OP_GOTO ) x += pRe->aArg[x];
if( pRe->aOp[x]==RE_OP_ACCEPT ){ rc = 1; break; }
}
re_match_end:
sqlite3_free(pToFree);
Expand Down Expand Up @@ -483,7 +518,6 @@ static const char *re_subcompile_string(ReCompiled *p){
iStart = p->nState;
switch( c ){
case '|':
case '$':
case ')': {
p->sIn.i--;
return 0;
Expand Down Expand Up @@ -520,6 +554,14 @@ static const char *re_subcompile_string(ReCompiled *p){
re_insert(p, iPrev, RE_OP_FORK, p->nState - iPrev+1);
break;
}
case '$': {
re_append(p, RE_OP_MATCH, RE_EOF);
break;
}
case '^': {
re_append(p, RE_OP_ATSTART, 0);
break;
}
case '{': {
int m = 0, n = 0;
int sz, j;
Expand All @@ -538,6 +580,7 @@ static const char *re_subcompile_string(ReCompiled *p){
if( m==0 ){
if( n==0 ) return "both m and n are zero in '{m,n}'";
re_insert(p, iPrev, RE_OP_FORK, sz+1);
iPrev++;
n--;
}else{
for(j=1; j<m; j++) re_copy(p, iPrev, sz);
Expand Down Expand Up @@ -656,11 +699,7 @@ static const char *re_compile(ReCompiled **ppRe, const char *zIn, int noCase){
re_free(pRe);
return zErr;
}
if( rePeek(pRe)=='$' && pRe->sIn.i+1>=pRe->sIn.mx ){
re_append(pRe, RE_OP_MATCH, RE_EOF);
re_append(pRe, RE_OP_ACCEPT, 0);
*ppRe = pRe;
}else if( pRe->sIn.i>=pRe->sIn.mx ){
if( pRe->sIn.i>=pRe->sIn.mx ){
re_append(pRe, RE_OP_ACCEPT, 0);
*ppRe = pRe;
}else{
Expand Down Expand Up @@ -744,6 +783,67 @@ static void re_sql_func(
}
}

#if defined(SQLITE_DEBUG)
/*
** This function is used for testing and debugging only. It is only available
** if the SQLITE_DEBUG compile-time option is used.
**
** Compile a regular expression and then convert the compiled expression into
** text and return that text.
*/
static void re_bytecode_func(
sqlite3_context *context,
int argc,
sqlite3_value **argv
){
const char *zPattern;
const char *zErr;
ReCompiled *pRe;
sqlite3_str *pStr;
int i;
int n;
char *z;

zPattern = (const char*)sqlite3_value_text(argv[0]);
if( zPattern==0 ) return;
zErr = re_compile(&pRe, zPattern, sqlite3_user_data(context)!=0);
if( zErr ){
re_free(pRe);
sqlite3_result_error(context, zErr, -1);
return;
}
if( pRe==0 ){
sqlite3_result_error_nomem(context);
return;
}
pStr = sqlite3_str_new(0);
if( pStr==0 ) goto re_bytecode_func_err;
if( pRe->nInit>0 ){
sqlite3_str_appendf(pStr, "INIT ");
for(i=0; i<pRe->nInit; i++){
sqlite3_str_appendf(pStr, "%02x", pRe->zInit[i]);
}
sqlite3_str_appendf(pStr, "\n");
}
for(i=0; (unsigned)i<pRe->nState; i++){
sqlite3_str_appendf(pStr, "%-8s %4d\n",
ReOpName[(unsigned char)pRe->aOp[i]], pRe->aArg[i]);
}
n = sqlite3_str_length(pStr);
z = sqlite3_str_finish(pStr);
if( n==0 ){
sqlite3_free(z);
}else{
sqlite3_result_text(context, z, n-1, sqlite3_free);
}

re_bytecode_func_err:
re_free(pRe);
}

#endif /* SQLITE_DEBUG */


/*
** Invoke this routine to register the regexp() function with the
** SQLite database connection.
Expand All @@ -768,6 +868,13 @@ int sqlite3_regexp_init(
rc = sqlite3_create_function(db, "regexpi", 2,
SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
(void*)db, re_sql_func, 0, 0);
#if defined(SQLITE_DEBUG)
if( rc==SQLITE_OK ){
rc = sqlite3_create_function(db, "regexp_bytecode", 1,
SQLITE_UTF8|SQLITE_INNOCUOUS|SQLITE_DETERMINISTIC,
0, re_bytecode_func, 0, 0);
}
#endif /* SQLITE_DEBUG */
}
return rc;
}
10 changes: 8 additions & 2 deletions src/rekeyvacuum.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
** Change 4: Call sqlite3mcBtreeSetPageSize instead of sqlite3BtreeSetPageSize for main database
** (sqlite3mcBtreeSetPageSize allows to reduce the number of reserved bytes)
**
** This code is generated by the script rekeyvacuum.sh from SQLite version 3.39.4 amalgamation.
** This code is generated by the script rekeyvacuum.sh from SQLite version 3.40.0 amalgamation.
*/
SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3mcRunVacuumForRekey(
char **pzErrMsg, /* Write error message here */
Expand All @@ -49,6 +49,7 @@ SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3mcRunVacuumForRekey(
int nDb; /* Number of attached databases */
const char *zDbMain; /* Schema name of database to vacuum */
const char *zOut; /* Name of output file */
u32 pgflags = PAGER_SYNCHRONOUS_OFF; /* sync flags for output db */

if( !db->autoCommit ){
sqlite3SetString(pzErrMsg, db, "cannot VACUUM from within a transaction");
Expand Down Expand Up @@ -120,6 +121,11 @@ SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3mcRunVacuumForRekey(
goto end_of_vacuum;
}
db->mDbFlags |= DBFLAG_VacuumInto;

/* For a VACUUM INTO, the pager-flags are set to the same values as
** they are for the database being vacuumed, except that PAGER_CACHESPILL
** is always set. */
pgflags = db->aDb[iDb].safety_level | (db->flags & PAGER_FLAGS_MASK);
}

/* A VACUUM cannot change the pagesize of an encrypted database. */
Expand All @@ -133,7 +139,7 @@ SQLITE_PRIVATE SQLITE_NOINLINE int sqlite3mcRunVacuumForRekey(

sqlite3BtreeSetCacheSize(pTemp, db->aDb[iDb].pSchema->cache_size);
sqlite3BtreeSetSpillSize(pTemp, sqlite3BtreeSetSpillSize(pMain,0));
sqlite3BtreeSetPagerFlags(pTemp, PAGER_SYNCHRONOUS_OFF|PAGER_CACHESPILL);
sqlite3BtreeSetPagerFlags(pTemp, pgflags|PAGER_CACHESPILL);

/* Begin a transaction and take an exclusive lock on the main database
** file. This is done before the sqlite3BtreeGetPageSize(pMain) call below,
Expand Down
4 changes: 4 additions & 0 deletions src/sha2.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@

#define SHFR(x, n) (x >> n)
#define ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n)))
#if 0
/* SQLite version 3.40.0 and later already defines this macro. */
/* The macro isn't used here anyway, so simply inactivate it. */
#define ROTL(x, n) ((x << n) | (x >> ((sizeof(x) << 3) - n)))
#endif
#define CH(x, y, z) ((x & y) ^ (~x & z))
#define MAJ(x, y, z) ((x & y) ^ (x & z) ^ (y & z))

Expand Down
Loading

0 comments on commit e623ed2

Please sign in to comment.