Fossil SCM

Fix problems with the built-in "decompress()" SQL function.

drh 2020-09-16 13:58 trunk
Commit 449ab5d6003c78ecd3014bf4ad6695703f2b54d6e6653a54aeffcc8d30ddd91c
1 file changed +3
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -110,12 +110,15 @@
110110
unsigned int nIn;
111111
unsigned long int nOut;
112112
int rc;
113113
114114
pIn = sqlite3_value_blob(argv[0]);
115
+ if( pIn==0 ) return;
115116
nIn = sqlite3_value_bytes(argv[0]);
117
+ if( nIn<4 ) return;
116118
nOut = (pIn[0]<<24) + (pIn[1]<<16) + (pIn[2]<<8) + pIn[3];
119
+ if( nOut<0 ) return;
117120
pOut = sqlite3_malloc( nOut+1 );
118121
rc = uncompress(pOut, &nOut, &pIn[4], nIn-4);
119122
if( rc==Z_OK ){
120123
sqlite3_result_blob(context, pOut, nOut, sqlite3_free);
121124
}else if( rc==Z_MEM_ERROR ){
122125
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -110,12 +110,15 @@
110 unsigned int nIn;
111 unsigned long int nOut;
112 int rc;
113
114 pIn = sqlite3_value_blob(argv[0]);
 
115 nIn = sqlite3_value_bytes(argv[0]);
 
116 nOut = (pIn[0]<<24) + (pIn[1]<<16) + (pIn[2]<<8) + pIn[3];
 
117 pOut = sqlite3_malloc( nOut+1 );
118 rc = uncompress(pOut, &nOut, &pIn[4], nIn-4);
119 if( rc==Z_OK ){
120 sqlite3_result_blob(context, pOut, nOut, sqlite3_free);
121 }else if( rc==Z_MEM_ERROR ){
122
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -110,12 +110,15 @@
110 unsigned int nIn;
111 unsigned long int nOut;
112 int rc;
113
114 pIn = sqlite3_value_blob(argv[0]);
115 if( pIn==0 ) return;
116 nIn = sqlite3_value_bytes(argv[0]);
117 if( nIn<4 ) return;
118 nOut = (pIn[0]<<24) + (pIn[1]<<16) + (pIn[2]<<8) + pIn[3];
119 if( nOut<0 ) return;
120 pOut = sqlite3_malloc( nOut+1 );
121 rc = uncompress(pOut, &nOut, &pIn[4], nIn-4);
122 if( rc==Z_OK ){
123 sqlite3_result_blob(context, pOut, nOut, sqlite3_free);
124 }else if( rc==Z_MEM_ERROR ){
125

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button