| | @@ -64,13 +64,13 @@ |
| 64 | 64 | static void deltaApplyFunc( |
| 65 | 65 | sqlite3_context *context, |
| 66 | 66 | int argc, |
| 67 | 67 | sqlite3_value **argv |
| 68 | 68 | ){ |
| 69 | | - const char *aOrig; int nOrig; /* The X input */ |
| 70 | | - const char *aDelta; int nDelta; /* The input delta (D) */ |
| 71 | | - char *aOut; int nOut, nOut2; /* The output */ |
| 69 | + const char *aOrig; int nOrig; /* The X input */ |
| 70 | + const char *aDelta; int nDelta; /* The input delta (D) */ |
| 71 | + char *aOut; sqlite3_int64 nOut; /* The output */ |
| 72 | 72 | |
| 73 | 73 | assert( argc==2 ); |
| 74 | 74 | if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; |
| 75 | 75 | if( sqlite3_value_type(argv[1])==SQLITE_NULL ) return; |
| 76 | 76 | nOrig = sqlite3_value_bytes(argv[0]); |
| | @@ -82,20 +82,24 @@ |
| 82 | 82 | nOut = delta_output_size(aDelta, nDelta); |
| 83 | 83 | if( nOut<0 ){ |
| 84 | 84 | sqlite3_result_error(context, "corrupt fossil delta", -1); |
| 85 | 85 | return; |
| 86 | 86 | } |
| 87 | | - aOut = sqlite3_malloc64((sqlite3_int64)nOut+1); |
| 87 | + if( nOut>0x7fffffff ){ |
| 88 | + sqlite3_result_error_toobig(context); |
| 89 | + return; |
| 90 | + } |
| 91 | + aOut = sqlite3_malloc64(nOut+1); |
| 88 | 92 | if( aOut==0 ){ |
| 89 | 93 | sqlite3_result_error_nomem(context); |
| 90 | 94 | }else{ |
| 91 | | - nOut2 = delta_apply(aOrig, nOrig, aDelta, nDelta, aOut); |
| 95 | + const int nOut2 = delta_apply(aOrig, nOrig, aDelta, nDelta, aOut); |
| 92 | 96 | if( nOut2!=nOut ){ |
| 93 | 97 | sqlite3_free(aOut); |
| 94 | 98 | sqlite3_result_error(context, "corrupt fossil delta", -1); |
| 95 | 99 | }else{ |
| 96 | | - sqlite3_result_blob(context, aOut, nOut, sqlite3_free); |
| 100 | + sqlite3_result_blob(context, aOut, nOut2, sqlite3_free); |
| 97 | 101 | } |
| 98 | 102 | } |
| 99 | 103 | } |
| 100 | 104 | |
| 101 | 105 | |
| | @@ -108,11 +112,11 @@ |
| 108 | 112 | sqlite3_context *context, |
| 109 | 113 | int argc, |
| 110 | 114 | sqlite3_value **argv |
| 111 | 115 | ){ |
| 112 | 116 | const char *aDelta; int nDelta; /* The input delta (D) */ |
| 113 | | - int nOut; /* Size of output */ |
| 117 | + sqlite3_int64 nOut; /* Size of output */ |
| 114 | 118 | assert( argc==1 ); |
| 115 | 119 | if( sqlite3_value_type(argv[0])==SQLITE_NULL ) return; |
| 116 | 120 | nDelta = sqlite3_value_bytes(argv[0]); |
| 117 | 121 | aDelta = (const char*)sqlite3_value_blob(argv[0]); |
| 118 | 122 | |
| | @@ -120,11 +124,11 @@ |
| 120 | 124 | nOut = delta_output_size(aDelta, nDelta); |
| 121 | 125 | if( nOut<0 ){ |
| 122 | 126 | sqlite3_result_error(context, "corrupt fossil delta", -1); |
| 123 | 127 | return; |
| 124 | 128 | }else{ |
| 125 | | - sqlite3_result_int(context, nOut); |
| 129 | + sqlite3_result_int64(context, nOut); |
| 126 | 130 | } |
| 127 | 131 | } |
| 128 | 132 | |
| 129 | 133 | /***************************************************************************** |
| 130 | 134 | ** Table-valued SQL function: delta_parse(DELTA) |
| | @@ -368,16 +372,16 @@ |
| 368 | 372 | case DELTAPARSEVTAB_OP: { |
| 369 | 373 | sqlite3_result_text(ctx, azOp[pCur->eOp], -1, SQLITE_STATIC); |
| 370 | 374 | break; |
| 371 | 375 | } |
| 372 | 376 | case DELTAPARSEVTAB_A1: { |
| 373 | | - sqlite3_result_int(ctx, pCur->a1); |
| 377 | + sqlite3_result_int64(ctx, pCur->a1); |
| 374 | 378 | break; |
| 375 | 379 | } |
| 376 | 380 | case DELTAPARSEVTAB_A2: { |
| 377 | 381 | if( pCur->eOp==DELTAPARSE_OP_COPY ){ |
| 378 | | - sqlite3_result_int(ctx, pCur->a2); |
| 382 | + sqlite3_result_int64(ctx, pCur->a2); |
| 379 | 383 | }else if( pCur->eOp==DELTAPARSE_OP_INSERT ){ |
| 380 | 384 | if( (i64)pCur->a2 + (i64)pCur->a1 > pCur->nDelta ){ |
| 381 | 385 | sqlite3_result_zeroblob(ctx, pCur->a1); |
| 382 | 386 | }else{ |
| 383 | 387 | sqlite3_result_blob(ctx, pCur->aDelta+pCur->a2, pCur->a1, |
| 384 | 388 | |