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.
Commit
20abe259639742fa8ae9519f070c4b850f34f54345ad300218a5d2ba5c70fce5
Parent
9002a80ad62c5d2…
1 file changed
+6
+6
| --- src/sqlcmd.c | ||
| +++ src/sqlcmd.c | ||
| @@ -84,10 +84,13 @@ | ||
| 84 | 84 | pOut[2] = nIn>>8 & 0xff; |
| 85 | 85 | pOut[3] = nIn & 0xff; |
| 86 | 86 | rc = compress(&pOut[4], &nOut, pIn, nIn); |
| 87 | 87 | if( rc==Z_OK ){ |
| 88 | 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); | |
| 89 | 92 | }else{ |
| 90 | 93 | sqlite3_free(pOut); |
| 91 | 94 | sqlite3_result_error(context, "input cannot be zlib compressed", -1); |
| 92 | 95 | } |
| 93 | 96 | } |
| @@ -113,10 +116,13 @@ | ||
| 113 | 116 | nOut = (pIn[0]<<24) + (pIn[1]<<16) + (pIn[2]<<8) + pIn[3]; |
| 114 | 117 | pOut = sqlite3_malloc( nOut+1 ); |
| 115 | 118 | rc = uncompress(pOut, &nOut, &pIn[4], nIn-4); |
| 116 | 119 | if( rc==Z_OK ){ |
| 117 | 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); | |
| 118 | 124 | }else{ |
| 119 | 125 | sqlite3_free(pOut); |
| 120 | 126 | sqlite3_result_error(context, "input is not zlib compressed", -1); |
| 121 | 127 | } |
| 122 | 128 | } |
| 123 | 129 |
| --- 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 |