diff options
author | dan <Dan Kennedy> | 2021-05-25 15:21:54 +0000 |
---|---|---|
committer | dan <Dan Kennedy> | 2021-05-25 15:21:54 +0000 |
commit | 4df68e0ae537a6821854d6cfacdf52b7d58ffb46 (patch) | |
tree | ffaabfe8a5abf177c46d8773fd8618dc3dccdfe2 /ext/session/sqlite3session.c | |
parent | 78a9d7551c7f709eef0804bd00caee1c06ff11d0 (diff) | |
download | sqlite-4df68e0ae537a6821854d6cfacdf52b7d58ffb46.tar.gz sqlite-4df68e0ae537a6821854d6cfacdf52b7d58ffb46.zip |
Update an allocation routine in the sessions module to allow it to allocate the maximum size permitted by sqlite3_realloc64().
FossilOrigin-Name: 0b45e821911e4a852edd6d9e9cfe5f9de33337edf76fb12b79adaf11a4b83e8a
Diffstat (limited to 'ext/session/sqlite3session.c')
-rw-r--r-- | ext/session/sqlite3session.c | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/ext/session/sqlite3session.c b/ext/session/sqlite3session.c index 1f6c58b4d..c96363b60 100644 --- a/ext/session/sqlite3session.c +++ b/ext/session/sqlite3session.c @@ -1974,13 +1974,29 @@ int sqlite3session_attach( ** If successful, return zero. Otherwise, if an OOM condition is encountered, ** set *pRc to SQLITE_NOMEM and return non-zero. */ -static int sessionBufferGrow(SessionBuffer *p, size_t nByte, int *pRc){ - if( *pRc==SQLITE_OK && (size_t)(p->nAlloc-p->nBuf)<nByte ){ +static int sessionBufferGrow(SessionBuffer *p, i64 nByte, int *pRc){ +#define SESSION_MAX_BUFFER_SZ (0x7FFFFF00 - 1) + i64 nReq = p->nBuf + nByte; + if( *pRc==SQLITE_OK && nReq>p->nAlloc ){ u8 *aNew; i64 nNew = p->nAlloc ? p->nAlloc : 128; + do { nNew = nNew*2; - }while( (size_t)(nNew-p->nBuf)<nByte ); + }while( nNew<nReq ); + + /* The value of SESSION_MAX_BUFFER_SZ is copied from the implementation + ** of sqlite3_realloc64(). Allocations greater than this size in bytes + ** always fail. It is used here to ensure that this routine can always + ** allocate up to this limit - instead of up to the largest power of + ** two smaller than the limit. */ + if( nNew>SESSION_MAX_BUFFER_SZ ){ + nNew = SESSION_MAX_BUFFER_SZ; + if( nNew<nReq ){ + *pRc = SQLITE_NOMEM; + return 1; + } + } aNew = (u8 *)sqlite3_realloc64(p->aBuf, nNew); if( 0==aNew ){ |