Fossil SCM
Avoid a potential 32-bit integer overflow when doing a diff on large files with large differences.
Commit
5882e9e87861c7c07aad78304fccfbe8114e7c2de0ff660aa393f3b22b89ae73
Parent
e6569d3f6328248…
1 file changed
+3
-1
+3
-1
| --- src/diff.c | ||
| +++ src/diff.c | ||
| @@ -2093,11 +2093,13 @@ | ||
| 2093 | 2093 | } |
| 2094 | 2094 | |
| 2095 | 2095 | /* For large alignments, try to use alternative algorithms that are |
| 2096 | 2096 | ** faster than the O(N*N) Wagner edit distance. |
| 2097 | 2097 | */ |
| 2098 | - if( nLeft*nRight>DIFF_ALIGN_MX && (pCfg->diffFlags & DIFF_SLOW_SBS)==0 ){ | |
| 2098 | + if( (i64)nLeft*(i64)nRight>DIFF_ALIGN_MX | |
| 2099 | + && (pCfg->diffFlags & DIFF_SLOW_SBS)==0 | |
| 2100 | + ){ | |
| 2099 | 2101 | if( (pCfg->diffFlags & DIFF_IGNORE_ALLWS)==0 ){ |
| 2100 | 2102 | unsigned char *aRes; |
| 2101 | 2103 | aRes = diffBlockAlignmentIgnoreSpace( |
| 2102 | 2104 | aLeft, nLeft,aRight, nRight,pCfg,pNResult); |
| 2103 | 2105 | if( aRes ) return aRes; |
| 2104 | 2106 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -2093,11 +2093,13 @@ | |
| 2093 | } |
| 2094 | |
| 2095 | /* For large alignments, try to use alternative algorithms that are |
| 2096 | ** faster than the O(N*N) Wagner edit distance. |
| 2097 | */ |
| 2098 | if( nLeft*nRight>DIFF_ALIGN_MX && (pCfg->diffFlags & DIFF_SLOW_SBS)==0 ){ |
| 2099 | if( (pCfg->diffFlags & DIFF_IGNORE_ALLWS)==0 ){ |
| 2100 | unsigned char *aRes; |
| 2101 | aRes = diffBlockAlignmentIgnoreSpace( |
| 2102 | aLeft, nLeft,aRight, nRight,pCfg,pNResult); |
| 2103 | if( aRes ) return aRes; |
| 2104 |
| --- src/diff.c | |
| +++ src/diff.c | |
| @@ -2093,11 +2093,13 @@ | |
| 2093 | } |
| 2094 | |
| 2095 | /* For large alignments, try to use alternative algorithms that are |
| 2096 | ** faster than the O(N*N) Wagner edit distance. |
| 2097 | */ |
| 2098 | if( (i64)nLeft*(i64)nRight>DIFF_ALIGN_MX |
| 2099 | && (pCfg->diffFlags & DIFF_SLOW_SBS)==0 |
| 2100 | ){ |
| 2101 | if( (pCfg->diffFlags & DIFF_IGNORE_ALLWS)==0 ){ |
| 2102 | unsigned char *aRes; |
| 2103 | aRes = diffBlockAlignmentIgnoreSpace( |
| 2104 | aLeft, nLeft,aRight, nRight,pCfg,pNResult); |
| 2105 | if( aRes ) return aRes; |
| 2106 |