Fossil SCM

Pedantic cleanup to how to the SQL compress()/decompress() UDFs report an OOM, which can happen via zlib, outside of fossil's fail-fast allocator.

stephan 2019-05-28 18:43 trunk
Commit 20abe259639742fa8ae9519f070c4b850f34f54345ad300218a5d2ba5c70fce5
1 file changed +6
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -84,10 +84,13 @@
8484
pOut[2] = nIn>>8 & 0xff;
8585
pOut[3] = nIn & 0xff;
8686
rc = compress(&pOut[4], &nOut, pIn, nIn);
8787
if( rc==Z_OK ){
8888
sqlite3_result_blob(context, pOut, nOut+4, sqlite3_free);
89
+ }else if( rc==Z_MEM_ERROR ){
90
+ sqlite3_free(pOut);
91
+ sqlite3_result_error_nomem(context);
8992
}else{
9093
sqlite3_free(pOut);
9194
sqlite3_result_error(context, "input cannot be zlib compressed", -1);
9295
}
9396
}
@@ -113,10 +116,13 @@
113116
nOut = (pIn[0]<<24) + (pIn[1]<<16) + (pIn[2]<<8) + pIn[3];
114117
pOut = sqlite3_malloc( nOut+1 );
115118
rc = uncompress(pOut, &nOut, &pIn[4], nIn-4);
116119
if( rc==Z_OK ){
117120
sqlite3_result_blob(context, pOut, nOut, sqlite3_free);
121
+ }else if( rc==Z_MEM_ERROR ){
122
+ sqlite3_free(pOut);
123
+ sqlite3_result_error_nomem(context);
118124
}else{
119125
sqlite3_free(pOut);
120126
sqlite3_result_error(context, "input is not zlib compressed", -1);
121127
}
122128
}
123129
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -84,10 +84,13 @@
84 pOut[2] = nIn>>8 & 0xff;
85 pOut[3] = nIn & 0xff;
86 rc = compress(&pOut[4], &nOut, pIn, nIn);
87 if( rc==Z_OK ){
88 sqlite3_result_blob(context, pOut, nOut+4, sqlite3_free);
 
 
 
89 }else{
90 sqlite3_free(pOut);
91 sqlite3_result_error(context, "input cannot be zlib compressed", -1);
92 }
93 }
@@ -113,10 +116,13 @@
113 nOut = (pIn[0]<<24) + (pIn[1]<<16) + (pIn[2]<<8) + pIn[3];
114 pOut = sqlite3_malloc( nOut+1 );
115 rc = uncompress(pOut, &nOut, &pIn[4], nIn-4);
116 if( rc==Z_OK ){
117 sqlite3_result_blob(context, pOut, nOut, sqlite3_free);
 
 
 
118 }else{
119 sqlite3_free(pOut);
120 sqlite3_result_error(context, "input is not zlib compressed", -1);
121 }
122 }
123
--- src/sqlcmd.c
+++ src/sqlcmd.c
@@ -84,10 +84,13 @@
84 pOut[2] = nIn>>8 & 0xff;
85 pOut[3] = nIn & 0xff;
86 rc = compress(&pOut[4], &nOut, pIn, nIn);
87 if( rc==Z_OK ){
88 sqlite3_result_blob(context, pOut, nOut+4, sqlite3_free);
89 }else if( rc==Z_MEM_ERROR ){
90 sqlite3_free(pOut);
91 sqlite3_result_error_nomem(context);
92 }else{
93 sqlite3_free(pOut);
94 sqlite3_result_error(context, "input cannot be zlib compressed", -1);
95 }
96 }
@@ -113,10 +116,13 @@
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 sqlite3_free(pOut);
123 sqlite3_result_error_nomem(context);
124 }else{
125 sqlite3_free(pOut);
126 sqlite3_result_error(context, "input is not zlib compressed", -1);
127 }
128 }
129

Keyboard Shortcuts

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