Avoid allocating large objects on the stack in the incremental BLOB I/O

interface. (CVS 6703)

FossilOrigin-Name: ea7dfde700fb57ed0ecb5000a55abbf45aa1e09d
This commit is contained in:
drh 2009-06-01 19:53:30 +00:00
parent e7b3470705
commit 6ee700c32c
3 changed files with 40 additions and 28 deletions

View File

@ -1,5 +1,5 @@
C Malloc\sfor\sspace\sto\shold\sthe\sParse\sobject\sin\ssqlite3_prepare()\sand\sfriends.\nOr,\sif\scompiled\swith\sSQLITE_USE_ALLOCA,\sobtain\sspace\sfor\sthe\sobject\sfrom\nalloca().\s(CVS\s6702) C Avoid\sallocating\slarge\sobjects\son\sthe\sstack\sin\sthe\sincremental\sBLOB\sI/O\ninterface.\s(CVS\s6703)
D 2009-06-01T18:18:21 D 2009-06-01T19:53:31
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 583e87706abc3026960ed759aff6371faf84c211 F Makefile.in 583e87706abc3026960ed759aff6371faf84c211
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@ -208,7 +208,7 @@ F src/vdbe.h 35a648bc3279a120da24f34d9a25213ec15daf8a
F src/vdbeInt.h 43183a2a18654fa570219ab65e53a608057c48ae F src/vdbeInt.h 43183a2a18654fa570219ab65e53a608057c48ae
F src/vdbeapi.c 86aa27a5f3493aaffb8ac051782aa3b22670d7ed F src/vdbeapi.c 86aa27a5f3493aaffb8ac051782aa3b22670d7ed
F src/vdbeaux.c 37730f227a5301c04e5bf03fd303b9086ada990c F src/vdbeaux.c 37730f227a5301c04e5bf03fd303b9086ada990c
F src/vdbeblob.c 5c5abe9af28316772e7829359f6f9cda2c737ebd F src/vdbeblob.c c25d7e7bc6d5917feeb17270bd275fa771f26e5c
F src/vdbemem.c 05183d46094aa99b8f8350e5761b9369dbef35a8 F src/vdbemem.c 05183d46094aa99b8f8350e5761b9369dbef35a8
F src/vtab.c b0216337ae7d27708dedd56d220e6f4fecda92f1 F src/vtab.c b0216337ae7d27708dedd56d220e6f4fecda92f1
F src/walker.c ec4b9742a4077ef80346e2f9aaf0f44c2d95087a F src/walker.c ec4b9742a4077ef80346e2f9aaf0f44c2d95087a
@ -731,7 +731,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P b126013b5a1d6526810139d19acbec7fd0ab8168 P c7c0c58e472cd8277b2ad58bb60834190bace4fa
R 5749ee12901dac70e7e5afa66675a445 R 01d40d71e1b5c8cea7b1b21c881c4bd8
U drh U drh
Z d18ab08e2623638148c802e092f00e62 Z f0ffd7a898768d77c536a218a2488cbe

View File

@ -1 +1 @@
c7c0c58e472cd8277b2ad58bb60834190bace4fa ea7dfde700fb57ed0ecb5000a55abbf45aa1e09d

View File

@ -12,7 +12,7 @@
** **
** This file contains code used to implement incremental BLOB I/O. ** This file contains code used to implement incremental BLOB I/O.
** **
** $Id: vdbeblob.c,v 1.32 2009/05/09 15:17:47 drh Exp $ ** $Id: vdbeblob.c,v 1.33 2009/06/01 19:53:31 drh Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
@ -83,40 +83,46 @@ int sqlite3_blob_open(
Vdbe *v = 0; Vdbe *v = 0;
int rc = SQLITE_OK; int rc = SQLITE_OK;
char zErr[128]; char *zErr = 0;
Table *pTab;
Parse *pParse;
*ppBlob = 0; *ppBlob = 0;
zErr[0] = 0;
sqlite3_mutex_enter(db->mutex); sqlite3_mutex_enter(db->mutex);
pParse = sqlite3StackAllocRaw(db, sizeof(*pParse));
if( pParse==0 ){
rc = SQLITE_NOMEM;
goto blob_open_out;
}
do { do {
Parse sParse; memset(pParse, 0, sizeof(Parse));
Table *pTab; pParse->db = db;
memset(&sParse, 0, sizeof(Parse));
sParse.db = db;
if( sqlite3SafetyOn(db) ){ if( sqlite3SafetyOn(db) ){
sqlite3DbFree(db, zErr);
sqlite3StackFree(db, pParse);
sqlite3_mutex_leave(db->mutex); sqlite3_mutex_leave(db->mutex);
return SQLITE_MISUSE; return SQLITE_MISUSE;
} }
sqlite3BtreeEnterAll(db); sqlite3BtreeEnterAll(db);
pTab = sqlite3LocateTable(&sParse, 0, zTable, zDb); pTab = sqlite3LocateTable(pParse, 0, zTable, zDb);
if( pTab && IsVirtual(pTab) ){ if( pTab && IsVirtual(pTab) ){
pTab = 0; pTab = 0;
sqlite3ErrorMsg(&sParse, "cannot open virtual table: %s", zTable); sqlite3ErrorMsg(pParse, "cannot open virtual table: %s", zTable);
} }
#ifndef SQLITE_OMIT_VIEW #ifndef SQLITE_OMIT_VIEW
if( pTab && pTab->pSelect ){ if( pTab && pTab->pSelect ){
pTab = 0; pTab = 0;
sqlite3ErrorMsg(&sParse, "cannot open view: %s", zTable); sqlite3ErrorMsg(pParse, "cannot open view: %s", zTable);
} }
#endif #endif
if( !pTab ){ if( !pTab ){
if( sParse.zErrMsg ){ if( pParse->zErrMsg ){
sqlite3_snprintf(sizeof(zErr), zErr, "%s", sParse.zErrMsg); sqlite3DbFree(db, zErr);
zErr = pParse->zErrMsg;
pParse->zErrMsg = 0;
} }
sqlite3DbFree(db, sParse.zErrMsg);
rc = SQLITE_ERROR; rc = SQLITE_ERROR;
(void)sqlite3SafetyOff(db); (void)sqlite3SafetyOff(db);
sqlite3BtreeLeaveAll(db); sqlite3BtreeLeaveAll(db);
@ -130,7 +136,8 @@ int sqlite3_blob_open(
} }
} }
if( iCol==pTab->nCol ){ if( iCol==pTab->nCol ){
sqlite3_snprintf(sizeof(zErr), zErr, "no such column: \"%s\"", zColumn); sqlite3DbFree(db, zErr);
zErr = sqlite3MPrintf(db, "no such column: \"%s\"", zColumn);
rc = SQLITE_ERROR; rc = SQLITE_ERROR;
(void)sqlite3SafetyOff(db); (void)sqlite3SafetyOff(db);
sqlite3BtreeLeaveAll(db); sqlite3BtreeLeaveAll(db);
@ -147,7 +154,8 @@ int sqlite3_blob_open(
int j; int j;
for(j=0; j<pIdx->nColumn; j++){ for(j=0; j<pIdx->nColumn; j++){
if( pIdx->aiColumn[j]==iCol ){ if( pIdx->aiColumn[j]==iCol ){
sqlite3_snprintf(sizeof(zErr), zErr, sqlite3DbFree(db, zErr);
zErr = sqlite3MPrintf(db,
"cannot open indexed column for writing"); "cannot open indexed column for writing");
rc = SQLITE_ERROR; rc = SQLITE_ERROR;
(void)sqlite3SafetyOff(db); (void)sqlite3SafetyOff(db);
@ -207,7 +215,8 @@ int sqlite3_blob_open(
if( rc!=SQLITE_ROW ){ if( rc!=SQLITE_ROW ){
nAttempt++; nAttempt++;
rc = sqlite3_finalize((sqlite3_stmt *)v); rc = sqlite3_finalize((sqlite3_stmt *)v);
sqlite3_snprintf(sizeof(zErr), zErr, sqlite3_errmsg(db)); sqlite3DbFree(db, zErr);
zErr = sqlite3MPrintf(db, sqlite3_errmsg(db));
v = 0; v = 0;
} }
} while( nAttempt<5 && rc==SQLITE_SCHEMA ); } while( nAttempt<5 && rc==SQLITE_SCHEMA );
@ -221,7 +230,8 @@ int sqlite3_blob_open(
u32 type = v->apCsr[0]->aType[iCol]; u32 type = v->apCsr[0]->aType[iCol];
if( type<12 ){ if( type<12 ){
sqlite3_snprintf(sizeof(zErr), zErr, "cannot open value of type %s", sqlite3DbFree(db, zErr);
zErr = sqlite3MPrintf(db, "cannot open value of type %s",
type==0?"null": type==7?"real": "integer" type==0?"null": type==7?"real": "integer"
); );
rc = SQLITE_ERROR; rc = SQLITE_ERROR;
@ -244,16 +254,18 @@ int sqlite3_blob_open(
*ppBlob = (sqlite3_blob *)pBlob; *ppBlob = (sqlite3_blob *)pBlob;
rc = SQLITE_OK; rc = SQLITE_OK;
}else if( rc==SQLITE_OK ){ }else if( rc==SQLITE_OK ){
sqlite3_snprintf(sizeof(zErr), zErr, "no such rowid: %lld", iRow); sqlite3DbFree(db, zErr);
zErr = sqlite3MPrintf(db, "no such rowid: %lld", iRow);
rc = SQLITE_ERROR; rc = SQLITE_ERROR;
} }
blob_open_out: blob_open_out:
zErr[sizeof(zErr)-1] = '\0';
if( v && (rc!=SQLITE_OK || db->mallocFailed) ){ if( v && (rc!=SQLITE_OK || db->mallocFailed) ){
sqlite3VdbeFinalize(v); sqlite3VdbeFinalize(v);
} }
sqlite3Error(db, rc, (rc==SQLITE_OK?0:zErr)); sqlite3Error(db, rc, zErr);
sqlite3DbFree(db, zErr);
sqlite3StackFree(db, pParse);
rc = sqlite3ApiExit(db, rc); rc = sqlite3ApiExit(db, rc);
sqlite3_mutex_leave(db->mutex); sqlite3_mutex_leave(db->mutex);
return rc; return rc;